file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Steel.Memory.fsti | Steel.Memory.name_of_inv | val name_of_inv (#p: slprop) (i: inv p) : GTot iname | val name_of_inv (#p: slprop) (i: inv p) : GTot iname | let name_of_inv (#p:slprop) (i:inv p)
: GTot iname
= name_of_pre_inv (pre_inv_of_inv i) | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 551,
"start_col": 0,
"start_line": 549
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a)
let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h))
val interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
[SMTPat (interp (sdep s f) m)]
(** See [Steel.Heap.h_exists_cong] *)
val h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
(** Introducing [h_exists] by presenting a witness *)
val intro_h_exists (#a:_) (x:a) (p:a -> slprop) (m:mem)
: Lemma (interp (p x) m ==> interp (h_exists p) m)
val elim_h_exists (#a:_) (p:a -> slprop) (m:mem)
: Lemma (interp (h_exists p) m ==> (exists x. interp (p x) m))
(** Introducing [h_forall] by proving all cases *)
val intro_h_forall (#a:_) (p:a -> slprop) (m:mem)
: Lemma ((forall x. interp (p x) m) ==> interp (h_forall p) m)
(** Eliminate a universal by instantiating it. *)
val elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a)
: Lemma (interp (h_forall p) m ==> interp (p x) m)
(** Introducing [h_and] by proving both sides *)
val intro_h_and (p q: slprop) (m:mem)
: Lemma (interp p m /\ interp q m ==> interp (h_and p q) m)
val elim_h_and (p q: slprop) (m:mem)
: Lemma (interp (h_and p q) m ==> (interp p m /\ interp q m))
(** Introducing [h_or] by proving one side *)
val intro_h_or_left (p q: slprop) (m:mem)
: Lemma (interp p m ==> interp (h_or p q) m)
val intro_h_or_right (p q: slprop) (m:mem)
: Lemma (interp q m ==> interp (h_or p q) m)
val elim_h_or (p q: slprop) (m:mem)
: Lemma (interp (h_or p q) m ==> (interp p m \/ interp q m))
val intro_wand (p1 p2: slprop u#a) (m:mem)
: Lemma ((forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
val elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem)
: Lemma ((interp (wand p1 p2) m /\ m `disjoint` m1 /\ interp p1 m1)
==> interp p2 (join m m1))
(**** Actions *)
/// Note, at this point, using the NMSTTotal effect constrains the mem to be
/// in universe 2, rather than being universe polymorphic
(** A memory predicate that depends only on fp *)
let mprop (fp:slprop u#a) =
q:(mem u#a -> prop){
forall (m0:mem{interp fp m0}) (m1:mem{disjoint m0 m1}).
q m0 <==> q (join m0 m1)}
let mprop2 (#a:Type u#b) (fp_pre:slprop u#a) (fp_post:a -> slprop u#a) =
q:(mem u#a -> a -> mem u#a -> prop){
// can join any disjoint mem to the pre-mem and q is still valid
(forall (x:a) (m0:mem{interp fp_pre m0}) (m_post:mem{interp (fp_post x) m_post}) (m1:mem{disjoint m0 m1}).
q m0 x m_post <==> q (join m0 m1) x m_post) /\
// can join any mem to the post-mem and q is still valid
(forall (x:a) (m_pre:mem{interp fp_pre m_pre}) (m0:mem{interp (fp_post x) m0}) (m1:mem{disjoint m0 m1}).
q m_pre x m0 <==> q m_pre x (join m0 m1))}
(**
The preorder along which the memory evolves with every update. See [Steel.Heap.heap_evolves]
*)
val mem_evolves : FStar.Preorder.preorder full_mem
(**
To guarantee that the memory always evolve according to frame-preserving updates,
we encode it into the [MstTot] effect build on top of the non-deterministic state total
effect NMSTATETOT. The effect is indexed by [except], which is the set of invariants that
are currently opened.
*)
effect MstTot
(a:Type u#a)
(except:inames)
(expects:slprop u#1)
(provides: a -> slprop u#1)
(frame:slprop u#1)
(pre:mprop expects)
(post:mprop2 expects provides)
= NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\
pre (core_mem m0))
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\ //TODO: fix the effect so as not to repeat this
interp (provides x `star` frame `star` locks_invariant except m1) m1 /\
post (core_mem m0) x (core_mem m1) /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(** An action is just a thunked computation in [MstTot] that takes a frame as argument *)
let action_except (a:Type u#a) (except:inames) (expects:slprop) (provides: a -> slprop) =
frame:slprop -> MstTot a except expects provides frame (fun _ -> True) (fun _ _ _ -> True)
let action_except_full (a:Type u#a)
(except:inames)
(expects:slprop)
(provides: a -> slprop)
(req:mprop expects)
(ens:mprop2 expects provides)
= frame:slprop -> MstTot a except expects provides frame req ens
val sel_action (#a:Type u#1) (#pcm:_) (e:inames) (r:ref a pcm) (v0:erased a)
: action_except (v:a{compatible pcm v0 v}) e (pts_to r v0) (fun _ -> pts_to r v0)
val upd_action (#a:Type u#1) (#pcm:_) (e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:a {FStar.PCM.frame_preserving pcm v0 v1 /\ pcm.refine v1})
: action_except unit e (pts_to r v0) (fun _ -> pts_to r v1)
val free_action (#a:Type u#1) (#pcm:pcm a) (e:inames)
(r:ref a pcm) (x:FStar.Ghost.erased a{FStar.PCM.exclusive pcm x /\ pcm.refine pcm.FStar.PCM.p.one})
: action_except unit e (pts_to r x) (fun _ -> pts_to r pcm.FStar.PCM.p.one)
(** Splitting a permission on a composite resource into two separate permissions *)
val split_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a{composable pcm v0 v1})
: action_except unit e (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 `star` pts_to r v1)
(** Combining separate permissions into a single composite permission *)
val gather_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a)
: action_except (_:unit{composable pcm v0 v1}) e (pts_to r v0 `star` pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
val alloc_action (#a:Type u#1) (#pcm:pcm a) (e:inames) (x:a{compatible pcm x x /\ pcm.refine x})
: action_except (ref a pcm) e emp (fun r -> pts_to r x)
val select_refine (#a:Type u#1) (#p:pcm a)
(e:inames)
(r:ref a p)
(x:erased a)
(f:(v:a{compatible p x v}
-> GTot (y:a{compatible p y v /\
FStar.PCM.frame_compatible p x v y})))
: action_except (v:a{compatible p x v /\ p.refine v}) e
(pts_to r x)
(fun v -> pts_to r (f v))
val upd_gen (#a:Type) (#p:pcm a) (e:inames) (r:ref a p) (x y:Ghost.erased a)
(f:FStar.PCM.frame_preserving_upd p x y)
: action_except unit e
(pts_to r x)
(fun _ -> pts_to r y)
let property (a:Type)
= a -> prop
val witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
: Type0
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm)
}
val witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
: action_except (witnessed r fact) e (pts_to r v) (fun _ -> pts_to r v)
val recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
: action_except (v1:Ghost.erased a{compatible pcm v v1}) e
(pts_to r v)
(fun v1 -> pts_to r v `star` pure (fact v1))
(**** Invariants *)
(**[i : inv p] is an invariant whose content is [p] *)
val pre_inv : Type0
val inv (p:slprop u#1) : Type0
val pre_inv_of_inv (#p:slprop) (i:inv p) : pre_inv
val name_of_pre_inv (i:pre_inv) : GTot iname | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Steel.Memory.inv p -> Prims.GTot Steel.Memory.iname | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.inv",
"Steel.Memory.name_of_pre_inv",
"Steel.Memory.pre_inv_of_inv",
"Steel.Memory.iname"
] | [] | false | false | false | false | false | let name_of_inv (#p: slprop) (i: inv p) : GTot iname =
| name_of_pre_inv (pre_inv_of_inv i) | false |
Steel.Memory.fsti | Steel.Memory.is_frame_monotonic | val is_frame_monotonic (#a: _) (p: (a -> slprop)) : prop | val is_frame_monotonic (#a: _) (p: (a -> slprop)) : prop | let is_frame_monotonic #a (p : a -> slprop) : prop =
forall x y m frame. interp (p x `star` frame) m /\ interp (p y) m ==> interp (p y `star` frame) m | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 597,
"start_col": 0,
"start_line": 596
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a)
let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h))
val interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
[SMTPat (interp (sdep s f) m)]
(** See [Steel.Heap.h_exists_cong] *)
val h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
(** Introducing [h_exists] by presenting a witness *)
val intro_h_exists (#a:_) (x:a) (p:a -> slprop) (m:mem)
: Lemma (interp (p x) m ==> interp (h_exists p) m)
val elim_h_exists (#a:_) (p:a -> slprop) (m:mem)
: Lemma (interp (h_exists p) m ==> (exists x. interp (p x) m))
(** Introducing [h_forall] by proving all cases *)
val intro_h_forall (#a:_) (p:a -> slprop) (m:mem)
: Lemma ((forall x. interp (p x) m) ==> interp (h_forall p) m)
(** Eliminate a universal by instantiating it. *)
val elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a)
: Lemma (interp (h_forall p) m ==> interp (p x) m)
(** Introducing [h_and] by proving both sides *)
val intro_h_and (p q: slprop) (m:mem)
: Lemma (interp p m /\ interp q m ==> interp (h_and p q) m)
val elim_h_and (p q: slprop) (m:mem)
: Lemma (interp (h_and p q) m ==> (interp p m /\ interp q m))
(** Introducing [h_or] by proving one side *)
val intro_h_or_left (p q: slprop) (m:mem)
: Lemma (interp p m ==> interp (h_or p q) m)
val intro_h_or_right (p q: slprop) (m:mem)
: Lemma (interp q m ==> interp (h_or p q) m)
val elim_h_or (p q: slprop) (m:mem)
: Lemma (interp (h_or p q) m ==> (interp p m \/ interp q m))
val intro_wand (p1 p2: slprop u#a) (m:mem)
: Lemma ((forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
val elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem)
: Lemma ((interp (wand p1 p2) m /\ m `disjoint` m1 /\ interp p1 m1)
==> interp p2 (join m m1))
(**** Actions *)
/// Note, at this point, using the NMSTTotal effect constrains the mem to be
/// in universe 2, rather than being universe polymorphic
(** A memory predicate that depends only on fp *)
let mprop (fp:slprop u#a) =
q:(mem u#a -> prop){
forall (m0:mem{interp fp m0}) (m1:mem{disjoint m0 m1}).
q m0 <==> q (join m0 m1)}
let mprop2 (#a:Type u#b) (fp_pre:slprop u#a) (fp_post:a -> slprop u#a) =
q:(mem u#a -> a -> mem u#a -> prop){
// can join any disjoint mem to the pre-mem and q is still valid
(forall (x:a) (m0:mem{interp fp_pre m0}) (m_post:mem{interp (fp_post x) m_post}) (m1:mem{disjoint m0 m1}).
q m0 x m_post <==> q (join m0 m1) x m_post) /\
// can join any mem to the post-mem and q is still valid
(forall (x:a) (m_pre:mem{interp fp_pre m_pre}) (m0:mem{interp (fp_post x) m0}) (m1:mem{disjoint m0 m1}).
q m_pre x m0 <==> q m_pre x (join m0 m1))}
(**
The preorder along which the memory evolves with every update. See [Steel.Heap.heap_evolves]
*)
val mem_evolves : FStar.Preorder.preorder full_mem
(**
To guarantee that the memory always evolve according to frame-preserving updates,
we encode it into the [MstTot] effect build on top of the non-deterministic state total
effect NMSTATETOT. The effect is indexed by [except], which is the set of invariants that
are currently opened.
*)
effect MstTot
(a:Type u#a)
(except:inames)
(expects:slprop u#1)
(provides: a -> slprop u#1)
(frame:slprop u#1)
(pre:mprop expects)
(post:mprop2 expects provides)
= NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\
pre (core_mem m0))
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\ //TODO: fix the effect so as not to repeat this
interp (provides x `star` frame `star` locks_invariant except m1) m1 /\
post (core_mem m0) x (core_mem m1) /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(** An action is just a thunked computation in [MstTot] that takes a frame as argument *)
let action_except (a:Type u#a) (except:inames) (expects:slprop) (provides: a -> slprop) =
frame:slprop -> MstTot a except expects provides frame (fun _ -> True) (fun _ _ _ -> True)
let action_except_full (a:Type u#a)
(except:inames)
(expects:slprop)
(provides: a -> slprop)
(req:mprop expects)
(ens:mprop2 expects provides)
= frame:slprop -> MstTot a except expects provides frame req ens
val sel_action (#a:Type u#1) (#pcm:_) (e:inames) (r:ref a pcm) (v0:erased a)
: action_except (v:a{compatible pcm v0 v}) e (pts_to r v0) (fun _ -> pts_to r v0)
val upd_action (#a:Type u#1) (#pcm:_) (e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:a {FStar.PCM.frame_preserving pcm v0 v1 /\ pcm.refine v1})
: action_except unit e (pts_to r v0) (fun _ -> pts_to r v1)
val free_action (#a:Type u#1) (#pcm:pcm a) (e:inames)
(r:ref a pcm) (x:FStar.Ghost.erased a{FStar.PCM.exclusive pcm x /\ pcm.refine pcm.FStar.PCM.p.one})
: action_except unit e (pts_to r x) (fun _ -> pts_to r pcm.FStar.PCM.p.one)
(** Splitting a permission on a composite resource into two separate permissions *)
val split_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a{composable pcm v0 v1})
: action_except unit e (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 `star` pts_to r v1)
(** Combining separate permissions into a single composite permission *)
val gather_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a)
: action_except (_:unit{composable pcm v0 v1}) e (pts_to r v0 `star` pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
val alloc_action (#a:Type u#1) (#pcm:pcm a) (e:inames) (x:a{compatible pcm x x /\ pcm.refine x})
: action_except (ref a pcm) e emp (fun r -> pts_to r x)
val select_refine (#a:Type u#1) (#p:pcm a)
(e:inames)
(r:ref a p)
(x:erased a)
(f:(v:a{compatible p x v}
-> GTot (y:a{compatible p y v /\
FStar.PCM.frame_compatible p x v y})))
: action_except (v:a{compatible p x v /\ p.refine v}) e
(pts_to r x)
(fun v -> pts_to r (f v))
val upd_gen (#a:Type) (#p:pcm a) (e:inames) (r:ref a p) (x y:Ghost.erased a)
(f:FStar.PCM.frame_preserving_upd p x y)
: action_except unit e
(pts_to r x)
(fun _ -> pts_to r y)
let property (a:Type)
= a -> prop
val witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
: Type0
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm)
}
val witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
: action_except (witnessed r fact) e (pts_to r v) (fun _ -> pts_to r v)
val recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
: action_except (v1:Ghost.erased a{compatible pcm v v1}) e
(pts_to r v)
(fun v1 -> pts_to r v `star` pure (fact v1))
(**** Invariants *)
(**[i : inv p] is an invariant whose content is [p] *)
val pre_inv : Type0
val inv (p:slprop u#1) : Type0
val pre_inv_of_inv (#p:slprop) (i:inv p) : pre_inv
val name_of_pre_inv (i:pre_inv) : GTot iname
let name_of_inv (#p:slprop) (i:inv p)
: GTot iname
= name_of_pre_inv (pre_inv_of_inv i)
let mem_inv (#p:slprop) (e:inames) (i:inv p) : erased bool = elift2 (fun e i -> Set.mem i e) e (name_of_inv i)
let add_inv (#p:slprop) (e:inames) (i:inv p) : inames =
Set.union (Set.singleton (name_of_inv i)) (reveal e)
(** Creates a new invariant from a separation logic predicate [p] owned at the time of the call *)
let fresh_wrt (ctx:list pre_inv)
(i:iname)
= forall i'. List.Tot.memP i' ctx ==> name_of_pre_inv i' <> i
val fresh_invariant (e:inames) (p:slprop) (ctx:list pre_inv)
: action_except (i:inv p { not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i) }) e p (fun _ -> emp)
val new_invariant (e:inames) (p:slprop)
: action_except (inv p) e p (fun _ -> emp)
val with_invariant (#a:Type)
(#fp:slprop)
(#fp':a -> slprop)
(#opened_invariants:inames)
(#p:slprop)
(i:inv p{not (mem_inv opened_invariants i)})
(f:action_except a (add_inv opened_invariants i) (p `star` fp) (fun x -> p `star` fp' x))
: action_except a opened_invariants fp fp'
val frame (#a:Type)
(#opened_invariants:inames)
(#pre:slprop)
(#post:a -> slprop)
(#req:mprop pre)
(#ens:mprop2 pre post)
(frame:slprop)
($f:action_except_full a opened_invariants pre post req ens)
: action_except_full a opened_invariants (pre `star` frame) (fun x -> post x `star` frame) req ens
val change_slprop (#opened_invariants:inames)
(p q:slprop)
(proof: (m:mem -> Lemma (requires interp p m) (ensures interp q m)))
: action_except unit opened_invariants p (fun _ -> q)
module U = FStar.Universe | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: (_: a -> Steel.Memory.slprop) -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Prims.l_Forall",
"Steel.Memory.mem",
"Prims.l_imp",
"Prims.l_and",
"Steel.Memory.interp",
"Steel.Memory.star",
"Prims.prop"
] | [] | false | false | false | true | true | let is_frame_monotonic #a (p: (a -> slprop)) : prop =
| forall x y m frame.
interp ((p x) `star` frame) m /\ interp (p y) m ==> interp ((p y) `star` frame) m | false |
Steel.Memory.fsti | Steel.Memory.add_inv | val add_inv (#p: slprop) (e: inames) (i: inv p) : inames | val add_inv (#p: slprop) (e: inames) (i: inv p) : inames | let add_inv (#p:slprop) (e:inames) (i:inv p) : inames =
Set.union (Set.singleton (name_of_inv i)) (reveal e) | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 556,
"start_col": 0,
"start_line": 555
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a)
let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h))
val interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
[SMTPat (interp (sdep s f) m)]
(** See [Steel.Heap.h_exists_cong] *)
val h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
(** Introducing [h_exists] by presenting a witness *)
val intro_h_exists (#a:_) (x:a) (p:a -> slprop) (m:mem)
: Lemma (interp (p x) m ==> interp (h_exists p) m)
val elim_h_exists (#a:_) (p:a -> slprop) (m:mem)
: Lemma (interp (h_exists p) m ==> (exists x. interp (p x) m))
(** Introducing [h_forall] by proving all cases *)
val intro_h_forall (#a:_) (p:a -> slprop) (m:mem)
: Lemma ((forall x. interp (p x) m) ==> interp (h_forall p) m)
(** Eliminate a universal by instantiating it. *)
val elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a)
: Lemma (interp (h_forall p) m ==> interp (p x) m)
(** Introducing [h_and] by proving both sides *)
val intro_h_and (p q: slprop) (m:mem)
: Lemma (interp p m /\ interp q m ==> interp (h_and p q) m)
val elim_h_and (p q: slprop) (m:mem)
: Lemma (interp (h_and p q) m ==> (interp p m /\ interp q m))
(** Introducing [h_or] by proving one side *)
val intro_h_or_left (p q: slprop) (m:mem)
: Lemma (interp p m ==> interp (h_or p q) m)
val intro_h_or_right (p q: slprop) (m:mem)
: Lemma (interp q m ==> interp (h_or p q) m)
val elim_h_or (p q: slprop) (m:mem)
: Lemma (interp (h_or p q) m ==> (interp p m \/ interp q m))
val intro_wand (p1 p2: slprop u#a) (m:mem)
: Lemma ((forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
val elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem)
: Lemma ((interp (wand p1 p2) m /\ m `disjoint` m1 /\ interp p1 m1)
==> interp p2 (join m m1))
(**** Actions *)
/// Note, at this point, using the NMSTTotal effect constrains the mem to be
/// in universe 2, rather than being universe polymorphic
(** A memory predicate that depends only on fp *)
let mprop (fp:slprop u#a) =
q:(mem u#a -> prop){
forall (m0:mem{interp fp m0}) (m1:mem{disjoint m0 m1}).
q m0 <==> q (join m0 m1)}
let mprop2 (#a:Type u#b) (fp_pre:slprop u#a) (fp_post:a -> slprop u#a) =
q:(mem u#a -> a -> mem u#a -> prop){
// can join any disjoint mem to the pre-mem and q is still valid
(forall (x:a) (m0:mem{interp fp_pre m0}) (m_post:mem{interp (fp_post x) m_post}) (m1:mem{disjoint m0 m1}).
q m0 x m_post <==> q (join m0 m1) x m_post) /\
// can join any mem to the post-mem and q is still valid
(forall (x:a) (m_pre:mem{interp fp_pre m_pre}) (m0:mem{interp (fp_post x) m0}) (m1:mem{disjoint m0 m1}).
q m_pre x m0 <==> q m_pre x (join m0 m1))}
(**
The preorder along which the memory evolves with every update. See [Steel.Heap.heap_evolves]
*)
val mem_evolves : FStar.Preorder.preorder full_mem
(**
To guarantee that the memory always evolve according to frame-preserving updates,
we encode it into the [MstTot] effect build on top of the non-deterministic state total
effect NMSTATETOT. The effect is indexed by [except], which is the set of invariants that
are currently opened.
*)
effect MstTot
(a:Type u#a)
(except:inames)
(expects:slprop u#1)
(provides: a -> slprop u#1)
(frame:slprop u#1)
(pre:mprop expects)
(post:mprop2 expects provides)
= NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\
pre (core_mem m0))
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\ //TODO: fix the effect so as not to repeat this
interp (provides x `star` frame `star` locks_invariant except m1) m1 /\
post (core_mem m0) x (core_mem m1) /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(** An action is just a thunked computation in [MstTot] that takes a frame as argument *)
let action_except (a:Type u#a) (except:inames) (expects:slprop) (provides: a -> slprop) =
frame:slprop -> MstTot a except expects provides frame (fun _ -> True) (fun _ _ _ -> True)
let action_except_full (a:Type u#a)
(except:inames)
(expects:slprop)
(provides: a -> slprop)
(req:mprop expects)
(ens:mprop2 expects provides)
= frame:slprop -> MstTot a except expects provides frame req ens
val sel_action (#a:Type u#1) (#pcm:_) (e:inames) (r:ref a pcm) (v0:erased a)
: action_except (v:a{compatible pcm v0 v}) e (pts_to r v0) (fun _ -> pts_to r v0)
val upd_action (#a:Type u#1) (#pcm:_) (e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:a {FStar.PCM.frame_preserving pcm v0 v1 /\ pcm.refine v1})
: action_except unit e (pts_to r v0) (fun _ -> pts_to r v1)
val free_action (#a:Type u#1) (#pcm:pcm a) (e:inames)
(r:ref a pcm) (x:FStar.Ghost.erased a{FStar.PCM.exclusive pcm x /\ pcm.refine pcm.FStar.PCM.p.one})
: action_except unit e (pts_to r x) (fun _ -> pts_to r pcm.FStar.PCM.p.one)
(** Splitting a permission on a composite resource into two separate permissions *)
val split_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a{composable pcm v0 v1})
: action_except unit e (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 `star` pts_to r v1)
(** Combining separate permissions into a single composite permission *)
val gather_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a)
: action_except (_:unit{composable pcm v0 v1}) e (pts_to r v0 `star` pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
val alloc_action (#a:Type u#1) (#pcm:pcm a) (e:inames) (x:a{compatible pcm x x /\ pcm.refine x})
: action_except (ref a pcm) e emp (fun r -> pts_to r x)
val select_refine (#a:Type u#1) (#p:pcm a)
(e:inames)
(r:ref a p)
(x:erased a)
(f:(v:a{compatible p x v}
-> GTot (y:a{compatible p y v /\
FStar.PCM.frame_compatible p x v y})))
: action_except (v:a{compatible p x v /\ p.refine v}) e
(pts_to r x)
(fun v -> pts_to r (f v))
val upd_gen (#a:Type) (#p:pcm a) (e:inames) (r:ref a p) (x y:Ghost.erased a)
(f:FStar.PCM.frame_preserving_upd p x y)
: action_except unit e
(pts_to r x)
(fun _ -> pts_to r y)
let property (a:Type)
= a -> prop
val witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
: Type0
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm)
}
val witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
: action_except (witnessed r fact) e (pts_to r v) (fun _ -> pts_to r v)
val recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
: action_except (v1:Ghost.erased a{compatible pcm v v1}) e
(pts_to r v)
(fun v1 -> pts_to r v `star` pure (fact v1))
(**** Invariants *)
(**[i : inv p] is an invariant whose content is [p] *)
val pre_inv : Type0
val inv (p:slprop u#1) : Type0
val pre_inv_of_inv (#p:slprop) (i:inv p) : pre_inv
val name_of_pre_inv (i:pre_inv) : GTot iname
let name_of_inv (#p:slprop) (i:inv p)
: GTot iname
= name_of_pre_inv (pre_inv_of_inv i)
let mem_inv (#p:slprop) (e:inames) (i:inv p) : erased bool = elift2 (fun e i -> Set.mem i e) e (name_of_inv i) | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Steel.Memory.inames -> i: Steel.Memory.inv p -> Steel.Memory.inames | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.inames",
"Steel.Memory.inv",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.union",
"FStar.Set.singleton",
"Steel.Memory.name_of_inv",
"FStar.Ghost.reveal"
] | [] | false | false | false | false | false | let add_inv (#p: slprop) (e: inames) (i: inv p) : inames =
| Set.union (Set.singleton (name_of_inv i)) (reveal e) | false |
Steel.Memory.fsti | Steel.Memory.dep_slprop_is_affine | val dep_slprop_is_affine (s: slprop) (f: (hmem s -> Tot slprop)) : Tot prop | val dep_slprop_is_affine (s: slprop) (f: (hmem s -> Tot slprop)) : Tot prop | let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h)) | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 52,
"end_line": 327,
"start_col": 0,
"start_line": 323
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a) | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Steel.Memory.slprop -> f: (_: Steel.Memory.hmem s -> Steel.Memory.slprop) -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.hmem",
"Prims.l_Forall",
"Steel.Memory.equiv",
"Steel.Memory.core_mem",
"Prims.prop"
] | [] | false | false | false | false | true | let dep_slprop_is_affine (s: slprop) (f: (hmem s -> Tot slprop)) : Tot prop =
| (forall (h: hmem s). (f h) `equiv` (f (core_mem h))) | false |
Steel.Memory.fsti | Steel.Memory.fresh_wrt | val fresh_wrt : ctx: Prims.list Steel.Memory.pre_inv -> i: Steel.Memory.iname -> Prims.logical | let fresh_wrt (ctx:list pre_inv)
(i:iname)
= forall i'. List.Tot.memP i' ctx ==> name_of_pre_inv i' <> i | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 63,
"end_line": 561,
"start_col": 0,
"start_line": 559
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a)
let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h))
val interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
[SMTPat (interp (sdep s f) m)]
(** See [Steel.Heap.h_exists_cong] *)
val h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
(** Introducing [h_exists] by presenting a witness *)
val intro_h_exists (#a:_) (x:a) (p:a -> slprop) (m:mem)
: Lemma (interp (p x) m ==> interp (h_exists p) m)
val elim_h_exists (#a:_) (p:a -> slprop) (m:mem)
: Lemma (interp (h_exists p) m ==> (exists x. interp (p x) m))
(** Introducing [h_forall] by proving all cases *)
val intro_h_forall (#a:_) (p:a -> slprop) (m:mem)
: Lemma ((forall x. interp (p x) m) ==> interp (h_forall p) m)
(** Eliminate a universal by instantiating it. *)
val elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a)
: Lemma (interp (h_forall p) m ==> interp (p x) m)
(** Introducing [h_and] by proving both sides *)
val intro_h_and (p q: slprop) (m:mem)
: Lemma (interp p m /\ interp q m ==> interp (h_and p q) m)
val elim_h_and (p q: slprop) (m:mem)
: Lemma (interp (h_and p q) m ==> (interp p m /\ interp q m))
(** Introducing [h_or] by proving one side *)
val intro_h_or_left (p q: slprop) (m:mem)
: Lemma (interp p m ==> interp (h_or p q) m)
val intro_h_or_right (p q: slprop) (m:mem)
: Lemma (interp q m ==> interp (h_or p q) m)
val elim_h_or (p q: slprop) (m:mem)
: Lemma (interp (h_or p q) m ==> (interp p m \/ interp q m))
val intro_wand (p1 p2: slprop u#a) (m:mem)
: Lemma ((forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
val elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem)
: Lemma ((interp (wand p1 p2) m /\ m `disjoint` m1 /\ interp p1 m1)
==> interp p2 (join m m1))
(**** Actions *)
/// Note, at this point, using the NMSTTotal effect constrains the mem to be
/// in universe 2, rather than being universe polymorphic
(** A memory predicate that depends only on fp *)
let mprop (fp:slprop u#a) =
q:(mem u#a -> prop){
forall (m0:mem{interp fp m0}) (m1:mem{disjoint m0 m1}).
q m0 <==> q (join m0 m1)}
let mprop2 (#a:Type u#b) (fp_pre:slprop u#a) (fp_post:a -> slprop u#a) =
q:(mem u#a -> a -> mem u#a -> prop){
// can join any disjoint mem to the pre-mem and q is still valid
(forall (x:a) (m0:mem{interp fp_pre m0}) (m_post:mem{interp (fp_post x) m_post}) (m1:mem{disjoint m0 m1}).
q m0 x m_post <==> q (join m0 m1) x m_post) /\
// can join any mem to the post-mem and q is still valid
(forall (x:a) (m_pre:mem{interp fp_pre m_pre}) (m0:mem{interp (fp_post x) m0}) (m1:mem{disjoint m0 m1}).
q m_pre x m0 <==> q m_pre x (join m0 m1))}
(**
The preorder along which the memory evolves with every update. See [Steel.Heap.heap_evolves]
*)
val mem_evolves : FStar.Preorder.preorder full_mem
(**
To guarantee that the memory always evolve according to frame-preserving updates,
we encode it into the [MstTot] effect build on top of the non-deterministic state total
effect NMSTATETOT. The effect is indexed by [except], which is the set of invariants that
are currently opened.
*)
effect MstTot
(a:Type u#a)
(except:inames)
(expects:slprop u#1)
(provides: a -> slprop u#1)
(frame:slprop u#1)
(pre:mprop expects)
(post:mprop2 expects provides)
= NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\
pre (core_mem m0))
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\ //TODO: fix the effect so as not to repeat this
interp (provides x `star` frame `star` locks_invariant except m1) m1 /\
post (core_mem m0) x (core_mem m1) /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(** An action is just a thunked computation in [MstTot] that takes a frame as argument *)
let action_except (a:Type u#a) (except:inames) (expects:slprop) (provides: a -> slprop) =
frame:slprop -> MstTot a except expects provides frame (fun _ -> True) (fun _ _ _ -> True)
let action_except_full (a:Type u#a)
(except:inames)
(expects:slprop)
(provides: a -> slprop)
(req:mprop expects)
(ens:mprop2 expects provides)
= frame:slprop -> MstTot a except expects provides frame req ens
val sel_action (#a:Type u#1) (#pcm:_) (e:inames) (r:ref a pcm) (v0:erased a)
: action_except (v:a{compatible pcm v0 v}) e (pts_to r v0) (fun _ -> pts_to r v0)
val upd_action (#a:Type u#1) (#pcm:_) (e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:a {FStar.PCM.frame_preserving pcm v0 v1 /\ pcm.refine v1})
: action_except unit e (pts_to r v0) (fun _ -> pts_to r v1)
val free_action (#a:Type u#1) (#pcm:pcm a) (e:inames)
(r:ref a pcm) (x:FStar.Ghost.erased a{FStar.PCM.exclusive pcm x /\ pcm.refine pcm.FStar.PCM.p.one})
: action_except unit e (pts_to r x) (fun _ -> pts_to r pcm.FStar.PCM.p.one)
(** Splitting a permission on a composite resource into two separate permissions *)
val split_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a{composable pcm v0 v1})
: action_except unit e (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 `star` pts_to r v1)
(** Combining separate permissions into a single composite permission *)
val gather_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a)
: action_except (_:unit{composable pcm v0 v1}) e (pts_to r v0 `star` pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
val alloc_action (#a:Type u#1) (#pcm:pcm a) (e:inames) (x:a{compatible pcm x x /\ pcm.refine x})
: action_except (ref a pcm) e emp (fun r -> pts_to r x)
val select_refine (#a:Type u#1) (#p:pcm a)
(e:inames)
(r:ref a p)
(x:erased a)
(f:(v:a{compatible p x v}
-> GTot (y:a{compatible p y v /\
FStar.PCM.frame_compatible p x v y})))
: action_except (v:a{compatible p x v /\ p.refine v}) e
(pts_to r x)
(fun v -> pts_to r (f v))
val upd_gen (#a:Type) (#p:pcm a) (e:inames) (r:ref a p) (x y:Ghost.erased a)
(f:FStar.PCM.frame_preserving_upd p x y)
: action_except unit e
(pts_to r x)
(fun _ -> pts_to r y)
let property (a:Type)
= a -> prop
val witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
: Type0
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm)
}
val witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
: action_except (witnessed r fact) e (pts_to r v) (fun _ -> pts_to r v)
val recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
: action_except (v1:Ghost.erased a{compatible pcm v v1}) e
(pts_to r v)
(fun v1 -> pts_to r v `star` pure (fact v1))
(**** Invariants *)
(**[i : inv p] is an invariant whose content is [p] *)
val pre_inv : Type0
val inv (p:slprop u#1) : Type0
val pre_inv_of_inv (#p:slprop) (i:inv p) : pre_inv
val name_of_pre_inv (i:pre_inv) : GTot iname
let name_of_inv (#p:slprop) (i:inv p)
: GTot iname
= name_of_pre_inv (pre_inv_of_inv i)
let mem_inv (#p:slprop) (e:inames) (i:inv p) : erased bool = elift2 (fun e i -> Set.mem i e) e (name_of_inv i)
let add_inv (#p:slprop) (e:inames) (i:inv p) : inames =
Set.union (Set.singleton (name_of_inv i)) (reveal e) | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ctx: Prims.list Steel.Memory.pre_inv -> i: Steel.Memory.iname -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Steel.Memory.pre_inv",
"Steel.Memory.iname",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.List.Tot.Base.memP",
"Prims.b2t",
"Prims.op_disEquality",
"Steel.Memory.name_of_pre_inv",
"Prims.logical"
] | [] | false | false | false | true | true | let fresh_wrt (ctx: list pre_inv) (i: iname) =
| forall i'. List.Tot.memP i' ctx ==> name_of_pre_inv i' <> i | false |
|
Steel.Memory.fsti | Steel.Memory.mem_inv | val mem_inv (#p: slprop) (e: inames) (i: inv p) : erased bool | val mem_inv (#p: slprop) (e: inames) (i: inv p) : erased bool | let mem_inv (#p:slprop) (e:inames) (i:inv p) : erased bool = elift2 (fun e i -> Set.mem i e) e (name_of_inv i) | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 110,
"end_line": 553,
"start_col": 0,
"start_line": 553
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a)
let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h))
val interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
[SMTPat (interp (sdep s f) m)]
(** See [Steel.Heap.h_exists_cong] *)
val h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
(** Introducing [h_exists] by presenting a witness *)
val intro_h_exists (#a:_) (x:a) (p:a -> slprop) (m:mem)
: Lemma (interp (p x) m ==> interp (h_exists p) m)
val elim_h_exists (#a:_) (p:a -> slprop) (m:mem)
: Lemma (interp (h_exists p) m ==> (exists x. interp (p x) m))
(** Introducing [h_forall] by proving all cases *)
val intro_h_forall (#a:_) (p:a -> slprop) (m:mem)
: Lemma ((forall x. interp (p x) m) ==> interp (h_forall p) m)
(** Eliminate a universal by instantiating it. *)
val elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a)
: Lemma (interp (h_forall p) m ==> interp (p x) m)
(** Introducing [h_and] by proving both sides *)
val intro_h_and (p q: slprop) (m:mem)
: Lemma (interp p m /\ interp q m ==> interp (h_and p q) m)
val elim_h_and (p q: slprop) (m:mem)
: Lemma (interp (h_and p q) m ==> (interp p m /\ interp q m))
(** Introducing [h_or] by proving one side *)
val intro_h_or_left (p q: slprop) (m:mem)
: Lemma (interp p m ==> interp (h_or p q) m)
val intro_h_or_right (p q: slprop) (m:mem)
: Lemma (interp q m ==> interp (h_or p q) m)
val elim_h_or (p q: slprop) (m:mem)
: Lemma (interp (h_or p q) m ==> (interp p m \/ interp q m))
val intro_wand (p1 p2: slprop u#a) (m:mem)
: Lemma ((forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
val elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem)
: Lemma ((interp (wand p1 p2) m /\ m `disjoint` m1 /\ interp p1 m1)
==> interp p2 (join m m1))
(**** Actions *)
/// Note, at this point, using the NMSTTotal effect constrains the mem to be
/// in universe 2, rather than being universe polymorphic
(** A memory predicate that depends only on fp *)
let mprop (fp:slprop u#a) =
q:(mem u#a -> prop){
forall (m0:mem{interp fp m0}) (m1:mem{disjoint m0 m1}).
q m0 <==> q (join m0 m1)}
let mprop2 (#a:Type u#b) (fp_pre:slprop u#a) (fp_post:a -> slprop u#a) =
q:(mem u#a -> a -> mem u#a -> prop){
// can join any disjoint mem to the pre-mem and q is still valid
(forall (x:a) (m0:mem{interp fp_pre m0}) (m_post:mem{interp (fp_post x) m_post}) (m1:mem{disjoint m0 m1}).
q m0 x m_post <==> q (join m0 m1) x m_post) /\
// can join any mem to the post-mem and q is still valid
(forall (x:a) (m_pre:mem{interp fp_pre m_pre}) (m0:mem{interp (fp_post x) m0}) (m1:mem{disjoint m0 m1}).
q m_pre x m0 <==> q m_pre x (join m0 m1))}
(**
The preorder along which the memory evolves with every update. See [Steel.Heap.heap_evolves]
*)
val mem_evolves : FStar.Preorder.preorder full_mem
(**
To guarantee that the memory always evolve according to frame-preserving updates,
we encode it into the [MstTot] effect build on top of the non-deterministic state total
effect NMSTATETOT. The effect is indexed by [except], which is the set of invariants that
are currently opened.
*)
effect MstTot
(a:Type u#a)
(except:inames)
(expects:slprop u#1)
(provides: a -> slprop u#1)
(frame:slprop u#1)
(pre:mprop expects)
(post:mprop2 expects provides)
= NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\
pre (core_mem m0))
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\ //TODO: fix the effect so as not to repeat this
interp (provides x `star` frame `star` locks_invariant except m1) m1 /\
post (core_mem m0) x (core_mem m1) /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(** An action is just a thunked computation in [MstTot] that takes a frame as argument *)
let action_except (a:Type u#a) (except:inames) (expects:slprop) (provides: a -> slprop) =
frame:slprop -> MstTot a except expects provides frame (fun _ -> True) (fun _ _ _ -> True)
let action_except_full (a:Type u#a)
(except:inames)
(expects:slprop)
(provides: a -> slprop)
(req:mprop expects)
(ens:mprop2 expects provides)
= frame:slprop -> MstTot a except expects provides frame req ens
val sel_action (#a:Type u#1) (#pcm:_) (e:inames) (r:ref a pcm) (v0:erased a)
: action_except (v:a{compatible pcm v0 v}) e (pts_to r v0) (fun _ -> pts_to r v0)
val upd_action (#a:Type u#1) (#pcm:_) (e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:a {FStar.PCM.frame_preserving pcm v0 v1 /\ pcm.refine v1})
: action_except unit e (pts_to r v0) (fun _ -> pts_to r v1)
val free_action (#a:Type u#1) (#pcm:pcm a) (e:inames)
(r:ref a pcm) (x:FStar.Ghost.erased a{FStar.PCM.exclusive pcm x /\ pcm.refine pcm.FStar.PCM.p.one})
: action_except unit e (pts_to r x) (fun _ -> pts_to r pcm.FStar.PCM.p.one)
(** Splitting a permission on a composite resource into two separate permissions *)
val split_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a{composable pcm v0 v1})
: action_except unit e (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 `star` pts_to r v1)
(** Combining separate permissions into a single composite permission *)
val gather_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a)
: action_except (_:unit{composable pcm v0 v1}) e (pts_to r v0 `star` pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
val alloc_action (#a:Type u#1) (#pcm:pcm a) (e:inames) (x:a{compatible pcm x x /\ pcm.refine x})
: action_except (ref a pcm) e emp (fun r -> pts_to r x)
val select_refine (#a:Type u#1) (#p:pcm a)
(e:inames)
(r:ref a p)
(x:erased a)
(f:(v:a{compatible p x v}
-> GTot (y:a{compatible p y v /\
FStar.PCM.frame_compatible p x v y})))
: action_except (v:a{compatible p x v /\ p.refine v}) e
(pts_to r x)
(fun v -> pts_to r (f v))
val upd_gen (#a:Type) (#p:pcm a) (e:inames) (r:ref a p) (x y:Ghost.erased a)
(f:FStar.PCM.frame_preserving_upd p x y)
: action_except unit e
(pts_to r x)
(fun _ -> pts_to r y)
let property (a:Type)
= a -> prop
val witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
: Type0
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm)
}
val witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
: action_except (witnessed r fact) e (pts_to r v) (fun _ -> pts_to r v)
val recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
: action_except (v1:Ghost.erased a{compatible pcm v v1}) e
(pts_to r v)
(fun v1 -> pts_to r v `star` pure (fact v1))
(**** Invariants *)
(**[i : inv p] is an invariant whose content is [p] *)
val pre_inv : Type0
val inv (p:slprop u#1) : Type0
val pre_inv_of_inv (#p:slprop) (i:inv p) : pre_inv
val name_of_pre_inv (i:pre_inv) : GTot iname
let name_of_inv (#p:slprop) (i:inv p)
: GTot iname
= name_of_pre_inv (pre_inv_of_inv i) | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Steel.Memory.inames -> i: Steel.Memory.inv p -> FStar.Ghost.erased Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.inames",
"Steel.Memory.inv",
"FStar.Ghost.elift2",
"FStar.Set.set",
"Steel.Memory.iname",
"Prims.bool",
"FStar.Set.mem",
"FStar.Ghost.hide",
"Steel.Memory.name_of_inv",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let mem_inv (#p: slprop) (e: inames) (i: inv p) : erased bool =
| elift2 (fun e i -> Set.mem i e) e (name_of_inv i) | false |
Steel.Memory.fsti | Steel.Memory.is_null | val is_null (#a: Type u#a) (#pcm: pcm a) (r: ref a pcm) : (b: bool{b <==> r == null}) | val is_null (#a: Type u#a) (#pcm: pcm a) (r: ref a pcm) : (b: bool{b <==> r == null}) | let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 102,
"end_line": 129,
"start_col": 0,
"start_line": 129
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null] | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.Memory.ref a pcm -> b: Prims.bool{b <==> r == Steel.Memory.null} | Prims.Tot | [
"total"
] | [] | [
"FStar.PCM.pcm",
"Steel.Memory.ref",
"Steel.Memory.core_ref_is_null",
"Prims.bool",
"Prims.l_iff",
"Prims.b2t",
"Prims.eq2",
"Steel.Memory.null"
] | [] | false | false | false | false | false | let is_null (#a: Type u#a) (#pcm: pcm a) (r: ref a pcm) : (b: bool{b <==> r == null}) =
| core_ref_is_null r | false |
Steel.Memory.fsti | Steel.Memory.is_witness_invariant | val is_witness_invariant : p: (_: a -> Steel.Memory.slprop) -> Prims.logical | let is_witness_invariant #a (p : a -> slprop) =
forall x y m. interp (p x) m /\ interp (p y) m ==> x == y | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 600,
"start_col": 0,
"start_line": 599
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m
let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1)))
let a_mem_prop (sl: slprop u#a) : Type u#(a+1) = (f: (hmem sl -> Tot prop) { mem_prop_is_affine sl f })
val refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (slprop u#a)
val interp_refine_slprop
(sl: slprop u#a)
(f: a_mem_prop sl)
(m: mem u#a)
: Lemma
(interp (refine_slprop sl f) m <==> (interp sl m /\ f m))
[SMTPat (interp (refine_slprop sl f) m)]
val sdep
(s: slprop u#a)
(f: (hmem s -> Tot (slprop u#a)))
: Tot (slprop u#a)
let dep_slprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot prop
= (forall (h: hmem s) . f h `equiv` f (core_mem h))
val interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
[SMTPat (interp (sdep s f) m)]
(** See [Steel.Heap.h_exists_cong] *)
val h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
(** Introducing [h_exists] by presenting a witness *)
val intro_h_exists (#a:_) (x:a) (p:a -> slprop) (m:mem)
: Lemma (interp (p x) m ==> interp (h_exists p) m)
val elim_h_exists (#a:_) (p:a -> slprop) (m:mem)
: Lemma (interp (h_exists p) m ==> (exists x. interp (p x) m))
(** Introducing [h_forall] by proving all cases *)
val intro_h_forall (#a:_) (p:a -> slprop) (m:mem)
: Lemma ((forall x. interp (p x) m) ==> interp (h_forall p) m)
(** Eliminate a universal by instantiating it. *)
val elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a)
: Lemma (interp (h_forall p) m ==> interp (p x) m)
(** Introducing [h_and] by proving both sides *)
val intro_h_and (p q: slprop) (m:mem)
: Lemma (interp p m /\ interp q m ==> interp (h_and p q) m)
val elim_h_and (p q: slprop) (m:mem)
: Lemma (interp (h_and p q) m ==> (interp p m /\ interp q m))
(** Introducing [h_or] by proving one side *)
val intro_h_or_left (p q: slprop) (m:mem)
: Lemma (interp p m ==> interp (h_or p q) m)
val intro_h_or_right (p q: slprop) (m:mem)
: Lemma (interp q m ==> interp (h_or p q) m)
val elim_h_or (p q: slprop) (m:mem)
: Lemma (interp (h_or p q) m ==> (interp p m \/ interp q m))
val intro_wand (p1 p2: slprop u#a) (m:mem)
: Lemma ((forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
val elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem)
: Lemma ((interp (wand p1 p2) m /\ m `disjoint` m1 /\ interp p1 m1)
==> interp p2 (join m m1))
(**** Actions *)
/// Note, at this point, using the NMSTTotal effect constrains the mem to be
/// in universe 2, rather than being universe polymorphic
(** A memory predicate that depends only on fp *)
let mprop (fp:slprop u#a) =
q:(mem u#a -> prop){
forall (m0:mem{interp fp m0}) (m1:mem{disjoint m0 m1}).
q m0 <==> q (join m0 m1)}
let mprop2 (#a:Type u#b) (fp_pre:slprop u#a) (fp_post:a -> slprop u#a) =
q:(mem u#a -> a -> mem u#a -> prop){
// can join any disjoint mem to the pre-mem and q is still valid
(forall (x:a) (m0:mem{interp fp_pre m0}) (m_post:mem{interp (fp_post x) m_post}) (m1:mem{disjoint m0 m1}).
q m0 x m_post <==> q (join m0 m1) x m_post) /\
// can join any mem to the post-mem and q is still valid
(forall (x:a) (m_pre:mem{interp fp_pre m_pre}) (m0:mem{interp (fp_post x) m0}) (m1:mem{disjoint m0 m1}).
q m_pre x m0 <==> q m_pre x (join m0 m1))}
(**
The preorder along which the memory evolves with every update. See [Steel.Heap.heap_evolves]
*)
val mem_evolves : FStar.Preorder.preorder full_mem
(**
To guarantee that the memory always evolve according to frame-preserving updates,
we encode it into the [MstTot] effect build on top of the non-deterministic state total
effect NMSTATETOT. The effect is indexed by [except], which is the set of invariants that
are currently opened.
*)
effect MstTot
(a:Type u#a)
(except:inames)
(expects:slprop u#1)
(provides: a -> slprop u#1)
(frame:slprop u#1)
(pre:mprop expects)
(post:mprop2 expects provides)
= NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\
pre (core_mem m0))
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (expects `star` frame `star` locks_invariant except m0) m0 /\ //TODO: fix the effect so as not to repeat this
interp (provides x `star` frame `star` locks_invariant except m1) m1 /\
post (core_mem m0) x (core_mem m1) /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(** An action is just a thunked computation in [MstTot] that takes a frame as argument *)
let action_except (a:Type u#a) (except:inames) (expects:slprop) (provides: a -> slprop) =
frame:slprop -> MstTot a except expects provides frame (fun _ -> True) (fun _ _ _ -> True)
let action_except_full (a:Type u#a)
(except:inames)
(expects:slprop)
(provides: a -> slprop)
(req:mprop expects)
(ens:mprop2 expects provides)
= frame:slprop -> MstTot a except expects provides frame req ens
val sel_action (#a:Type u#1) (#pcm:_) (e:inames) (r:ref a pcm) (v0:erased a)
: action_except (v:a{compatible pcm v0 v}) e (pts_to r v0) (fun _ -> pts_to r v0)
val upd_action (#a:Type u#1) (#pcm:_) (e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:a {FStar.PCM.frame_preserving pcm v0 v1 /\ pcm.refine v1})
: action_except unit e (pts_to r v0) (fun _ -> pts_to r v1)
val free_action (#a:Type u#1) (#pcm:pcm a) (e:inames)
(r:ref a pcm) (x:FStar.Ghost.erased a{FStar.PCM.exclusive pcm x /\ pcm.refine pcm.FStar.PCM.p.one})
: action_except unit e (pts_to r x) (fun _ -> pts_to r pcm.FStar.PCM.p.one)
(** Splitting a permission on a composite resource into two separate permissions *)
val split_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a{composable pcm v0 v1})
: action_except unit e (pts_to r (v0 `op pcm` v1)) (fun _ -> pts_to r v0 `star` pts_to r v1)
(** Combining separate permissions into a single composite permission *)
val gather_action
(#a:Type u#1)
(#pcm:pcm a)
(e:inames)
(r:ref a pcm)
(v0:FStar.Ghost.erased a)
(v1:FStar.Ghost.erased a)
: action_except (_:unit{composable pcm v0 v1}) e (pts_to r v0 `star` pts_to r v1) (fun _ -> pts_to r (op pcm v0 v1))
val alloc_action (#a:Type u#1) (#pcm:pcm a) (e:inames) (x:a{compatible pcm x x /\ pcm.refine x})
: action_except (ref a pcm) e emp (fun r -> pts_to r x)
val select_refine (#a:Type u#1) (#p:pcm a)
(e:inames)
(r:ref a p)
(x:erased a)
(f:(v:a{compatible p x v}
-> GTot (y:a{compatible p y v /\
FStar.PCM.frame_compatible p x v y})))
: action_except (v:a{compatible p x v /\ p.refine v}) e
(pts_to r x)
(fun v -> pts_to r (f v))
val upd_gen (#a:Type) (#p:pcm a) (e:inames) (r:ref a p) (x y:Ghost.erased a)
(f:FStar.PCM.frame_preserving_upd p x y)
: action_except unit e
(pts_to r x)
(fun _ -> pts_to r y)
let property (a:Type)
= a -> prop
val witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
: Type0
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm)
}
val witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
: action_except (witnessed r fact) e (pts_to r v) (fun _ -> pts_to r v)
val recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
: action_except (v1:Ghost.erased a{compatible pcm v v1}) e
(pts_to r v)
(fun v1 -> pts_to r v `star` pure (fact v1))
(**** Invariants *)
(**[i : inv p] is an invariant whose content is [p] *)
val pre_inv : Type0
val inv (p:slprop u#1) : Type0
val pre_inv_of_inv (#p:slprop) (i:inv p) : pre_inv
val name_of_pre_inv (i:pre_inv) : GTot iname
let name_of_inv (#p:slprop) (i:inv p)
: GTot iname
= name_of_pre_inv (pre_inv_of_inv i)
let mem_inv (#p:slprop) (e:inames) (i:inv p) : erased bool = elift2 (fun e i -> Set.mem i e) e (name_of_inv i)
let add_inv (#p:slprop) (e:inames) (i:inv p) : inames =
Set.union (Set.singleton (name_of_inv i)) (reveal e)
(** Creates a new invariant from a separation logic predicate [p] owned at the time of the call *)
let fresh_wrt (ctx:list pre_inv)
(i:iname)
= forall i'. List.Tot.memP i' ctx ==> name_of_pre_inv i' <> i
val fresh_invariant (e:inames) (p:slprop) (ctx:list pre_inv)
: action_except (i:inv p { not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i) }) e p (fun _ -> emp)
val new_invariant (e:inames) (p:slprop)
: action_except (inv p) e p (fun _ -> emp)
val with_invariant (#a:Type)
(#fp:slprop)
(#fp':a -> slprop)
(#opened_invariants:inames)
(#p:slprop)
(i:inv p{not (mem_inv opened_invariants i)})
(f:action_except a (add_inv opened_invariants i) (p `star` fp) (fun x -> p `star` fp' x))
: action_except a opened_invariants fp fp'
val frame (#a:Type)
(#opened_invariants:inames)
(#pre:slprop)
(#post:a -> slprop)
(#req:mprop pre)
(#ens:mprop2 pre post)
(frame:slprop)
($f:action_except_full a opened_invariants pre post req ens)
: action_except_full a opened_invariants (pre `star` frame) (fun x -> post x `star` frame) req ens
val change_slprop (#opened_invariants:inames)
(p q:slprop)
(proof: (m:mem -> Lemma (requires interp p m) (ensures interp q m)))
: action_except unit opened_invariants p (fun _ -> q)
module U = FStar.Universe
let is_frame_monotonic #a (p : a -> slprop) : prop =
forall x y m frame. interp (p x `star` frame) m /\ interp (p y) m ==> interp (p y `star` frame) m | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: (_: a -> Steel.Memory.slprop) -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Prims.l_Forall",
"Steel.Memory.mem",
"Prims.l_imp",
"Prims.l_and",
"Steel.Memory.interp",
"Prims.eq2",
"Prims.logical"
] | [] | false | false | false | true | true | let is_witness_invariant #a (p: (a -> slprop)) =
| forall x y m. interp (p x) m /\ interp (p y) m ==> x == y | false |
|
Steel.Memory.fsti | Steel.Memory.mem_prop_is_affine | val mem_prop_is_affine (sl: slprop u#a) (f: (hmem sl -> Tot prop)) : Tot prop | val mem_prop_is_affine (sl: slprop u#a) (f: (hmem sl -> Tot prop)) : Tot prop | let mem_prop_is_affine
(sl: slprop u#a)
(f: (hmem sl -> Tot prop))
: Tot prop
= (forall m . f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1 . (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1))) | {
"file_name": "lib/steel/Steel.Memory.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 103,
"end_line": 301,
"start_col": 0,
"start_line": 296
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
open FStar.Ghost
open FStar.PCM
/// Building up on `Steel.Heap`, this module adds memory invariants to the heap to expose the
/// final interface for Steel's PCM-based memory model.
(**** Basic memory properties *)
(** Abstract type of memories *)
val mem : Type u#(a + 1)
(**
The memory is built on top of the heap, adding on the memory invariants. However, some of the
properties exposed for memories need only to talk about the underlying heap, putting aside
the memory invariants. To avoid exposing the underlying heap in this abstract interface, we
prefer to relying on this [core_mem] function that returns a new memory sharing the same
heap with the original memory but without any of the memory invariants.
*)
val core_mem (m:mem u#a) : mem u#a
val core_mem_invol (m: mem u#a) : Lemma
(core_mem (core_mem m) == core_mem m)
[SMTPat (core_mem (core_mem m))]
(** A predicate describing non-overlapping memories. Based on [Steel.Heap.disjoint] *)
val disjoint (m0 m1:mem u#h) : prop
(** Disjointness is symmetric *)
val disjoint_sym (m0 m1:mem u#h)
: Lemma (disjoint m0 m1 <==> disjoint m1 m0)
[SMTPat (disjoint m0 m1)]
(** Disjoint memories can be combined. Based on [Steel.Heap.join] *)
val join (m0:mem u#h) (m1:mem u#h{disjoint m0 m1}) : mem u#h
(** Join is commutative *)
val join_commutative (m0 m1:mem)
: Lemma
(requires
disjoint m0 m1)
(ensures
(disjoint m0 m1 /\
disjoint m1 m0 /\
join m0 m1 == join m1 m0))
(** Disjointness distributes over join *)
val disjoint_join (m0 m1 m2:mem)
: Lemma (disjoint m1 m2 /\
disjoint m0 (join m1 m2) ==>
disjoint m0 m1 /\
disjoint m0 m2 /\
disjoint (join m0 m1) m2 /\
disjoint (join m0 m2) m1)
(** Join is associative *)
val join_associative (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
(**** Separation logic *)
(** The type of separation logic propositions. Based on Steel.Heap.slprop *)
[@@erasable]
val slprop : Type u#(a + 1)
(** Interpreting mem assertions as memory predicates *)
val interp (p:slprop u#a) (m:mem u#a) : prop
(** A common abbreviation: memories validating [p] *)
let hmem (p:slprop u#a) = m:mem u#a {interp p m}
(** Equivalence relation on slprops is just equivalence of their interpretations *)
val equiv (p1 p2:slprop u#a) : prop
(**
An extensional equivalence principle for slprop
*)
val slprop_extensionality (p q:slprop)
: Lemma
(requires p `equiv` q)
(ensures p == q)
val reveal_equiv (p1 p2:slprop u#a) : Lemma
(ensures (forall m. interp p1 m <==> interp p2 m) <==> p1 `equiv` p2)
[SMTPat (p1 `equiv` p2)]
(** Implication of slprops *)
let slimp (p1 p2 : slprop) : prop =
forall m. interp p1 m ==> interp p2 m
(** A memory maps a [ref]erence to its associated value *)
val core_ref : Type u#0
let ref (a:Type u#a) (pcm:pcm a) : Type u#0 = core_ref
(** [null] is a specific reference, that is not associated to any value
*)
val core_ref_null : core_ref
(** [null] is a specific reference, that is not associated to any value
*)
let null (#a:Type u#a) (#pcm:pcm a) : ref a pcm = core_ref_null
val core_ref_is_null (r:core_ref) : b:bool { b <==> r == core_ref_null }
(** Checking whether [r] is the null pointer is decidable through [is_null]
*)
let is_null (#a:Type u#a) (#pcm:pcm a) (r:ref a pcm) : (b:bool{b <==> r == null}) = core_ref_is_null r
(** All the standard connectives of separation logic, based on [Steel.Heap] *)
val emp : slprop u#a
val pure (p:prop) : slprop u#a
val pts_to (#a:Type u#a) (#pcm:_) (r:ref a pcm) (v:a) : slprop u#a
val h_and (p1 p2:slprop u#a) : slprop u#a
val h_or (p1 p2:slprop u#a) : slprop u#a
val star (p1 p2:slprop u#a) : slprop u#a
val wand (p1 p2:slprop u#a) : slprop u#a
val h_exists (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
val h_forall (#a:Type u#b) (f: (a -> slprop u#a)) : slprop u#a
(***** Properties of separation logic equivalence *)
val equiv_symmetric (p1 p2:slprop)
: squash (p1 `equiv` p2 ==> p2 `equiv` p1)
val equiv_extensional_on_star (p1 p2 p3:slprop)
: squash (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
val emp_unit (p:slprop)
: Lemma (p `equiv` (p `star` emp))
val intro_emp (m:mem)
: Lemma (interp emp m)
(** Equivalence of pure propositions is the equivalence of the underlying propositions *)
val pure_equiv (p q:prop)
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
(** And the interpretation of pure propositions is their underlying propositions *)
val pure_interp (q:prop) (m:mem)
: Lemma (interp (pure q) m <==> q)
(** A helper lemma for interpreting a pure proposition with another [slprop] *)
val pure_star_interp (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `star` pure q) m <==>
interp (p `star` emp) m /\ q)
(***** Properties of [pts_to] *)
(** [ptr r] asserts that the reference [r] points to a value *)
let ptr (#a: Type u#a) (#pcm: pcm a) (r:ref a pcm) =
h_exists (pts_to r)
(** Injectivity-like lemma for [pts_to], see [Steel.Heap] for more explanations *)
val pts_to_compatible
(#a:Type u#a)
(#pcm:pcm a)
(x:ref a pcm)
(v0 v1:a)
(m:mem u#a)
: Lemma
(interp (pts_to x v0 `star` pts_to x v1) m <==>
composable pcm v0 v1 /\ interp (pts_to x (op pcm v0 v1)) m)
val pts_to_compatible_equiv (#a:Type)
(#pcm:_)
(x:ref a pcm)
(v0:a)
(v1:a{composable pcm v0 v1})
: Lemma (equiv (pts_to x v0 `star` pts_to x v1)
(pts_to x (op pcm v0 v1)))
val pts_to_not_null (#a:Type u#a)
(#pcm:_)
(x:ref a pcm)
(v:a)
(m:mem u#a)
: Lemma (requires interp (pts_to x v) m)
(ensures x =!= null)
(***** Properties of the separating conjunction *)
/// See [Steel.Memory.Heap] for more explanations
val intro_star (p q:slprop) (mp:hmem p) (mq:hmem q)
: Lemma
(requires
disjoint mp mq)
(ensures
interp (p `star` q) (join mp mq))
val elim_star (p q:slprop) (m:hmem (p `star` q))
: Lemma
(requires
interp (p `star` q) m)
(ensures exists ml mr.
disjoint ml mr /\ m == join ml mr /\ interp p ml /\ interp q mr)
val interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
val star_commutative (p1 p2:slprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1))
val star_associative (p1 p2 p3:slprop)
: Lemma ((p1 `star` (p2 `star` p3))
`equiv`
((p1 `star` p2) `star` p3))
val star_congruence (p1 p2 p3 p4:slprop)
: Lemma (requires p1 `equiv` p3 /\ p2 `equiv` p4)
(ensures (p1 `star` p2) `equiv` (p3 `star` p4))
val affine_star (p q:slprop) (m:mem)
: Lemma ((interp (p `star` q) m ==> interp p m /\ interp q m))
(**** Memory invariants *)
module S = FStar.Set
(** Invariants have a name *)
val iname : eqtype
let inames = erased (S.set iname)
(** This proposition tells us that all the invariants names in [e] are valid in memory [m] *)
val inames_ok (e:inames) (m:mem) : prop
(** The empty set of invariants is always empty *)
val inames_ok_empty (m:mem)
: Lemma (ensures inames_ok Set.empty m)
[SMTPat (inames_ok Set.empty m)]
(**
This separation logic proposition asserts that all the invariants whose names are in [e]
are in effect and satisfied on the heap inside the memory [m]
*)
val locks_invariant (e:inames) (m:mem u#a) : slprop u#a
val full_mem_pred: mem -> prop
let full_mem = m:mem{full_mem_pred m}
(** Memory refined with invariants and a footprint *)
let hmem_with_inv_except (e:inames) (fp:slprop u#a) =
m:full_mem{inames_ok e m /\ interp (fp `star` locks_invariant e m) m}
(** Memory refined with just a footprint and no invariants *)
let hmem_with_inv (fp:slprop u#a) = hmem_with_inv_except S.empty fp
/// The following lemmas are needed in `Steel.Effect`
(** Any separation logic proposition valid over [m] is also valid on [core_mem m] *)
val core_mem_interp (hp:slprop u#a) (m:mem u#a)
: Lemma
(requires True)
(ensures (interp hp (core_mem m) <==> interp hp m))
[SMTPat (interp hp (core_mem m))]
(** Interpretation is an affine heap proposition. See [Steel.Heap.interp_depends_only_on] *)
val interp_depends_only_on (hp:slprop u#a)
: Lemma
(forall (m0:hmem hp) (m1:mem u#a{disjoint m0 m1}).
interp hp m0 <==> interp hp (join m0 m1))
(** This adds a SMT trigger to the [Steel.Heap.affine_star] lemma *)
let affine_star_smt (p q:slprop u#a) (m:mem u#a)
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
[SMTPat (interp (p `star` q) m)]
= affine_star p q m | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Memory.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sl: Steel.Memory.slprop -> f: (_: Steel.Memory.hmem sl -> Prims.prop) -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.hmem",
"Prims.prop",
"Prims.l_and",
"Prims.l_Forall",
"Steel.Memory.mem",
"Steel.Memory.interp",
"Prims.l_iff",
"Steel.Memory.core_mem",
"Steel.Memory.disjoint",
"Prims.l_imp",
"Steel.Memory.join"
] | [] | false | false | false | false | true | let mem_prop_is_affine (sl: slprop u#a) (f: (hmem sl -> Tot prop)) : Tot prop =
| (forall m. f m <==> f (core_mem m)) /\
(forall (m0: hmem sl) m1. (disjoint m0 m1 /\ interp sl (join m0 m1)) ==> (f m0 <==> f (join m0 m1))) | false |
Steel.Effect.Atomic.fsti | Steel.Effect.Atomic.gget | val gget (#opened: inames) (p: vprop)
: SteelGhost (erased (t_of p))
opened
p
(fun _ -> p)
(requires (fun _ -> True))
(ensures (fun h0 res h1 -> h1 p == h0 p /\ reveal res == h0 p /\ reveal res == h1 p)) | val gget (#opened: inames) (p: vprop)
: SteelGhost (erased (t_of p))
opened
p
(fun _ -> p)
(requires (fun _ -> True))
(ensures (fun h0 res h1 -> h1 p == h0 p /\ reveal res == h0 p /\ reveal res == h1 p)) | let gget (#opened:inames) (p: vprop) : SteelGhost (erased (t_of p))
opened
p (fun _ -> p)
(requires (fun _ -> True))
(ensures (fun h0 res h1 ->
h1 p == h0 p /\
reveal res == h0 p /\
reveal res == h1 p
))
=
let m = get #p () in
hide ((reveal m) p) | {
"file_name": "lib/steel/Steel.Effect.Atomic.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 531,
"start_col": 0,
"start_line": 520
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect.Atomic
open Steel.Memory
module T = FStar.Tactics
include Steel.Effect.Common
/// This module defines atomic and ghost variants of the Steel effect
#set-options "--warn_error -330 --ide_id_info_off" //turn off the experimental feature warning
(*** SteelAGCommon effect ***)
/// The underlying representation of atomic and ghost computations, very similar to Steel
/// computations in Steel.Effect.
/// The opened_invariants index corresponds to the set of currently opened invariants,
/// and is relevant to the with_invariant combinator below
/// The observability bit will always be Unobservable for ghost computations
val repr (a:Type u#a)
(already_framed:bool)
(opened_invariants:inames)
(g:observability)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
: Type u#(max a 2)
/// Logical precondition of the return combinator
unfold
let return_req (p:vprop) : req_t p = fun _ -> True
/// Logical postcondition of the return combinator:
/// The returned value [r] corresponds to the value passed to the return [x],
/// and return leaves selectors of all resources in [p] unchanged
unfold
let return_ens (a:Type) (x:a) (p:a -> vprop) : ens_t (p x) a p =
fun h0 r h1 -> r == x /\ frame_equalities (p x) h0 (focus_rmem h1 (p x))
/// Monadic return combinator for the Steel effect. It is parametric in the postcondition
/// The vprop precondition is annotated with the return_pre predicate to enable special handling,
/// as explained in Steel.Effect.Common
val return_ (a:Type u#a)
(x:a)
(opened_invariants:inames)
(#[@@@ framing_implicit] p:a -> vprop)
: repr a true opened_invariants Unobservable
(return_pre (p x)) p
(return_req (p x)) (return_ens a x p)
/// Logical precondition for the composition (bind) of two Steel computations:
/// The postcondition of the first computation must imply the precondition of the second computation,
/// and also ensure that any equalities abducted during frame inference inside the predicate [pr] are satisfied
unfold
let bind_req (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t)
(#pr:a -> prop)
(req_g:(x:a -> req_t (pre_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
: req_t (pre_f `star` frame_f)
= fun m0 ->
req_f (focus_rmem m0 pre_f) /\
(forall (x:a) (h1:hmem (post_f x `star` frame_f)).
(ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
frame_equalities frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f))
==> pr x /\
(can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
(req_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x))))
/// Logical postcondition for the composition (bind) of two Steel computations:
/// The precondition of the first computation was satisfied in the initial state, and there
/// exists an intermediate state where the two-state postcondition of the first computation was
/// satisfied, and which yields the validity of the two-state postcondition of the second computation
/// on the final state [m2] with the returned value [y]
/// Note that the ensures for the bind below asserts req_f
/// This is not necessary, but an explicit assert may help the solver
unfold
let bind_ens (#a:Type) (#b:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#pr:a -> prop)
(ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(post:post_t b)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(_:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
: ens_t (pre_f `star` frame_f) b post
= fun m0 y m2 ->
req_f (focus_rmem m0 pre_f) /\
(exists (x:a) (h1:hmem (post_f x `star` frame_f)).
pr x /\
(
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
frame_equalities frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f) /\
frame_equalities (frame_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (frame_g x)) (focus_rmem m2 (frame_g x)) /\
ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
(ens_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x)) y (focus_rmem m2 (post_g x y))))
/// Steel atomic effect combinator to compose two Steel atomic computations
/// Separation logic VCs are squashed goals passed as implicits, annotated with the framing_implicit
/// attribute. This indicates that they will be discharged by the tactic in Steel.Effect.Common
/// Requires/ensures logical VCs are defined using weakest preconditions combinators defined above,
/// and discharged by SMT.
/// The requires clause obs_at_most_one ensures that the composition of two atomic, non-ghost computations is not considered an atomic computation
val bind (a:Type) (b:Type)
(opened_invariants:inames)
(o1:eqtype_as_type observability)
(o2:eqtype_as_type observability)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a)
(#[@@@ framing_implicit] req_f:req_t pre_f) (#[@@@ framing_implicit] ens_f:ens_t pre_f a post_f)
(#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:a -> post_t b)
(#[@@@ framing_implicit] req_g:(x:a -> req_t (pre_g x))) (#[@@@ framing_implicit] ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:a -> vprop)
(#[@@@ framing_implicit] post:post_t b)
(#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame_f))
(#[@@@ framing_implicit] _ : squash (maybe_emp_dep framed_g frame_g))
(#[@@@ framing_implicit] pr:a -> prop)
(#[@@@ framing_implicit] p1:squash (can_be_split_forall_dep pr
(fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(#[@@@ framing_implicit] p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
(f:repr a framed_f opened_invariants o1 pre_f post_f req_f ens_f)
(g:(x:a -> repr b framed_g opened_invariants o2 (pre_g x) (post_g x) (req_g x) (ens_g x)))
: Pure (repr b true opened_invariants (join_obs o1 o2)
(pre_f `star` frame_f)
post
(bind_req req_f ens_f req_g frame_f frame_g p1)
(bind_ens req_f ens_f ens_g frame_f frame_g post p1 p2)
)
(requires obs_at_most_one o1 o2)
(ensures fun _ -> True)
/// Logical precondition for subtyping relation for Steel atomic computation.
unfold
let subcomp_pre (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#p:prop)
(_:squash (can_be_split_dep p pre_g (pre_f `star` frame)))
(_:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: pure_pre
// The call to with_tactic allows us to reduce VCs in a controlled way, once all
// uvars have been resolved.
// To ensure an SMT-friendly encoding of the VC, it needs to be encapsulated in a squash call
= T.rewrite_with_tactic vc_norm (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> p /\
(can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
p ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
/// Subtyping combinator for Steel atomic computations.
/// Computation [f] is given type `repr a framed_g pre_g post_g req_g ens_g`.
/// As for bind, separation logic goals are encoded as squashed implicits which will be discharged
/// by tactic, while logical requires/ensures operating on selectors are discharged by SMT.
/// The requires clause allows a ghost computation to be considered as an atomic computation,
/// but not the converse
val subcomp (a:Type)
(opened_invariants:inames)
(o1:eqtype_as_type observability)
(o2:eqtype_as_type observability)
(#framed_f: eqtype_as_type bool)
(#framed_g: eqtype_as_type bool)
(#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a)
(#[@@@ framing_implicit] req_f:req_t pre_f) (#[@@@ framing_implicit] ens_f:ens_t pre_f a post_f)
(#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a)
(#[@@@ framing_implicit] req_g:req_t pre_g) (#[@@@ framing_implicit] ens_g:ens_t pre_g a post_g)
(#[@@@ framing_implicit] frame:vprop)
(#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame))
(#[@@@ framing_implicit] p: prop)
(#[@@@ framing_implicit] p1:squash (can_be_split_dep p pre_g (pre_f `star` frame)))
(#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
(f:repr a framed_f opened_invariants o1 pre_f post_f req_f ens_f)
: Pure (repr a framed_g opened_invariants o2 pre_g post_g req_g ens_g)
(requires (o1 = Unobservable || o2 = Observable) /\
subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures fun _ -> True)
/// Logical precondition for the if_then_else combinator
unfold
let if_then_else_req
(#pre_f:pre_t) (#pre_g:pre_t) (#frame_f #frame_g:vprop)
(#pr: prop)
(s_pre: squash (can_be_split_dep pr (pre_f `star` frame_f) (pre_g `star` frame_g)))
(req_then:req_t pre_f) (req_else:req_t pre_g)
(p:Type0)
: req_t (pre_f `star` frame_f)
= fun h -> pr /\ (
can_be_split_trans (pre_f `star` frame_f) (pre_g `star` frame_g) pre_g;
(p ==> req_then (focus_rmem h pre_f)) /\
((~ p) ==> req_else (focus_rmem h pre_g)))
/// Logical postcondition for the if_then_else combinator
unfold
let if_then_else_ens (#a:Type)
(#pre_f:pre_t) (#pre_g:pre_t) (#post_f:post_t a) (#post_g:post_t a)
(#frame_f #frame_g:vprop) (#pr:prop)
(s1: squash (can_be_split_dep pr (pre_f `star` frame_f) (pre_g `star` frame_g)))
(s2: squash (equiv_forall (fun x -> post_f x `star` frame_f) (fun x -> post_g x `star` frame_g)))
(ens_then:ens_t pre_f a post_f) (ens_else:ens_t pre_g a post_g)
(p:Type0)
: ens_t (pre_f `star` frame_f) a (fun x -> post_f x `star` frame_f)
= fun h0 x h1 -> pr /\ (
can_be_split_trans (pre_f `star` frame_f) (pre_g `star` frame_g) pre_g;
can_be_split_trans (post_f x `star` frame_f) (post_g x `star` frame_g) (post_g x);
(p ==> ens_then (focus_rmem h0 pre_f) x (focus_rmem h1 (post_f x))) /\
((~ p) ==> ens_else (focus_rmem h0 pre_g) x (focus_rmem h1 (post_g x))))
/// If_then_else combinator for Steel computations.
/// The soundness of this combinator is automatically proven with respect to the subcomp
/// subtyping combinator defined above by the F* layered effects framework.
/// The if_then_else combinator is only applicable to ghost computations, not to atomic computations.
/// This is encoded by ensuring that computations f and g both are [Unobservable], and that
/// the resulting computation therefore is [Unobservable]
let if_then_else (a:Type)
(o:inames)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] pre_g:pre_t)
(#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] post_g:post_t a)
(#[@@@ framing_implicit] req_then:req_t pre_f) (#[@@@ framing_implicit] ens_then:ens_t pre_f a post_f)
(#[@@@ framing_implicit] req_else:req_t pre_g) (#[@@@ framing_implicit] ens_else:ens_t pre_g a post_g)
(#[@@@ framing_implicit] frame_f : vprop)
(#[@@@ framing_implicit] frame_g : vprop)
(#[@@@ framing_implicit] pr : prop)
(#[@@@ framing_implicit] me1 : squash (maybe_emp framed_f frame_f))
(#[@@@ framing_implicit] me2 : squash (maybe_emp framed_g frame_g))
(#[@@@ framing_implicit] s_pre: squash (can_be_split_dep pr (pre_f `star` frame_f) (pre_g `star` frame_g)))
(#[@@@ framing_implicit] s_post: squash (equiv_forall (fun x -> post_f x `star` frame_f) (fun x -> post_g x `star` frame_g)))
(f:repr a framed_f o Unobservable pre_f post_f req_then ens_then)
(g:repr a framed_g o Unobservable pre_g post_g req_else ens_else)
(p:bool)
: Type
= repr a true o Unobservable
(pre_f `star` frame_f) (fun x -> post_f x `star` frame_f)
(if_then_else_req s_pre req_then req_else p)
(if_then_else_ens s_pre s_post ens_then ens_else p)
/// Assembling the combinators defined above into an actual effect
/// The total keyword ensures that all ghost and atomic computations terminate.
[@@ ite_soundness_by ite_attr; primitive_extraction]
total
reflectable
effect {
SteelAGCommon (a:Type)
(framed:bool)
(opened_invariants:inames)
(o:observability)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
with { repr = repr;
return = return_;
bind = bind;
subcomp = subcomp;
if_then_else = if_then_else }
}
/// Defining a SteelAtomic effect for atomic Steel computations.
/// F*'s effect system is nominal; defining this as a `new_effect` ensures
/// that SteelAtomic computations are distinct from any computation with the
/// SteelAGCommon effect, while allowing this effect to directly inherit
/// the SteelAGCommon combinators
[@@ ite_soundness_by ite_attr]
total
reflectable
new_effect SteelAtomicBase = SteelAGCommon
/// The two user-facing effects, corresponding to not yet framed (SteelAtomic)
/// and already framed (SteelAtomicF) computations.
/// In the ICFP21 paper, this is modeled by the |- and |-_F modalities.
/// Both effects are instantiated with the Observable bit, indicating that they do not
/// model ghost computations
effect SteelAtomic (a:Type)
(opened:inames)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
= SteelAtomicBase a false opened Observable pre post req ens
effect SteelAtomicF (a:Type)
(opened:inames)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
= SteelAtomicBase a true opened Observable pre post req ens
effect SteelAtomicU (a:Type)
(opened:inames)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
= SteelAtomicBase a false opened Unobservable pre post req ens
effect SteelAtomicUF (a:Type)
(opened:inames)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
= SteelAtomicBase a true opened Unobservable pre post req ens
(* Composing SteelAtomic and Pure computations *)
/// Logical precondition of a Pure and a SteelAtomic computation composition.
/// The current state (memory) must satisfy the precondition of the SteelAtomic computation,
/// and the wp of the PURE computation `as_requires wp` must also be satisfied
unfold
let bind_pure_steel__req (#a:Type) (wp:pure_wp a)
(#pre:pre_t) (req:a -> req_t pre)
: req_t pre
= fun m -> wp (fun x -> (req x) m)
/// Logical postcondition of a Pure and a SteelAtomic composition.
/// There exists an intermediate value (the output of the Pure computation) such that
/// the postcondition of the pure computation is satisfied.
unfold
let bind_pure_steel__ens (#a:Type) (#b:Type)
(wp:pure_wp a)
(#pre:pre_t) (#post:post_t b) (ens:a -> ens_t pre b post)
: ens_t pre b post
= fun m0 r m1 -> as_requires wp /\ (exists (x:a). as_ensures wp x /\ ((ens x) m0 r m1))
/// The composition combinator
val bind_pure_steela_ (a:Type) (b:Type)
(opened_invariants:inames)
(o:eqtype_as_type observability)
(#[@@@ framing_implicit] wp:pure_wp a)
(#framed: eqtype_as_type bool)
(#[@@@ framing_implicit] pre:pre_t) (#[@@@ framing_implicit] post:post_t b)
(#[@@@ framing_implicit] req:a -> req_t pre) (#[@@@ framing_implicit] ens:a -> ens_t pre b post)
(f:eqtype_as_type unit -> PURE a wp)
(g:(x:a -> repr b framed opened_invariants o pre post (req x) (ens x)))
: repr b framed opened_invariants o
pre
post
(bind_pure_steel__req wp req)
(bind_pure_steel__ens wp ens)
/// A polymonadic composition between Pure computations (in the PURE effects) and Steel atomic computations (in the SteelAtomicBase effect).
/// Note that the SteelAtomicBase, PURE case is not handled here:
/// In this case, a SteelAtomicBase return is automatically inserted by the F* typechecker
polymonadic_bind (PURE, SteelAtomicBase) |> SteelAtomicBase = bind_pure_steela_
/// A version of the SteelAtomic effect with trivial requires and ensures clauses
///
effect SteelAtomicBaseT (a:Type) (opened:inames) (obs:observability) (pre:pre_t) (post:post_t a) =
SteelAtomicBase a false opened obs pre post (fun _ -> True) (fun _ _ _ -> True)
effect SteelAtomicT (a:Type) (opened:inames) (pre:pre_t) (post:post_t a) =
SteelAtomic a opened pre post (fun _ -> True) (fun _ _ _ -> True)
effect SteelAtomicUT (a:Type) (opened:inames) (pre:pre_t) (post:post_t a) =
SteelAtomicU a opened pre post (fun _ -> True) (fun _ _ _ -> True)
(*** SteelGhost effect ***)
/// Defining an effect for ghost, computationally irrelevant Steel computations.
/// As for SteelAtomicBase, this effect is defined using the `new_effect` keyword,
/// which ensures that despite these computations inheriting the SteelAGCommon effect
/// combinators, any ghost computation will be separated from atomic computations in F*'s
/// effect system.
/// The erasable attribute ensures that such computations will not be extracted.
/// Using any SteelGhost computation in a computationally relevant context will require the
/// computation to have a non-informative (erasable) return value to ensure the soundness
/// of the extraction. If this is not the case, the F* typechecker will raise an error
[@@ erasable; ite_soundness_by ite_attr]
total
reflectable
new_effect SteelGhostBase = SteelAGCommon
/// The two user-facing effects, corresponding to not yet framed (SteelGhost)
/// and already framed (SteelGhostF) computations.
/// In the ICFP21 paper, this is modeled by the |- and |-_F modalities.
/// Both effects are instantiated with the UnObservable bit, indicating that they
/// model ghost computations, which can be freely composed with each other
effect SteelGhost (a:Type)
(opened:inames)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
= SteelGhostBase a false opened Unobservable pre post req ens
effect SteelGhostF (a:Type)
(opened:inames)
(pre:pre_t)
(post:post_t a)
(req:req_t pre)
(ens:ens_t pre a post)
= SteelGhostBase a true opened Unobservable pre post req ens
/// A polymonadic composition between Pure computations (in the PURE effects) and Steel ghost computations (in the SteelGhostBase effect).
/// Note that the SteelGhostBase, PURE case is not handled here:
/// In this case, a SteelGhostBase return is automatically inserted by the F* typechecker
polymonadic_bind (PURE, SteelGhostBase) |> SteelGhostBase = bind_pure_steela_
/// A version of the SteelGhost effect with trivial requires and ensures clauses
effect SteelGhostT (a:Type) (opened:inames) (pre:pre_t) (post:post_t a) =
SteelGhost a opened pre post (fun _ -> True) (fun _ _ _ -> True)
(***** Lift relations *****)
/// Any Steel ghost computation can always be lifted to an atomic computation if needed.
/// Note that because SteelGhost is marked as erasable, the F* typechecker will throw an error
/// if this lift is applied to a ghost computation with an informative return value
val lift_ghost_atomic
(a:Type)
(opened:inames)
(#framed:eqtype_as_type bool)
(#[@@@ framing_implicit] pre:pre_t) (#[@@@ framing_implicit] post:post_t a)
(#[@@@ framing_implicit] req:req_t pre) (#[@@@ framing_implicit] ens:ens_t pre a post)
(f:repr a framed opened Unobservable pre post req ens)
: repr a framed opened Unobservable pre post req ens
sub_effect SteelGhostBase ~> SteelAtomicBase = lift_ghost_atomic
/// If the set of currently opened invariants is empty, an atomic Steel computation can be lifted
/// to a generic Steel computation.
/// Note that lifts are transitive in the effect lattice; hence a Steel ghost computation
/// will automatically be lifted to a generic Steel computation if needed by successively applying the lift from ghost to atomic computations, followed by the lift from atomic to generic steel computations, as long as all preconditions are satisfied
val lift_atomic_steel
(a:Type)
(o:eqtype_as_type observability)
(#framed:eqtype_as_type bool)
(#[@@@ framing_implicit] pre:pre_t) (#[@@@ framing_implicit] post:post_t a)
(#[@@@ framing_implicit] req:req_t pre) (#[@@@ framing_implicit] ens:ens_t pre a post)
(f:repr a framed Set.empty o pre post req ens)
: Steel.Effect.repr a framed pre post req ens
sub_effect SteelAtomicBase ~> Steel.Effect.SteelBase = lift_atomic_steel
/// Lifting actions from the memory model to Steel atomic and ghost computations.
/// Only to be used internally, for the core primitives of the Steel framework
[@@warn_on_use "as_atomic_action is a trusted primitive"]
val as_atomic_action (#a:Type u#a)
(#opened_invariants:inames)
(#fp:slprop)
(#fp': a -> slprop)
(f:action_except a opened_invariants fp fp')
: SteelAtomicT a opened_invariants (to_vprop fp) (fun x -> to_vprop (fp' x))
[@@warn_on_use "as_atomic_action is a trusted primitive"]
val as_atomic_action_ghost (#a:Type u#a)
(#opened_invariants:inames)
(#fp:slprop)
(#fp': a -> slprop)
(f:action_except a opened_invariants fp fp')
: SteelGhostT a opened_invariants (to_vprop fp) (fun x -> to_vprop (fp' x))
[@@warn_on_use "as_unobservable_atomic_action is a trusted primitive"]
val as_atomic_unobservable_action
(#a:Type u#a)
(#opened_invariants:inames)
(#fp:slprop)
(#fp': a -> slprop)
(f:action_except a opened_invariants fp fp')
: SteelAtomicUT a opened_invariants (to_vprop fp) (fun x -> to_vprop (fp' x))
(*** Some helper functions ***)
open FStar.Ghost
/// Returning the current global selector in the context
val get (#p:vprop) (#opened:inames) (_:unit) : SteelGhostF (erased (rmem p))
opened
p (fun _ -> p)
(requires fun _ -> True)
(ensures fun h0 r h1 -> frame_equalities p h0 h1 /\ frame_equalities p r h1) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Effect.Atomic.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Common",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.Effect.Common.vprop
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (Steel.Effect.Common.t_of p)) | Steel.Effect.Atomic.SteelGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Ghost.hide",
"Steel.Effect.Common.t_of",
"FStar.Ghost.reveal",
"Steel.Effect.Common.rmem",
"FStar.Ghost.erased",
"Steel.Effect.Common.rmem'",
"Steel.Effect.Common.valid_rmem",
"Steel.Effect.Atomic.get",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Steel.Effect.Common.normal"
] | [] | false | true | false | false | false | let gget (#opened: inames) (p: vprop)
: SteelGhost (erased (t_of p))
opened
p
(fun _ -> p)
(requires (fun _ -> True))
(ensures (fun h0 res h1 -> h1 p == h0 p /\ reveal res == h0 p /\ reveal res == h1 p)) =
| let m = get #p () in
hide ((reveal m) p) | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_ret | val parse_ret (#t:Type) (v:t)
: Tot (parser ret_kind t) | val parse_ret (#t:Type) (v:t)
: Tot (parser ret_kind t) | let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 22,
"end_line": 54,
"start_col": 0,
"start_line": 52
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: t -> EverParse3d.Prelude.parser EverParse3d.Kinds.ret_kind t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.parse_ret",
"EverParse3d.Prelude.parser",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"EverParse3d.Kinds.ret_kind"
] | [] | false | false | false | false | false | let parse_ret #t (v: t) : Tot (parser ret_kind t) =
| LPC.parse_ret #t v | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.is_weaker_than | val is_weaker_than : k: EverParse3d.Kinds.parser_kind nz1 wk1 -> k': EverParse3d.Kinds.parser_kind nz2 wk2 -> Type0 | let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k' | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 80,
"end_line": 34,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: EverParse3d.Kinds.parser_kind nz1 wk1 -> k': EverParse3d.Kinds.parser_kind nz2 wk2 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"LowParse.Spec.Base.is_weaker_than"
] | [] | false | false | false | false | true | let is_weaker_than #nz1 #wk1 (k: parser_kind nz1 wk1) #nz2 #wk2 (k': parser_kind nz2 wk2) =
| k `LP.is_weaker_than` k' | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.parser | val parser (#nz:bool) (#wk: weak_kind) (k:parser_kind nz wk) (t:Type u#r) : Type u#r | val parser (#nz:bool) (#wk: weak_kind) (k:parser_kind nz wk) (t:Type u#r) : Type u#r | let parser k t = LP.parser k t | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 30,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
//////////////////////////////////////////////////////////////////////////////// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: EverParse3d.Kinds.parser_kind nz wk -> t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"LowParse.Spec.Base.parser"
] | [] | false | false | false | false | true | let parser k t =
| LP.parser k t | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.injective_map | val injective_map : a: Type -> b: Type -> Type | let injective_map a b = (a -> Tot b) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 36,
"end_line": 67,
"start_col": 0,
"start_line": 67
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let injective_map a b =
| (a -> Tot b) | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_dep_pair | val parse_dep_pair (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: Type) (p1: parser k1 t1)
(#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2: (t1 -> Tot Type)) (p2: (x: t1) -> parser k2 (t2 x))
: Tot (parser (and_then_kind k1 k2) (dtuple2 t1 t2) ) | val parse_dep_pair (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: Type) (p1: parser k1 t1)
(#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2: (t1 -> Tot Type)) (p2: (x: t1) -> parser k2 (t2 x))
: Tot (parser (and_then_kind k1 k2) (dtuple2 t1 t2) ) | let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 59,
"start_col": 0,
"start_line": 58
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: EverParse3d.Prelude.parser k1 t1 -> p2: (x: t1 -> EverParse3d.Prelude.parser k2 (t2 x))
-> EverParse3d.Prelude.parser (EverParse3d.Kinds.and_then_kind k1 k2) (Prims.dtuple2 t1 t2) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"EverParse3d.Prelude.parser",
"EverParse3d.Kinds.weak_kind",
"LowParse.Spec.Combinators.parse_dtuple2",
"Prims.op_BarBar",
"EverParse3d.Kinds.and_then_kind",
"Prims.dtuple2"
] | [] | false | false | false | false | false | let parse_dep_pair p1 p2 =
| LPC.parse_dtuple2 p1 p2 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_filter | val parse_filter (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t) (f:(t -> bool))
: Tot (parser (filter_kind k) (refine t f)) | val parse_filter (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t) (f:(t -> bool))
: Tot (parser (filter_kind k) (refine t f)) | let parse_filter p f
= LPC.parse_filter p f | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 24,
"end_line": 71,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: EverParse3d.Prelude.parser k t -> f: (_: t -> Prims.bool)
-> EverParse3d.Prelude.parser (EverParse3d.Kinds.filter_kind k) (EverParse3d.Prelude.refine t f) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"LowParse.Spec.Combinators.parse_filter",
"EverParse3d.Kinds.filter_kind",
"EverParse3d.Prelude.refine"
] | [] | false | false | false | false | false | let parse_filter p f =
| LPC.parse_filter p f | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.nlist | val nlist (n:U32.t) (t:Type u#r) : Type u#r | val nlist (n:U32.t) (t:Type u#r) : Type u#r | let nlist (n:U32.t) (t:Type) = list t | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 37,
"end_line": 101,
"start_col": 0,
"start_line": 101
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.UInt32.t -> t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.list"
] | [] | false | false | false | true | true | let nlist (n: U32.t) (t: Type) =
| list t | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_pair | val parse_pair (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:_) (p1:parser k1 t1)
(#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:_) (p2:parser k2 t2)
: Tot (parser (and_then_kind k1 k2) (t1 * t2)) | val parse_pair (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:_) (p1:parser k1 t1)
(#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:_) (p2:parser k2 t2)
: Tot (parser (and_then_kind k1 k2) (t1 * t2)) | let parse_pair p1 p2
= LPC.nondep_then p1 p2 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 25,
"end_line": 64,
"start_col": 0,
"start_line": 63
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: EverParse3d.Prelude.parser k1 t1 -> p2: EverParse3d.Prelude.parser k2 t2
-> EverParse3d.Prelude.parser (EverParse3d.Kinds.and_then_kind k1 k2) (t1 * t2) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"EverParse3d.Prelude.parser",
"EverParse3d.Kinds.weak_kind",
"LowParse.Spec.Combinators.nondep_then",
"Prims.op_BarBar",
"EverParse3d.Kinds.and_then_kind",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let parse_pair p1 p2 =
| LPC.nondep_then p1 p2 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.all_bytes | val all_bytes: Type0 | val all_bytes: Type0 | let all_bytes = Seq.seq LP.byte | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 112,
"start_col": 0,
"start_line": 112
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte"
] | [] | false | false | false | true | true | let all_bytes =
| Seq.seq LP.byte | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.t_exact | val t_exact (n:U32.t) (t:Type u#r) : Type u#r | val t_exact (n:U32.t) (t:Type u#r) : Type u#r | let t_exact (n:U32.t) (t:Type) = t | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 34,
"end_line": 137,
"start_col": 0,
"start_line": 137
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.UInt32.t -> t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t"
] | [] | false | false | false | true | true | let t_exact (n: U32.t) (t: Type) =
| t | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.t_at_most | val t_at_most (n:U32.t) (t:Type u#r) : Type u#r | val t_at_most (n:U32.t) (t:Type u#r) : Type u#r | let t_at_most (n:U32.t) (t:Type) = t & all_bytes | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 122,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
//////////////////////////////////////////////////////////////////////////////// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.UInt32.t -> t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"FStar.Pervasives.Native.tuple2",
"EverParse3d.Prelude.all_bytes"
] | [] | false | false | false | true | true | let t_at_most (n: U32.t) (t: Type) =
| t & all_bytes | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.reader | val reader (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:_) (p:parser k t) : Type u#1 | val reader (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:_) (p:parser k t) : Type u#1 | let reader p = LPLC.leaf_reader p | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 156,
"start_col": 0,
"start_line": 156
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
//////////////////////////////////////////////////////////////////////////////// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: EverParse3d.Prelude.parser k t -> Type | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"EverParse3d.Prelude.parser",
"LowParse.Low.Base.leaf_reader"
] | [] | false | false | false | false | true | let reader p =
| LPLC.leaf_reader p | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read_filter | val read_filter (#nz:_)
(#k: parser_kind nz WeakKindStrongPrefix)
(#t: Type)
(#p: parser k t)
(p32: reader p)
(f: (t -> bool))
: reader (parse_filter p f) | val read_filter (#nz:_)
(#k: parser_kind nz WeakKindStrongPrefix)
(#t: Type)
(#p: parser k t)
(p32: reader p)
(f: (t -> bool))
: reader (parse_filter p f) | let read_filter p32 f
= LPLC.read_filter p32 f | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 160,
"start_col": 0,
"start_line": 159
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p32: EverParse3d.Prelude.reader p -> f: (_: t -> Prims.bool)
-> EverParse3d.Prelude.reader (EverParse3d.Prelude.parse_filter p f) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"EverParse3d.Prelude.parser",
"EverParse3d.Prelude.reader",
"LowParse.Low.Combinators.read_filter",
"EverParse3d.Kinds.filter_kind",
"EverParse3d.Prelude.refine",
"EverParse3d.Prelude.parse_filter"
] | [] | false | false | false | false | false | let read_filter p32 f =
| LPLC.read_filter p32 f | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.cstring | val cstring
(t: eqtype)
(terminator: t)
: Tot Type0 | val cstring
(t: eqtype)
(terminator: t)
: Tot Type0 | let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 55,
"end_line": 260,
"start_col": 0,
"start_line": 256
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Prims.eqtype -> terminator: t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"EverParse3d.Prelude.cond_string_up_to"
] | [] | false | false | false | false | true | let cstring (t: eqtype) (terminator: t) : Tot Type0 =
| LUT.parse_list_up_to_t (cond_string_up_to terminator) | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.all_zeros | val all_zeros: Type0 | val all_zeros: Type0 | let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 271,
"start_col": 0,
"start_line": 271
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"LowParse.Spec.Combinators.parse_filter_refine",
"FStar.UInt8.t",
"EverParse3d.Prelude.is_zero"
] | [] | false | false | false | true | true | let all_zeros =
| list (LowParse.Spec.Combinators.parse_filter_refine is_zero) | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.cond_string_up_to | val cond_string_up_to (#t: eqtype) (terminator x: t) : Tot bool | val cond_string_up_to (#t: eqtype) (terminator x: t) : Tot bool | let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 16,
"end_line": 254,
"start_col": 0,
"start_line": 249
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | terminator: t -> x: t -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.op_Equality",
"Prims.bool"
] | [] | false | false | false | false | false | let cond_string_up_to (#t: eqtype) (terminator x: t) : Tot bool =
| x = terminator | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.is_zero | val is_zero (x: FStar.UInt8.t) : Tot bool | val is_zero (x: FStar.UInt8.t) : Tot bool | let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 269,
"start_col": 0,
"start_line": 269
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ())) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.op_Equality",
"FStar.UInt8.__uint_to_t",
"Prims.bool"
] | [] | false | false | false | true | false | let is_zero (x: FStar.UInt8.t) : Tot bool =
| x = 0uy | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_all_zeros | val parse_all_zeros: parser kind_all_zeros all_zeros | val parse_all_zeros: parser kind_all_zeros all_zeros | let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 127,
"end_line": 272,
"start_col": 0,
"start_line": 272
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind_all_zeros EverParse3d.Prelude.all_zeros | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.List.parse_list",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Int.parse_u8_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"FStar.UInt8.t",
"EverParse3d.Prelude.is_zero",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.Int.parse_u8"
] | [] | false | false | false | false | false | let parse_all_zeros =
| LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8
is_zero) | false |
STLC.Core.fst | STLC.Core.index | val index : Type0 | let index = nat | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 15,
"end_line": 12,
"start_col": 0,
"start_line": 12
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat"
] | [] | false | false | false | true | true | let index =
| nat | false |
|
Pulse.Soundness.Admit.fst | Pulse.Soundness.Admit.admit_soundess | val admit_soundess
(#g:stt_env)
(#t:st_term)
(#c:comp)
(d:st_typing g t c{T_Admit? d})
: GTot (RT.tot_typing (elab_env g)
(elab_st_typing d)
(elab_comp c)) | val admit_soundess
(#g:stt_env)
(#t:st_term)
(#c:comp)
(d:st_typing g t c{T_Admit? d})
: GTot (RT.tot_typing (elab_env g)
(elab_st_typing d)
(elab_comp c)) | let admit_soundess
(#g:stt_env)
(#t:st_term)
(#c:comp)
(d:st_typing g t c{T_Admit? d})
: GTot (RT.tot_typing (elab_env g)
(elab_st_typing d)
(elab_comp c)) =
let T_Admit _ s c st_typing = d in
let rt_typing, rpre_typing, rpost_typing = Comp.stc_soundness st_typing in
match c with
| STT ->
WT.stt_admit_typing rt_typing rpre_typing rpost_typing
| STT_Atomic ->
WT.stt_atomic_admit_typing rt_typing rpre_typing rpost_typing
| STT_Ghost ->
WT.stt_ghost_admit_typing rt_typing rpre_typing rpost_typing | {
"file_name": "lib/steel/pulse/Pulse.Soundness.Admit.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 51,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Soundness.Admit
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Elaborate.Pure
open Pulse.Elaborate.Core
open Pulse.Elaborate
open Pulse.Soundness.Common
module WT = Pulse.Steel.Wrapper.Typing
module Comp = Pulse.Soundness.Comp | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Steel.Wrapper.Typing.fsti.checked",
"Pulse.Soundness.Comp.fsti.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Elaborate.Core.fst.checked",
"Pulse.Elaborate.fsti.checked",
"prims.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Soundness.Admit.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Soundness.Comp",
"short_module": "Comp"
},
{
"abbrev": true,
"full_module": "Pulse.Steel.Wrapper.Typing",
"short_module": "WT"
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | d: Pulse.Typing.st_typing g t c {T_Admit? d}
-> Prims.GTot
(FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g)
(Pulse.Elaborate.Core.elab_st_typing d)
(Pulse.Elaborate.Pure.elab_comp c)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Soundness.Common.stt_env",
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.comp",
"Pulse.Typing.st_typing",
"Prims.b2t",
"Pulse.Typing.uu___is_T_Admit",
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.ctag",
"Pulse.Typing.st_comp_typing",
"FStar.Reflection.Typing.tot_typing",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"FStar.Reflection.Typing.tm_type",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Reflection.Util.vprop_tm",
"Pulse.Reflection.Util.mk_abs",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Pulse.Soundness.Common.post1_type_bind",
"Pulse.Steel.Wrapper.Typing.stt_admit_typing",
"Pulse.Steel.Wrapper.Typing.stt_atomic_admit_typing",
"Pulse.Steel.Wrapper.Typing.stt_ghost_admit_typing",
"Pulse.Elaborate.Core.elab_st_typing",
"Pulse.Elaborate.Pure.elab_comp",
"FStar.Pervasives.Native.tuple3",
"Pulse.Soundness.Comp.stc_soundness"
] | [] | false | false | false | false | false | let admit_soundess (#g: stt_env) (#t: st_term) (#c: comp) (d: st_typing g t c {T_Admit? d})
: GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c)) =
| let T_Admit _ s c st_typing = d in
let rt_typing, rpre_typing, rpost_typing = Comp.stc_soundness st_typing in
match c with
| STT -> WT.stt_admit_typing rt_typing rpre_typing rpost_typing
| STT_Atomic -> WT.stt_atomic_admit_typing rt_typing rpre_typing rpost_typing
| STT_Ghost -> WT.stt_ghost_admit_typing rt_typing rpre_typing rpost_typing | false |
STLC.Core.fst | STLC.Core.var | val var : Type0 | let var = nat | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 11,
"start_col": 0,
"start_line": 11
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat"
] | [] | false | false | false | true | true | let var =
| nat | false |
|
STLC.Core.fst | STLC.Core.ln | val ln : e: STLC.Core.stlc_exp -> Prims.bool | let ln e = ln' e (-1) | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 40,
"start_col": 0,
"start_line": 40
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.ln'",
"Prims.op_Minus",
"Prims.bool"
] | [] | false | false | false | true | false | let ln e =
| ln' e (- 1) | false |
|
STLC.Core.fst | STLC.Core.open_exp | val open_exp : e: STLC.Core.stlc_exp -> v: STLC.Core.var
-> e': STLC.Core.stlc_exp{STLC.Core.size e == STLC.Core.size e'} | let open_exp e v = open_exp' e v 0 | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 60,
"start_col": 0,
"start_line": 60
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> v: STLC.Core.var
-> e': STLC.Core.stlc_exp{STLC.Core.size e == STLC.Core.size e'} | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.var",
"STLC.Core.open_exp'",
"Prims.eq2",
"Prims.nat",
"STLC.Core.size"
] | [] | false | false | false | false | false | let open_exp e v =
| open_exp' e v 0 | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT8 | val parse____UINT8 : parser kind____UINT8 ___UINT8 | val parse____UINT8 : parser kind____UINT8 ___UINT8 | let parse____UINT8 = LowParse.Spec.Int.parse_u8 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 280,
"start_col": 0,
"start_line": 280
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
//////////////////////////////////////////////////////////////////////////////// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT8 EverParse3d.Prelude.___UINT8 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Int.parse_u8"
] | [] | false | false | false | false | false | let parse____UINT8 =
| LowParse.Spec.Int.parse_u8 | false |
STLC.Core.fst | STLC.Core.close_exp | val close_exp : e: STLC.Core.stlc_exp -> v: STLC.Core.var
-> e': STLC.Core.stlc_exp{STLC.Core.size e == STLC.Core.size e'} | let close_exp e v = close_exp' e v 0 | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 61,
"start_col": 0,
"start_line": 61
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> v: STLC.Core.var
-> e': STLC.Core.stlc_exp{STLC.Core.size e == STLC.Core.size e'} | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.var",
"STLC.Core.close_exp'",
"Prims.eq2",
"Prims.nat",
"STLC.Core.size"
] | [] | false | false | false | false | false | let close_exp e v =
| close_exp' e v 0 | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT8BE | val parse____UINT8BE : parser kind____UINT8BE ___UINT8BE | val parse____UINT8BE : parser kind____UINT8BE ___UINT8BE | let parse____UINT8BE = LowParse.Spec.Int.parse_u8 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 49,
"end_line": 284,
"start_col": 0,
"start_line": 284
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT8BE EverParse3d.Prelude.___UINT8BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Int.parse_u8"
] | [] | false | false | false | false | false | let parse____UINT8BE =
| LowParse.Spec.Int.parse_u8 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_all_bytes' | val parse_all_bytes':LP.bare_parser all_bytes | val parse_all_bytes':LP.bare_parser all_bytes | let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input)) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 77,
"end_line": 115,
"start_col": 0,
"start_line": 113
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.bare_parser EverParse3d.Prelude.all_bytes | Prims.Tot | [
"total"
] | [] | [
"LowParse.Bytes.bytes",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"EverParse3d.Prelude.all_bytes",
"LowParse.Spec.Base.consumed_length",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | true | false | let parse_all_bytes':LP.bare_parser all_bytes =
| fun input -> Some (input, (Seq.length input <: LP.consumed_length input)) | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT32BE | val parse____UINT32BE : parser kind____UINT32BE ___UINT32BE | val parse____UINT32BE : parser kind____UINT32BE ___UINT32BE | let parse____UINT32BE = LowParse.Spec.Int.parse_u32 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 292,
"start_col": 0,
"start_line": 292
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT32BE EverParse3d.Prelude.___UINT32BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Int.parse_u32"
] | [] | false | false | false | false | false | let parse____UINT32BE =
| LowParse.Spec.Int.parse_u32 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT32BE | val read____UINT32BE : reader parse____UINT32BE | val read____UINT32BE : reader parse____UINT32BE | let read____UINT32BE = LowParse.Low.Int.read_u32 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 293,
"start_col": 0,
"start_line": 293
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT32BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Int.read_u32"
] | [] | false | false | false | false | false | let read____UINT32BE =
| LowParse.Low.Int.read_u32 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT8 | val read____UINT8 : reader parse____UINT8 | val read____UINT8 : reader parse____UINT8 | let read____UINT8 = LowParse.Low.Int.read_u8 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 281,
"start_col": 0,
"start_line": 281
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT8 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Int.read_u8"
] | [] | false | false | false | false | false | let read____UINT8 =
| LowParse.Low.Int.read_u8 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT16BE | val read____UINT16BE : reader parse____UINT16BE | val read____UINT16BE : reader parse____UINT16BE | let read____UINT16BE = LowParse.Low.Int.read_u16 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 289,
"start_col": 0,
"start_line": 289
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT16BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Int.read_u16"
] | [] | false | false | false | false | false | let read____UINT16BE =
| LowParse.Low.Int.read_u16 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_weaken_right | val parse_weaken_right (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
(#nz':_) (#wk': _) (k':parser_kind nz' wk')
: Tot (parser (glb k k') t) | val parse_weaken_right (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
(#nz':_) (#wk': _) (k':parser_kind nz' wk')
: Tot (parser (glb k k') t) | let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 26,
"end_line": 88,
"start_col": 0,
"start_line": 87
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: EverParse3d.Prelude.parser k t -> k': EverParse3d.Kinds.parser_kind nz' wk'
-> EverParse3d.Prelude.parser (EverParse3d.Kinds.glb k k') t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"LowParse.Spec.Base.weaken",
"EverParse3d.Kinds.glb",
"Prims.op_AmpAmp",
"EverParse3d.Kinds.weak_kind_glb"
] | [] | false | false | false | false | false | let parse_weaken_right #nz #wk #k p k' =
| LP.weaken (glb k k') p | false |
STLC.Core.fst | STLC.Core.max | val max : n1: Prims.nat -> n2: Prims.nat -> Prims.nat | let max (n1 n2:nat) = if n1 < n2 then n2 else n1 | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 145,
"start_col": 0,
"start_line": 145
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n1: Prims.nat -> n2: Prims.nat -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.op_LessThan",
"Prims.bool"
] | [] | false | false | false | true | false | let max (n1 n2: nat) =
| if n1 < n2 then n2 else n1 | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT64BE | val parse____UINT64BE : parser kind____UINT64BE ___UINT64BE | val parse____UINT64BE : parser kind____UINT64BE ___UINT64BE | let parse____UINT64BE = LowParse.Spec.Int.parse_u64 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 296,
"start_col": 0,
"start_line": 296
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT64BE EverParse3d.Prelude.___UINT64BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Int.parse_u64"
] | [] | false | false | false | false | false | let parse____UINT64BE =
| LowParse.Spec.Int.parse_u64 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT64BE | val read____UINT64BE : reader parse____UINT64BE | val read____UINT64BE : reader parse____UINT64BE | let read____UINT64BE = LowParse.Low.Int.read_u64 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 297,
"start_col": 0,
"start_line": 297
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT64BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Int.read_u64"
] | [] | false | false | false | false | false | let read____UINT64BE =
| LowParse.Low.Int.read_u64 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT32 | val parse____UINT32 : parser kind____UINT32 ___UINT32 | val parse____UINT32 : parser kind____UINT32 ___UINT32 | let parse____UINT32 = LowParse.Spec.BoundedInt.parse_u32_le | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 59,
"end_line": 305,
"start_col": 0,
"start_line": 305
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64
/// UInt16
let parse____UINT16 = LowParse.Spec.BoundedInt.parse_u16_le
let read____UINT16 = LowParse.Low.BoundedInt.read_u16_le | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT32 EverParse3d.Prelude.___UINT32 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.parse_u32_le"
] | [] | false | false | false | false | false | let parse____UINT32 =
| LowParse.Spec.BoundedInt.parse_u32_le | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT16 | val read____UINT16 : reader parse____UINT16 | val read____UINT16 : reader parse____UINT16 | let read____UINT16 = LowParse.Low.BoundedInt.read_u16_le | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 56,
"end_line": 302,
"start_col": 0,
"start_line": 302
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64
/// UInt16 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT16 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.BoundedInt.read_u16_le"
] | [] | false | false | false | false | false | let read____UINT16 =
| LowParse.Low.BoundedInt.read_u16_le | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT8BE | val read____UINT8BE : reader parse____UINT8BE | val read____UINT8BE : reader parse____UINT8BE | let read____UINT8BE = LowParse.Low.Int.read_u8 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 285,
"start_col": 0,
"start_line": 285
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT8BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Int.read_u8"
] | [] | false | false | false | false | false | let read____UINT8BE =
| LowParse.Low.Int.read_u8 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_weaken | val parse_weaken
(#nz #wk: _)
(#k: parser_kind nz wk)
(#t: _)
(p: parser k t)
(#nz' #wk': _)
(k': parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t) | val parse_weaken
(#nz #wk: _)
(#k: parser_kind nz wk)
(#t: _)
(p: parser k t)
(#nz' #wk': _)
(k': parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t) | let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 78,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: EverParse3d.Prelude.parser k t ->
k': EverParse3d.Kinds.parser_kind nz' wk' {EverParse3d.Prelude.is_weaker_than k' k}
-> EverParse3d.Prelude.parser k' t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"EverParse3d.Prelude.is_weaker_than",
"LowParse.Spec.Base.weaken"
] | [] | false | false | false | false | false | let parse_weaken
#nz
#wk
(#k: parser_kind nz wk)
#t
(p: parser k t)
#nz'
#wk'
(k': parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t) =
| LP.weaken k' p | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_impos | val parse_impos (_:unit)
: parser impos_kind False | val parse_impos (_:unit)
: parser impos_kind False | let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 96,
"start_col": 0,
"start_line": 92
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> EverParse3d.Prelude.parser EverParse3d.Kinds.impos_kind Prims.l_False | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"Prims.l_False",
"EverParse3d.Kinds.impos_kind",
"LowParse.Spec.Base.bare_parser",
"LowParse.Bytes.bytes",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"FStar.Pervasives.Native.option",
"EverParse3d.Prelude.parser",
"EverParse3d.Kinds.WeakKindStrongPrefix"
] | [] | false | false | false | false | false | let parse_impos () : parser impos_kind False =
| let p:LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_weaken_left | val parse_weaken_left (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
(#nz':_) (#wk': _) (k':parser_kind nz' wk')
: Tot (parser (glb k' k) t) | val parse_weaken_left (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
(#nz':_) (#wk': _) (k':parser_kind nz' wk')
: Tot (parser (glb k' k) t) | let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 26,
"end_line": 83,
"start_col": 0,
"start_line": 82
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: EverParse3d.Prelude.parser k t -> k': EverParse3d.Kinds.parser_kind nz' wk'
-> EverParse3d.Prelude.parser (EverParse3d.Kinds.glb k' k) t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"LowParse.Spec.Base.weaken",
"EverParse3d.Kinds.glb",
"Prims.op_AmpAmp",
"EverParse3d.Kinds.weak_kind_glb"
] | [] | false | false | false | false | false | let parse_weaken_left #nz #wk #k p k' =
| LP.weaken (glb k' k) p | false |
STLC.Core.fst | STLC.Core.tun | val tun : FStar.Stubs.Reflection.Types.term | let tun = R.pack_ln R.Tv_Unknown | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 209,
"start_col": 0,
"start_line": 209
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Unknown"
] | [] | false | false | false | true | false | let tun =
| R.pack_ln R.Tv_Unknown | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT16 | val parse____UINT16 : parser kind____UINT16 ___UINT16 | val parse____UINT16 : parser kind____UINT16 ___UINT16 | let parse____UINT16 = LowParse.Spec.BoundedInt.parse_u16_le | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 59,
"end_line": 301,
"start_col": 0,
"start_line": 301
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT16 EverParse3d.Prelude.___UINT16 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.parse_u16_le"
] | [] | false | false | false | false | false | let parse____UINT16 =
| LowParse.Spec.BoundedInt.parse_u16_le | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_t_exact | val parse_t_exact (n:U32.t) (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
: Tot (parser kind_t_exact (t_exact n t)) | val parse_t_exact (n:U32.t) (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
: Tot (parser kind_t_exact (t_exact n t)) | let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 24,
"end_line": 149,
"start_col": 0,
"start_line": 139
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t
-> EverParse3d.Prelude.parser EverParse3d.Kinds.kind_t_exact (EverParse3d.Prelude.t_exact n t) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"EverParse3d.Prelude.parse_weaken",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata",
"EverParse3d.Kinds.kind_t_exact",
"EverParse3d.Prelude.t_exact"
] | [] | false | false | false | false | false | let parse_t_exact n #nz #wk #k #t p =
| let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken #false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata p (U32.v n))
#false
kind_t_exact | false |
STLC.Core.fst | STLC.Core.stlc_env | val stlc_env : Type0 | let stlc_env = list (var & stlc_ty) | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 139,
"start_col": 0,
"start_line": 139
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"STLC.Core.var",
"STLC.Core.stlc_ty"
] | [] | false | false | false | true | true | let stlc_env =
| list (var & stlc_ty) | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT32 | val read____UINT32 : reader parse____UINT32 | val read____UINT32 : reader parse____UINT32 | let read____UINT32 = LowParse.Low.BoundedInt.read_u32_le | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 56,
"end_line": 306,
"start_col": 0,
"start_line": 306
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64
/// UInt16
let parse____UINT16 = LowParse.Spec.BoundedInt.parse_u16_le
let read____UINT16 = LowParse.Low.BoundedInt.read_u16_le
/// UInt32 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT32 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.BoundedInt.read_u32_le"
] | [] | false | false | false | false | false | let read____UINT32 =
| LowParse.Low.BoundedInt.read_u32_le | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT16BE | val parse____UINT16BE : parser kind____UINT16BE ___UINT16BE | val parse____UINT16BE : parser kind____UINT16BE ___UINT16BE | let parse____UINT16BE = LowParse.Spec.Int.parse_u16 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 288,
"start_col": 0,
"start_line": 288
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT16BE EverParse3d.Prelude.___UINT16BE | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Int.parse_u16"
] | [] | false | false | false | false | false | let parse____UINT16BE =
| LowParse.Spec.Int.parse_u16 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_nlist | val parse_nlist (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#t:_) (p:parser k t)
: Tot (parser kind_nlist (nlist n t)) | val parse_nlist (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#t:_) (p:parser k t)
: Tot (parser kind_nlist (nlist n t)) | let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 110,
"start_col": 0,
"start_line": 104
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t
-> EverParse3d.Prelude.parser EverParse3d.Kinds.kind_nlist (EverParse3d.Prelude.nlist n t) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"EverParse3d.Prelude.parse_weaken",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.List.parse_list_kind",
"Prims.list",
"LowParse.Spec.FLData.parse_fldata",
"LowParse.Spec.List.parse_list",
"EverParse3d.Kinds.kind_nlist",
"EverParse3d.Prelude.nlist"
] | [] | false | false | false | false | false | let parse_nlist n #wk #k #t p =
| let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken #false
#WeakKindStrongPrefix
#(parse_fldata_kind (U32.v n) parse_list_kind)
#(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false
kind_nlist | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_ite | val parse_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk)
(e:bool)
(#a:squash e -> Type)
(#b:squash (not e) -> Type)
(p1:squash e -> parser k (a()))
(p2:squash (not e) -> parser k (b()))
: Tot (parser k (t_ite e a b)) | val parse_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk)
(e:bool)
(#a:squash e -> Type)
(#b:squash (not e) -> Type)
(p1:squash e -> parser k (a()))
(p2:squash (not e) -> parser k (b()))
: Tot (parser k (t_ite e a b)) | let parse_ite e p1 p2
= if e then p1 () else p2 () | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 30,
"end_line": 99,
"start_col": 0,
"start_line": 98
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
e: Prims.bool ->
p1: (_: Prims.squash e -> EverParse3d.Prelude.parser k (a ())) ->
p2: (_: Prims.squash (Prims.op_Negation e) -> EverParse3d.Prelude.parser k (b ()))
-> EverParse3d.Prelude.parser k (EverParse3d.Prelude.t_ite e a b) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"Prims.squash",
"Prims.b2t",
"Prims.op_Negation",
"EverParse3d.Prelude.parser",
"EverParse3d.Prelude.t_ite"
] | [] | false | false | false | false | false | let parse_ite e p1 p2 =
| if e then p1 () else p2 () | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse____UINT64 | val parse____UINT64 : parser kind____UINT64 ___UINT64 | val parse____UINT64 : parser kind____UINT64 ___UINT64 | let parse____UINT64 = LowParse.Spec.Int.parse_u64_le | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 310,
"start_col": 0,
"start_line": 310
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64
/// UInt16
let parse____UINT16 = LowParse.Spec.BoundedInt.parse_u16_le
let read____UINT16 = LowParse.Low.BoundedInt.read_u16_le
/// UInt32
let parse____UINT32 = LowParse.Spec.BoundedInt.parse_u32_le
let read____UINT32 = LowParse.Low.BoundedInt.read_u32_le | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind____UINT64 EverParse3d.Prelude.___UINT64 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Int.parse_u64_le"
] | [] | false | false | false | false | false | let parse____UINT64 =
| LowParse.Spec.Int.parse_u64_le | false |
STLC.Core.fst | STLC.Core.contains | val contains : sg: Prims.list (STLC.Core.var * STLC.Core.stlc_ty) -> x: STLC.Core.var -> Prims.bool | let contains (sg:list (var & stlc_ty)) (x:var) =
Some? (lookup sg x) | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 232,
"start_col": 0,
"start_line": 231
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t
let ty_to_string = ty_to_string' false
let mem_intension_pat (#a:eqtype) (x:a) (f:(a -> Tot bool))
: Lemma
(ensures FStar.Set.(mem x (intension f) = f x))
[SMTPat FStar.Set.(mem x (intension f))]
= Set.mem_intension x f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sg: Prims.list (STLC.Core.var * STLC.Core.stlc_ty) -> x: STLC.Core.var -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"STLC.Core.var",
"STLC.Core.stlc_ty",
"FStar.Pervasives.Native.uu___is_Some",
"STLC.Core.lookup",
"Prims.bool"
] | [] | false | false | false | true | false | let contains (sg: list (var & stlc_ty)) (x: var) =
| Some? (lookup sg x) | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.read____UINT64 | val read____UINT64 : reader parse____UINT64 | val read____UINT64 : reader parse____UINT64 | let read____UINT64 = LowParse.Low.Int.read_u64_le | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 49,
"end_line": 311,
"start_col": 0,
"start_line": 311
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64
/// UInt16
let parse____UINT16 = LowParse.Spec.BoundedInt.parse_u16_le
let read____UINT16 = LowParse.Low.BoundedInt.read_u16_le
/// UInt32
let parse____UINT32 = LowParse.Spec.BoundedInt.parse_u32_le
let read____UINT32 = LowParse.Low.BoundedInt.read_u32_le
/// UInt64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader EverParse3d.Prelude.parse____UINT64 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Int.read_u64_le"
] | [] | false | false | false | false | false | let read____UINT64 =
| LowParse.Low.Int.read_u64_le | false |
STLC.Core.fst | STLC.Core.ty_to_string | val ty_to_string : t: STLC.Core.stlc_ty -> Prims.Tot Prims.string | let ty_to_string = ty_to_string' false | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 223,
"start_col": 0,
"start_line": 223
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: STLC.Core.stlc_ty -> Prims.Tot Prims.string | Prims.Tot | [
"total",
""
] | [] | [
"STLC.Core.ty_to_string'"
] | [] | false | false | false | true | false | let ty_to_string =
| ty_to_string' false | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.read_unit | val read_unit
: reader (parse_ret ()) | val read_unit
: reader (parse_ret ()) | let read_unit
: LPL.leaf_reader (parse_ret ())
= LPLC.read_ret () | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 20,
"end_line": 316,
"start_col": 0,
"start_line": 314
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator)
let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ()))
inline_for_extraction noextract
let is_zero (x: FStar.UInt8.t) : Tot bool = x = 0uy
let all_zeros = list (LowParse.Spec.Combinators.parse_filter_refine is_zero)
let parse_all_zeros = LowParse.Spec.List.parse_list (LowParse.Spec.Combinators.parse_filter LowParse.Spec.Int.parse_u8 is_zero)
////////////////////////////////////////////////////////////////////////////////
// Base types
////////////////////////////////////////////////////////////////////////////////
/// UINT8
let parse____UINT8 = LowParse.Spec.Int.parse_u8
let read____UINT8 = LowParse.Low.Int.read_u8
/// UINT8BE
let parse____UINT8BE = LowParse.Spec.Int.parse_u8
let read____UINT8BE = LowParse.Low.Int.read_u8
/// UInt16BE
let parse____UINT16BE = LowParse.Spec.Int.parse_u16
let read____UINT16BE = LowParse.Low.Int.read_u16
/// UInt32BE
let parse____UINT32BE = LowParse.Spec.Int.parse_u32
let read____UINT32BE = LowParse.Low.Int.read_u32
/// UInt64BE
let parse____UINT64BE = LowParse.Spec.Int.parse_u64
let read____UINT64BE = LowParse.Low.Int.read_u64
/// UInt16
let parse____UINT16 = LowParse.Spec.BoundedInt.parse_u16_le
let read____UINT16 = LowParse.Low.BoundedInt.read_u16_le
/// UInt32
let parse____UINT32 = LowParse.Spec.BoundedInt.parse_u32_le
let read____UINT32 = LowParse.Low.BoundedInt.read_u32_le
/// UInt64
let parse____UINT64 = LowParse.Spec.Int.parse_u64_le
let read____UINT64 = LowParse.Low.Int.read_u64_le | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader (EverParse3d.Prelude.parse_ret ()) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.Combinators.read_ret",
"Prims.unit",
"LowParse.Low.Base.leaf_reader",
"EverParse3d.Kinds.ret_kind",
"EverParse3d.Prelude.parse_ret"
] | [] | false | false | false | false | false | let read_unit:LPL.leaf_reader (parse_ret ()) =
| LPLC.read_ret () | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_all_bytes | val parse_all_bytes: parser kind_all_bytes all_bytes | val parse_all_bytes: parser kind_all_bytes all_bytes | let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes' | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 118,
"start_col": 0,
"start_line": 116
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.parser EverParse3d.Kinds.kind_all_bytes EverParse3d.Prelude.all_bytes | Prims.Tot | [
"total"
] | [] | [
"EverParse3d.Prelude.parse_all_bytes'",
"Prims.unit",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"EverParse3d.Prelude.all_bytes",
"EverParse3d.Kinds.kind_all_bytes"
] | [] | false | false | false | false | false | let parse_all_bytes =
| LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes' | false |
STLC.Core.fst | STLC.Core.extend_env_l | val extend_env_l : g: FStar.Stubs.Reflection.Types.env -> sg: STLC.Core.stlc_env -> FStar.Stubs.Reflection.Types.env | let extend_env_l (g:R.env) (sg:stlc_env) =
L.fold_right (fun (x, t) g -> RT.extend_env g x (elab_ty t)) sg g | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 323,
"start_col": 0,
"start_line": 322
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t
let ty_to_string = ty_to_string' false
let mem_intension_pat (#a:eqtype) (x:a) (f:(a -> Tot bool))
: Lemma
(ensures FStar.Set.(mem x (intension f) = f x))
[SMTPat FStar.Set.(mem x (intension f))]
= Set.mem_intension x f
let contains (sg:list (var & stlc_ty)) (x:var) =
Some? (lookup sg x)
let vars_of_env (sg:list (var & stlc_ty))
: GTot (Set.set var)
= Set.intension (contains sg)
let rec check (g:R.env)
(sg:list (var & stlc_ty))
(e:stlc_exp { ln e /\ (freevars e `Set.subset` vars_of_env sg)})
: T.Tac (t:stlc_ty &
stlc_typing sg e t)
= match e with
| EUnit ->
let d = T_Unit sg in
(| TUnit, d |)
| EVar n ->
begin
match lookup sg n with
| None -> T.fail "Ill-typed"
| Some t ->
let d = T_Var sg n in
(| t, d |)
end
| ELam t e ->
let x = fresh sg in
fresh_is_fresh sg;
freevars_open e x 0;
let (| tbody, dbody |) = check g ((x,t)::sg) (open_exp e x) in
(| TArrow t tbody,
T_Lam sg t e tbody x dbody |)
| EApp e1 e2 ->
let (| t1, d1 |) = check g sg e1 in
let (| t2, d2 |) = check g sg e2 in
match t1 with
| TArrow t2' t ->
if t2' = t2
then (| t, T_App _ _ _ _ _ d1 d2 |)
else T.fail
(Printf.sprintf "Expected argument of type %s got %s"
(ty_to_string t2')
(ty_to_string t2))
| _ ->
T.fail (Printf.sprintf "Expected an arrow, got %s"
(ty_to_string t1))
let rec elab_ty (t:stlc_ty)
: R.term
= let open R in
match t with
| TUnit ->
R.pack_ln (R.Tv_FVar (R.pack_fv unit_lid))
| TArrow t1 t2 ->
let t1 = elab_ty t1 in
let t2 = elab_ty t2 in
R.pack_ln
(R.Tv_Arrow
(RT.mk_simple_binder RT.pp_name_default t1)
(R.pack_comp (C_Total t2)))
let rec elab_exp (e:stlc_exp)
: Tot R.term (decreases (size e))
= let open R in
match e with
| EUnit ->
pack_ln (Tv_Const C_Unit)
| EBVar n ->
let bv = R.pack_bv (RT.make_bv n) in
R.pack_ln (Tv_BVar bv)
| EVar n ->
let bv = R.pack_namedv (RT.make_namedv n) in
R.pack_ln (Tv_Var bv)
| ELam t e ->
let t = elab_ty t in
let e = elab_exp e in
R.pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default t) e)
| EApp e1 e2 ->
let e1 = elab_exp e1 in
let e2 = elab_exp e2 in
R.pack_ln (Tv_App e1 (e2, Q_Explicit)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: FStar.Stubs.Reflection.Types.env -> sg: STLC.Core.stlc_env -> FStar.Stubs.Reflection.Types.env | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.env",
"STLC.Core.stlc_env",
"FStar.List.Tot.Base.fold_right",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V2.Data.var",
"STLC.Core.stlc_ty",
"FStar.Reflection.Typing.extend_env",
"STLC.Core.elab_ty"
] | [] | false | false | false | true | false | let extend_env_l (g: R.env) (sg: stlc_env) =
| L.fold_right (fun (x, t) g -> RT.extend_env g x (elab_ty t)) sg g | false |
|
EverParse3d.Prelude.fst | EverParse3d.Prelude.read_impos | val read_impos : reader (parse_impos()) | val read_impos : reader (parse_impos()) | let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim () | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 167,
"start_col": 0,
"start_line": 162
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverParse3d.Prelude.reader (EverParse3d.Prelude.parse_impos ()) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.false_elim",
"Prims.l_False",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"EverParse3d.Kinds.impos_kind",
"EverParse3d.Prelude.parse_impos",
"Prims._assert",
"LowParse.Low.Base.Spec.valid",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"EverParse3d.Prelude.reader"
] | [] | false | false | false | false | false | let read_impos:reader (parse_impos ()) =
| fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get () in
assert (LPLC.valid (parse_impos ()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos ()) h sl pos;
false_elim () | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.mem | val mem : key: a -> m: FStar.FiniteMap.Base.map a b -> Prims.bool | let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 73,
"start_col": 0,
"start_line": 72
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | key: a -> m: FStar.FiniteMap.Base.map a b -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"Prims.bool"
] | [] | false | false | false | false | false | let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
| FSet.mem key (domain m) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.remove | val remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : map a b | val remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : map a b | let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 177,
"start_col": 0,
"start_line": 175
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | key: a -> m: FStar.FiniteMap.Base.map a b -> FStar.FiniteMap.Base.map a b | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"FStar.FiniteMap.Base.subtract",
"FStar.FiniteSet.Base.singleton"
] | [] | false | false | false | false | false | let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : map a b =
| subtract m (FSet.singleton key) | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.notin | val notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : bool | val notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : bool | let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 181,
"start_col": 0,
"start_line": 179
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | key: a -> m: FStar.FiniteMap.Base.map a b -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.op_Negation",
"FStar.FiniteMap.Base.mem",
"Prims.bool"
] | [] | false | false | false | false | false | let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : bool =
| not (mem key m) | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_t_at_most | val parse_t_at_most (n:U32.t) (#nz: _) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
: Tot (parser kind_t_at_most (t_at_most n t)) | val parse_t_at_most (n:U32.t) (#nz: _) (#wk: _) (#k:parser_kind nz wk) (#t:_) (p:parser k t)
: Tot (parser kind_t_at_most (t_at_most n t)) | let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 26,
"end_line": 134,
"start_col": 0,
"start_line": 124
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t
-> EverParse3d.Prelude.parser EverParse3d.Kinds.kind_t_at_most (EverParse3d.Prelude.t_at_most n t) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Prelude.parser",
"EverParse3d.Prelude.parse_weaken",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.Combinators.and_then_kind",
"EverParse3d.Kinds.kind_all_bytes",
"FStar.Pervasives.Native.tuple2",
"EverParse3d.Prelude.all_bytes",
"LowParse.Spec.FLData.parse_fldata",
"LowParse.Spec.Combinators.nondep_then",
"EverParse3d.Prelude.parse_all_bytes",
"EverParse3d.Kinds.kind_t_at_most",
"EverParse3d.Prelude.t_at_most"
] | [] | false | false | false | false | false | let parse_t_at_most n #nz #wk #k #t p =
| let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken #false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata (LPC.nondep_then p parse_all_bytes) (U32.v n))
#false
kind_t_at_most | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.cardinality_zero_iff_empty_fact | val cardinality_zero_iff_empty_fact : Prims.logical | let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 200,
"start_col": 0,
"start_line": 198
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty()); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_iff",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.FiniteMap.Base.cardinality",
"Prims.eq2",
"FStar.FiniteMap.Base.emptymap"
] | [] | false | false | false | true | true | let cardinality_zero_iff_empty_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b). {:pattern cardinality m}
cardinality m = 0 <==> m == emptymap | false |
|
STLC.Core.fst | STLC.Core.mem_intension_pat | val mem_intension_pat (#a: eqtype) (x: a) (f: (a -> Tot bool))
: Lemma (ensures FStar.Set.(mem x (intension f) = f x)) [SMTPat FStar.Set.(mem x (intension f))] | val mem_intension_pat (#a: eqtype) (x: a) (f: (a -> Tot bool))
: Lemma (ensures FStar.Set.(mem x (intension f) = f x)) [SMTPat FStar.Set.(mem x (intension f))] | let mem_intension_pat (#a:eqtype) (x:a) (f:(a -> Tot bool))
: Lemma
(ensures FStar.Set.(mem x (intension f) = f x))
[SMTPat FStar.Set.(mem x (intension f))]
= Set.mem_intension x f | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 229,
"start_col": 0,
"start_line": 225
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t
let ty_to_string = ty_to_string' false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> f: (_: a -> Prims.bool)
-> FStar.Pervasives.Lemma (ensures FStar.Set.mem x (FStar.Set.intension f) = f x)
[SMTPat (FStar.Set.mem x (FStar.Set.intension f))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.bool",
"FStar.Set.mem_intension",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Set.mem",
"FStar.Set.intension",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let mem_intension_pat (#a: eqtype) (x: a) (f: (a -> Tot bool))
: Lemma (ensures FStar.Set.(mem x (intension f) = f x)) [SMTPat FStar.Set.(mem x (intension f))] =
| Set.mem_intension x f | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.empty_or_values_occupied_fact | val empty_or_values_occupied_fact : Prims.logical | let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 220,
"start_col": 0,
"start_line": 218
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_or",
"Prims.eq2",
"FStar.FiniteMap.Base.emptymap",
"Prims.l_Exists",
"FStar.FiniteMap.Base.values"
] | [] | false | false | false | true | true | let empty_or_values_occupied_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b). {:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v} (values m) v) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.empty_or_items_occupied_fact | val empty_or_items_occupied_fact : Prims.logical | let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 230,
"start_col": 0,
"start_line": 228
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_or",
"Prims.eq2",
"FStar.FiniteMap.Base.emptymap",
"Prims.l_Exists",
"FStar.Pervasives.Native.tuple2",
"FStar.FiniteMap.Base.items"
] | [] | false | false | false | true | true | let empty_or_items_occupied_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b). {:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item} (items m) item) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.values_contains_fact | val values_contains_fact : Prims.logical | let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 265,
"start_col": 0,
"start_line": 261
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_iff",
"FStar.FiniteMap.Base.values",
"Prims.l_Exists",
"Prims.l_and",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.FiniteMap.Base.elements",
"FStar.Pervasives.Native.Some"
] | [] | false | false | false | true | true | let values_contains_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b). {:pattern (values m) v}
(values m) v <==>
(exists (u: a). {:pattern FSet.mem u (domain m)\/((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.empty_or_domain_occupied_fact | val empty_or_domain_occupied_fact : Prims.logical | let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 210,
"start_col": 0,
"start_line": 208
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_or",
"Prims.eq2",
"FStar.FiniteMap.Base.emptymap",
"Prims.l_Exists",
"Prims.b2t",
"FStar.FiniteMap.Base.mem",
"FStar.FiniteMap.Base.domain"
] | [] | false | false | false | true | true | let empty_or_domain_occupied_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b). {:pattern domain m}
m == emptymap \/ (exists k. {:pattern mem k m} mem k m) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.empty_domain_empty_fact | val empty_domain_empty_fact : Prims.logical | let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b))) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 288,
"start_col": 0,
"start_line": 286
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"Prims.b2t",
"Prims.op_Negation",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.emptymap"
] | [] | false | false | false | true | true | let empty_domain_empty_fact =
| forall (a: eqtype) (b: Type u#b) (u: a). {:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b))) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.glue_domain_fact | val glue_domain_fact : Prims.logical | let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 298,
"start_col": 0,
"start_line": 296
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteMap.Base.setfun_t",
"Prims.eq2",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.glue"
] | [] | false | false | false | true | true | let glue_domain_fact =
| forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).
{:pattern domain (glue keys f)}
domain (glue keys f) == keys | false |
|
STLC.Core.fst | STLC.Core.bar_s | val bar_s : STLC.Core.stlc_exp | let bar_s = (ELam TUnit (ELam TUnit (EBVar 1))) | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 556,
"start_col": 0,
"start_line": 556
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t
let ty_to_string = ty_to_string' false
let mem_intension_pat (#a:eqtype) (x:a) (f:(a -> Tot bool))
: Lemma
(ensures FStar.Set.(mem x (intension f) = f x))
[SMTPat FStar.Set.(mem x (intension f))]
= Set.mem_intension x f
let contains (sg:list (var & stlc_ty)) (x:var) =
Some? (lookup sg x)
let vars_of_env (sg:list (var & stlc_ty))
: GTot (Set.set var)
= Set.intension (contains sg)
let rec check (g:R.env)
(sg:list (var & stlc_ty))
(e:stlc_exp { ln e /\ (freevars e `Set.subset` vars_of_env sg)})
: T.Tac (t:stlc_ty &
stlc_typing sg e t)
= match e with
| EUnit ->
let d = T_Unit sg in
(| TUnit, d |)
| EVar n ->
begin
match lookup sg n with
| None -> T.fail "Ill-typed"
| Some t ->
let d = T_Var sg n in
(| t, d |)
end
| ELam t e ->
let x = fresh sg in
fresh_is_fresh sg;
freevars_open e x 0;
let (| tbody, dbody |) = check g ((x,t)::sg) (open_exp e x) in
(| TArrow t tbody,
T_Lam sg t e tbody x dbody |)
| EApp e1 e2 ->
let (| t1, d1 |) = check g sg e1 in
let (| t2, d2 |) = check g sg e2 in
match t1 with
| TArrow t2' t ->
if t2' = t2
then (| t, T_App _ _ _ _ _ d1 d2 |)
else T.fail
(Printf.sprintf "Expected argument of type %s got %s"
(ty_to_string t2')
(ty_to_string t2))
| _ ->
T.fail (Printf.sprintf "Expected an arrow, got %s"
(ty_to_string t1))
let rec elab_ty (t:stlc_ty)
: R.term
= let open R in
match t with
| TUnit ->
R.pack_ln (R.Tv_FVar (R.pack_fv unit_lid))
| TArrow t1 t2 ->
let t1 = elab_ty t1 in
let t2 = elab_ty t2 in
R.pack_ln
(R.Tv_Arrow
(RT.mk_simple_binder RT.pp_name_default t1)
(R.pack_comp (C_Total t2)))
let rec elab_exp (e:stlc_exp)
: Tot R.term (decreases (size e))
= let open R in
match e with
| EUnit ->
pack_ln (Tv_Const C_Unit)
| EBVar n ->
let bv = R.pack_bv (RT.make_bv n) in
R.pack_ln (Tv_BVar bv)
| EVar n ->
let bv = R.pack_namedv (RT.make_namedv n) in
R.pack_ln (Tv_Var bv)
| ELam t e ->
let t = elab_ty t in
let e = elab_exp e in
R.pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default t) e)
| EApp e1 e2 ->
let e1 = elab_exp e1 in
let e2 = elab_exp e2 in
R.pack_ln (Tv_App e1 (e2, Q_Explicit))
let extend_env_l (g:R.env) (sg:stlc_env) =
L.fold_right (fun (x, t) g -> RT.extend_env g x (elab_ty t)) sg g
let rec extend_env_l_lookup_bvar (g:R.env) (sg:stlc_env) (x:var)
: Lemma
(requires (forall x. RT.lookup_bvar g x == None))
(ensures (
match lookup sg x with
| Some t -> RT.lookup_bvar (extend_env_l g sg) x == Some (elab_ty t)
| None -> RT.lookup_bvar (extend_env_l g sg) x == None))
(decreases sg)
[SMTPat (RT.lookup_bvar (extend_env_l g sg) x)]
= match sg with
| [] -> ()
| hd :: tl -> extend_env_l_lookup_bvar g tl x
open FStar.Calc
//key lemma about STLC types: Their elaborations are closed
let rec stlc_types_are_closed_core (ty:stlc_ty) (ss:RT.subst)
: Lemma (ensures RT.subst_term (elab_ty ty) ss == elab_ty ty)
(decreases ty)
[SMTPat (RT.subst_term (elab_ty ty) ss)]
= match ty with
| TUnit -> ()
| TArrow t1 t2 ->
stlc_types_are_closed_core t1 ss;
stlc_types_are_closed_core t2 (RT.shift_subst ss)
let stlc_types_are_closed1 (ty:stlc_ty) (v:R.term)
: Lemma (RT.open_with (elab_ty ty) v == elab_ty ty)
[SMTPat (RT.open_with (elab_ty ty) v)]
= stlc_types_are_closed_core ty [ RT.DT 0 v ];
RT.open_with_spec (elab_ty ty) v
let stlc_types_are_closed2 (ty:stlc_ty) (x:R.var)
: Lemma (RT.close_term (elab_ty ty) x == elab_ty ty)
[SMTPat (RT.close_term (elab_ty ty) x)]
= stlc_types_are_closed_core ty [ RT.ND x 0 ];
RT.close_term_spec (elab_ty ty) x
let stlc_types_are_closed3 (ty:stlc_ty) (x:R.var)
: Lemma (RT.open_term (elab_ty ty) x == elab_ty ty)
[SMTPat (RT.open_term (elab_ty ty) x)]
= stlc_types_are_closed_core ty [ RT.DT 0 (RT.var_as_term x) ];
RT.open_term_spec (elab_ty ty) x
let rec elab_ty_freevars (ty:stlc_ty)
: Lemma (RT.freevars (elab_ty ty) `Set.equal` Set.empty)
= match ty with
| TUnit -> ()
| TArrow t1 t2 ->
elab_ty_freevars t1;
elab_ty_freevars t2
let rec elab_open_commute' (e:stlc_exp) (x:var) (n:nat)
: Lemma (ensures
RT.subst_term (elab_exp e) (RT.open_with_var x n) ==
elab_exp (open_exp' e x n))
(decreases e)
= match e with
| EUnit -> ()
| EBVar _ -> ()
| EVar _ -> ()
| EApp e1 e2 ->
elab_open_commute' e1 x n;
elab_open_commute' e2 x n
| ELam t e ->
calc (==) {
elab_exp (open_exp' (ELam t e) x n);
(==) {}
elab_exp (ELam t (open_exp' e x (n + 1)));
(==) { }
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t)) (elab_exp (open_exp' e x (n + 1)))));
(==) { elab_open_commute' e x (n + 1) }
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t))
(RT.subst_term (elab_exp e) RT.(open_with_var x (n + 1)))));
(==) { stlc_types_are_closed_core t (RT.open_with_var x n) }
RT.subst_term
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t)) (elab_exp e)))
RT.(open_with_var x n);
}
let elab_open_commute (e:stlc_exp) (x:var)
: Lemma (RT.open_term (elab_exp e) x == elab_exp (open_exp e x))
[SMTPat (RT.open_term (elab_exp e) x)]
= elab_open_commute' e x 0;
RT.open_term_spec (elab_exp e) x
let rec extend_env_l_lookup_fvar (g:R.env) (sg:stlc_env) (fv:R.fv)
: Lemma
(ensures
RT.lookup_fvar (extend_env_l g sg) fv ==
RT.lookup_fvar g fv)
[SMTPat (RT.lookup_fvar (extend_env_l g sg) fv)]
= match sg with
| [] -> ()
| hd::tl -> extend_env_l_lookup_fvar g tl fv
let rec elab_ty_soundness (g:RT.fstar_top_env)
(sg:stlc_env)
(t:stlc_ty)
: GTot (RT.tot_typing (extend_env_l g sg) (elab_ty t) (RT.tm_type RT.u_zero))
(decreases t)
= match t with
| TUnit ->
RT.T_FVar _ RT.unit_fv
| TArrow t1 t2 ->
let t1_ok = elab_ty_soundness g sg t1 in
let x = fresh sg in
fresh_is_fresh sg;
elab_ty_freevars t2;
let t2_ok = elab_ty_soundness g ((x, t1)::sg) t2 in
let arr_max
: RT.tot_typing
(extend_env_l g sg)
(elab_ty t)
(RT.tm_type RT.(u_max u_zero u_zero))
= RT.T_Arrow _ x (elab_ty t1) (elab_ty t2)
_ _ RT.pp_name_default R.Q_Explicit T.E_Total _ _ t1_ok t2_ok
in
RT.simplify_umax arr_max
let rec elab_exp_freevars (e:stlc_exp)
: Lemma (freevars e `Set.equal` RT.freevars (elab_exp e))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam t e ->
elab_ty_freevars t;
elab_exp_freevars e
| EApp e1 e2 ->
elab_exp_freevars e1;
elab_exp_freevars e2
let rec soundness (#sg:stlc_env)
(#se:stlc_exp)
(#st:stlc_ty)
(dd:stlc_typing sg se st)
(g:RT.fstar_top_env)
: GTot (RT.tot_typing (extend_env_l g sg)
(elab_exp se)
(elab_ty st))
(decreases dd)
= match dd with
| T_Unit _ ->
RT.T_Const _ _ _ RT.CT_Unit
| T_Var _ x ->
RT.T_Var _ (R.pack_namedv (RT.make_namedv x))
| T_Lam _ t e t' x de ->
let de : RT.tot_typing (extend_env_l g ((x,t)::sg))
(elab_exp (open_exp e x))
(elab_ty t')
= soundness de g
in
let de : RT.tot_typing (RT.extend_env (extend_env_l g sg) x (elab_ty t))
(elab_exp (open_exp e x))
(elab_ty t')
= de
in
fresh_is_fresh sg;
elab_exp_freevars e;
let dd
= RT.T_Abs (extend_env_l g sg)
x
(elab_ty t)
(elab_exp e)
(T.E_Total, elab_ty t')
_
RT.pp_name_default
R.Q_Explicit
_
(elab_ty_soundness g sg t)
de
in
dd
| T_App _ e1 e2 t t' d1 d2 ->
let dt1
: RT.tot_typing (extend_env_l g sg)
(elab_exp e1)
(elab_ty (TArrow t t'))
= soundness d1 g
in
let dt2
: RT.tot_typing (extend_env_l g sg)
(elab_exp e2)
(elab_ty t)
= soundness d2 g
in
let dt :
RT.tot_typing (extend_env_l g sg)
(elab_exp (EApp e1 e2))
(RT.open_with (elab_ty t') (elab_exp e2))
= RT.T_App _ _ _ _ _ _ dt1 dt2
in
dt
let soundness_lemma (sg:stlc_env)
(se:stlc_exp)
(st:stlc_ty)
(g:RT.fstar_top_env)
: Lemma
(requires stlc_typing sg se st)
(ensures RT.tot_typing (extend_env_l g sg)
(elab_exp se)
(elab_ty st))
= FStar.Squash.bind_squash
#(stlc_typing sg se st)
()
(fun dd -> FStar.Squash.return_squash (soundness dd g))
let main (nm:string) (src:stlc_exp) : RT.dsl_tac_t =
fun g ->
if ln src && closed src
then
let (| src_ty, d |) = check g [] src in
soundness_lemma [] src src_ty g;
[RT.mk_checked_let g nm (elab_exp src) (elab_ty src_ty)]
else T.fail "Not locally nameless"
(***** Tests *****)
%splice_t[foo] (main "foo" (ELam TUnit (EBVar 0)))
#push-options "--no_smt"
let test_id () = assert (foo () == ()) by (T.compute ())
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | STLC.Core.stlc_exp | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.ELam",
"STLC.Core.TUnit",
"STLC.Core.EBVar"
] | [] | false | false | false | true | false | let bar_s =
| (ELam TUnit (ELam TUnit (EBVar 1))) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.item_list_doesnt_repeat_keys | val item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool | val item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool | let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 82,
"end_line": 85,
"start_col": 0,
"start_line": 82
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | items: Prims.list (a * b) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"FStar.FiniteMap.Base.key_in_item_list",
"FStar.FiniteMap.Base.item_list_doesnt_repeat_keys",
"Prims.bool"
] | [
"recursion"
] | false | false | false | false | false | let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
| match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.items_contains_fact | val items_contains_fact : Prims.logical | let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 278,
"start_col": 0,
"start_line": 274
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item))); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"FStar.Pervasives.Native.tuple2",
"Prims.l_iff",
"FStar.FiniteMap.Base.items",
"Prims.l_and",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.Pervasives.Native.fst",
"FStar.FiniteMap.Base.domain",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.FiniteMap.Base.elements",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | true | true | let items_contains_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b) (item: (a * b)). {:pattern (items m) item}
(items m) item <==> FSet.mem (fst item) (domain m) /\ (elements m) (fst item) == Some (snd item) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.insert_nonmember_cardinality_fact | val insert_nonmember_cardinality_fact : Prims.logical | let insert_nonmember_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
not (FSet.mem key (domain m)) ==> cardinality (insert key value m) = cardinality m + 1 | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 90,
"end_line": 355,
"start_col": 0,
"start_line": 353
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u']));
let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key')
/// We represent the following Dafny axiom with `insert_member_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m));
let insert_member_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
/// We represent the following Dafny axiom with `insert_nonmember_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// !Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m) + 1); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Negation",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"Prims.op_Equality",
"Prims.int",
"FStar.FiniteMap.Base.cardinality",
"FStar.FiniteMap.Base.insert",
"Prims.op_Addition"
] | [] | false | false | false | true | true | let insert_nonmember_cardinality_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).
{:pattern cardinality (insert key value m)}
not (FSet.mem key (domain m)) ==> cardinality (insert key value m) = cardinality m + 1 | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.lookup | val lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b | val lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b | let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 94,
"start_col": 0,
"start_line": 92
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | key: a -> m: FStar.FiniteMap.Base.map a b {FStar.FiniteMap.Base.mem key m} -> b | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.b2t",
"FStar.FiniteMap.Base.mem",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.FiniteMap.Base.elements"
] | [] | false | false | false | false | false | let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b =
| Some?.v ((elements m) key) | false |
STLC.Core.fst | STLC.Core.baz_s | val baz_s:stlc_exp | val baz_s:stlc_exp | let baz_s : stlc_exp = EApp bar_s EUnit | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 559,
"start_col": 0,
"start_line": 559
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t
let ty_to_string = ty_to_string' false
let mem_intension_pat (#a:eqtype) (x:a) (f:(a -> Tot bool))
: Lemma
(ensures FStar.Set.(mem x (intension f) = f x))
[SMTPat FStar.Set.(mem x (intension f))]
= Set.mem_intension x f
let contains (sg:list (var & stlc_ty)) (x:var) =
Some? (lookup sg x)
let vars_of_env (sg:list (var & stlc_ty))
: GTot (Set.set var)
= Set.intension (contains sg)
let rec check (g:R.env)
(sg:list (var & stlc_ty))
(e:stlc_exp { ln e /\ (freevars e `Set.subset` vars_of_env sg)})
: T.Tac (t:stlc_ty &
stlc_typing sg e t)
= match e with
| EUnit ->
let d = T_Unit sg in
(| TUnit, d |)
| EVar n ->
begin
match lookup sg n with
| None -> T.fail "Ill-typed"
| Some t ->
let d = T_Var sg n in
(| t, d |)
end
| ELam t e ->
let x = fresh sg in
fresh_is_fresh sg;
freevars_open e x 0;
let (| tbody, dbody |) = check g ((x,t)::sg) (open_exp e x) in
(| TArrow t tbody,
T_Lam sg t e tbody x dbody |)
| EApp e1 e2 ->
let (| t1, d1 |) = check g sg e1 in
let (| t2, d2 |) = check g sg e2 in
match t1 with
| TArrow t2' t ->
if t2' = t2
then (| t, T_App _ _ _ _ _ d1 d2 |)
else T.fail
(Printf.sprintf "Expected argument of type %s got %s"
(ty_to_string t2')
(ty_to_string t2))
| _ ->
T.fail (Printf.sprintf "Expected an arrow, got %s"
(ty_to_string t1))
let rec elab_ty (t:stlc_ty)
: R.term
= let open R in
match t with
| TUnit ->
R.pack_ln (R.Tv_FVar (R.pack_fv unit_lid))
| TArrow t1 t2 ->
let t1 = elab_ty t1 in
let t2 = elab_ty t2 in
R.pack_ln
(R.Tv_Arrow
(RT.mk_simple_binder RT.pp_name_default t1)
(R.pack_comp (C_Total t2)))
let rec elab_exp (e:stlc_exp)
: Tot R.term (decreases (size e))
= let open R in
match e with
| EUnit ->
pack_ln (Tv_Const C_Unit)
| EBVar n ->
let bv = R.pack_bv (RT.make_bv n) in
R.pack_ln (Tv_BVar bv)
| EVar n ->
let bv = R.pack_namedv (RT.make_namedv n) in
R.pack_ln (Tv_Var bv)
| ELam t e ->
let t = elab_ty t in
let e = elab_exp e in
R.pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default t) e)
| EApp e1 e2 ->
let e1 = elab_exp e1 in
let e2 = elab_exp e2 in
R.pack_ln (Tv_App e1 (e2, Q_Explicit))
let extend_env_l (g:R.env) (sg:stlc_env) =
L.fold_right (fun (x, t) g -> RT.extend_env g x (elab_ty t)) sg g
let rec extend_env_l_lookup_bvar (g:R.env) (sg:stlc_env) (x:var)
: Lemma
(requires (forall x. RT.lookup_bvar g x == None))
(ensures (
match lookup sg x with
| Some t -> RT.lookup_bvar (extend_env_l g sg) x == Some (elab_ty t)
| None -> RT.lookup_bvar (extend_env_l g sg) x == None))
(decreases sg)
[SMTPat (RT.lookup_bvar (extend_env_l g sg) x)]
= match sg with
| [] -> ()
| hd :: tl -> extend_env_l_lookup_bvar g tl x
open FStar.Calc
//key lemma about STLC types: Their elaborations are closed
let rec stlc_types_are_closed_core (ty:stlc_ty) (ss:RT.subst)
: Lemma (ensures RT.subst_term (elab_ty ty) ss == elab_ty ty)
(decreases ty)
[SMTPat (RT.subst_term (elab_ty ty) ss)]
= match ty with
| TUnit -> ()
| TArrow t1 t2 ->
stlc_types_are_closed_core t1 ss;
stlc_types_are_closed_core t2 (RT.shift_subst ss)
let stlc_types_are_closed1 (ty:stlc_ty) (v:R.term)
: Lemma (RT.open_with (elab_ty ty) v == elab_ty ty)
[SMTPat (RT.open_with (elab_ty ty) v)]
= stlc_types_are_closed_core ty [ RT.DT 0 v ];
RT.open_with_spec (elab_ty ty) v
let stlc_types_are_closed2 (ty:stlc_ty) (x:R.var)
: Lemma (RT.close_term (elab_ty ty) x == elab_ty ty)
[SMTPat (RT.close_term (elab_ty ty) x)]
= stlc_types_are_closed_core ty [ RT.ND x 0 ];
RT.close_term_spec (elab_ty ty) x
let stlc_types_are_closed3 (ty:stlc_ty) (x:R.var)
: Lemma (RT.open_term (elab_ty ty) x == elab_ty ty)
[SMTPat (RT.open_term (elab_ty ty) x)]
= stlc_types_are_closed_core ty [ RT.DT 0 (RT.var_as_term x) ];
RT.open_term_spec (elab_ty ty) x
let rec elab_ty_freevars (ty:stlc_ty)
: Lemma (RT.freevars (elab_ty ty) `Set.equal` Set.empty)
= match ty with
| TUnit -> ()
| TArrow t1 t2 ->
elab_ty_freevars t1;
elab_ty_freevars t2
let rec elab_open_commute' (e:stlc_exp) (x:var) (n:nat)
: Lemma (ensures
RT.subst_term (elab_exp e) (RT.open_with_var x n) ==
elab_exp (open_exp' e x n))
(decreases e)
= match e with
| EUnit -> ()
| EBVar _ -> ()
| EVar _ -> ()
| EApp e1 e2 ->
elab_open_commute' e1 x n;
elab_open_commute' e2 x n
| ELam t e ->
calc (==) {
elab_exp (open_exp' (ELam t e) x n);
(==) {}
elab_exp (ELam t (open_exp' e x (n + 1)));
(==) { }
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t)) (elab_exp (open_exp' e x (n + 1)))));
(==) { elab_open_commute' e x (n + 1) }
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t))
(RT.subst_term (elab_exp e) RT.(open_with_var x (n + 1)))));
(==) { stlc_types_are_closed_core t (RT.open_with_var x n) }
RT.subst_term
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t)) (elab_exp e)))
RT.(open_with_var x n);
}
let elab_open_commute (e:stlc_exp) (x:var)
: Lemma (RT.open_term (elab_exp e) x == elab_exp (open_exp e x))
[SMTPat (RT.open_term (elab_exp e) x)]
= elab_open_commute' e x 0;
RT.open_term_spec (elab_exp e) x
let rec extend_env_l_lookup_fvar (g:R.env) (sg:stlc_env) (fv:R.fv)
: Lemma
(ensures
RT.lookup_fvar (extend_env_l g sg) fv ==
RT.lookup_fvar g fv)
[SMTPat (RT.lookup_fvar (extend_env_l g sg) fv)]
= match sg with
| [] -> ()
| hd::tl -> extend_env_l_lookup_fvar g tl fv
let rec elab_ty_soundness (g:RT.fstar_top_env)
(sg:stlc_env)
(t:stlc_ty)
: GTot (RT.tot_typing (extend_env_l g sg) (elab_ty t) (RT.tm_type RT.u_zero))
(decreases t)
= match t with
| TUnit ->
RT.T_FVar _ RT.unit_fv
| TArrow t1 t2 ->
let t1_ok = elab_ty_soundness g sg t1 in
let x = fresh sg in
fresh_is_fresh sg;
elab_ty_freevars t2;
let t2_ok = elab_ty_soundness g ((x, t1)::sg) t2 in
let arr_max
: RT.tot_typing
(extend_env_l g sg)
(elab_ty t)
(RT.tm_type RT.(u_max u_zero u_zero))
= RT.T_Arrow _ x (elab_ty t1) (elab_ty t2)
_ _ RT.pp_name_default R.Q_Explicit T.E_Total _ _ t1_ok t2_ok
in
RT.simplify_umax arr_max
let rec elab_exp_freevars (e:stlc_exp)
: Lemma (freevars e `Set.equal` RT.freevars (elab_exp e))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam t e ->
elab_ty_freevars t;
elab_exp_freevars e
| EApp e1 e2 ->
elab_exp_freevars e1;
elab_exp_freevars e2
let rec soundness (#sg:stlc_env)
(#se:stlc_exp)
(#st:stlc_ty)
(dd:stlc_typing sg se st)
(g:RT.fstar_top_env)
: GTot (RT.tot_typing (extend_env_l g sg)
(elab_exp se)
(elab_ty st))
(decreases dd)
= match dd with
| T_Unit _ ->
RT.T_Const _ _ _ RT.CT_Unit
| T_Var _ x ->
RT.T_Var _ (R.pack_namedv (RT.make_namedv x))
| T_Lam _ t e t' x de ->
let de : RT.tot_typing (extend_env_l g ((x,t)::sg))
(elab_exp (open_exp e x))
(elab_ty t')
= soundness de g
in
let de : RT.tot_typing (RT.extend_env (extend_env_l g sg) x (elab_ty t))
(elab_exp (open_exp e x))
(elab_ty t')
= de
in
fresh_is_fresh sg;
elab_exp_freevars e;
let dd
= RT.T_Abs (extend_env_l g sg)
x
(elab_ty t)
(elab_exp e)
(T.E_Total, elab_ty t')
_
RT.pp_name_default
R.Q_Explicit
_
(elab_ty_soundness g sg t)
de
in
dd
| T_App _ e1 e2 t t' d1 d2 ->
let dt1
: RT.tot_typing (extend_env_l g sg)
(elab_exp e1)
(elab_ty (TArrow t t'))
= soundness d1 g
in
let dt2
: RT.tot_typing (extend_env_l g sg)
(elab_exp e2)
(elab_ty t)
= soundness d2 g
in
let dt :
RT.tot_typing (extend_env_l g sg)
(elab_exp (EApp e1 e2))
(RT.open_with (elab_ty t') (elab_exp e2))
= RT.T_App _ _ _ _ _ _ dt1 dt2
in
dt
let soundness_lemma (sg:stlc_env)
(se:stlc_exp)
(st:stlc_ty)
(g:RT.fstar_top_env)
: Lemma
(requires stlc_typing sg se st)
(ensures RT.tot_typing (extend_env_l g sg)
(elab_exp se)
(elab_ty st))
= FStar.Squash.bind_squash
#(stlc_typing sg se st)
()
(fun dd -> FStar.Squash.return_squash (soundness dd g))
let main (nm:string) (src:stlc_exp) : RT.dsl_tac_t =
fun g ->
if ln src && closed src
then
let (| src_ty, d |) = check g [] src in
soundness_lemma [] src src_ty g;
[RT.mk_checked_let g nm (elab_exp src) (elab_ty src_ty)]
else T.fail "Not locally nameless"
(***** Tests *****)
%splice_t[foo] (main "foo" (ELam TUnit (EBVar 0)))
#push-options "--no_smt"
let test_id () = assert (foo () == ()) by (T.compute ())
#pop-options
let bar_s = (ELam TUnit (ELam TUnit (EBVar 1)))
%splice_t[bar] (main "bar" bar_s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | STLC.Core.stlc_exp | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.EApp",
"STLC.Core.bar_s",
"STLC.Core.EUnit"
] | [] | false | false | false | true | false | let baz_s:stlc_exp =
| EApp bar_s EUnit | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.key_in_item_list | val key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool | val key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool | let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 80,
"start_col": 0,
"start_line": 77
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | key: a -> items: Prims.list (a * b) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_BarBar",
"Prims.op_Equality",
"FStar.FiniteMap.Base.key_in_item_list",
"Prims.bool"
] | [
"recursion"
] | false | false | false | false | false | let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
| match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.insert_elements_fact | val insert_elements_fact : Prims.logical | let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key') | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 82,
"end_line": 337,
"start_col": 0,
"start_line": 331
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u'])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.insert",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.FiniteMap.Base.elements",
"FStar.Pervasives.Native.Some",
"Prims.op_disEquality",
"Prims.bool"
] | [] | false | false | false | true | true | let insert_elements_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m))\/((elements (insert key value m)) key')}
(key' = key ==>
FSet.mem key' (domain (insert key value m)) /\
(elements (insert key value m)) key' == Some value) /\
(key' <> key ==>
FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m) /\
(elements (insert key value m)) key' == (elements m) key') | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.merge_domain_is_union_fact | val merge_domain_is_union_fact : Prims.logical | let merge_domain_is_union_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b).{:pattern domain (merge m1 m2)}
domain (merge m1 m2) == FSet.union (domain m1) (domain m2) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 62,
"end_line": 365,
"start_col": 0,
"start_line": 363
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u']));
let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key')
/// We represent the following Dafny axiom with `insert_member_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m));
let insert_member_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
/// We represent the following Dafny axiom with `insert_nonmember_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// !Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m) + 1);
let insert_nonmember_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
not (FSet.mem key (domain m)) ==> cardinality (insert key value m) = cardinality m + 1
/// We represent the following Dafny axiom with `merge_domain_is_union_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V ::
/// { Map#Domain(Map#Merge(m, n)) }
/// Map#Domain(Map#Merge(m, n)) == Set#Union(Map#Domain(m), Map#Domain(n))); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.eq2",
"FStar.FiniteSet.Base.set",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.merge",
"FStar.FiniteSet.Base.union"
] | [] | false | false | false | true | true | let merge_domain_is_union_fact =
| forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b). {:pattern domain (merge m1 m2)}
domain (merge m1 m2) == FSet.union (domain m1) (domain m2) | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.map_cardinality_matches_domain_fact | val map_cardinality_matches_domain_fact : Prims.logical | let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 240,
"start_col": 0,
"start_line": 238
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m)); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.FiniteSet.Base.cardinality",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.cardinality"
] | [] | false | false | false | true | true | let map_cardinality_matches_domain_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b). {:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m | false |
|
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.merge_element_fact | val merge_element_fact : Prims.logical | let merge_element_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b) (key: a).{:pattern (elements (merge m1 m2)) key}
FSet.mem key (domain (merge m1 m2)) ==>
(not (FSet.mem key (domain m2)) ==> FSet.mem key (domain m1) /\ (elements (merge m1 m2)) key == (elements m1) key)
/\ (FSet.mem key (domain m2) ==> (elements (merge m1 m2)) key == (elements m2) key) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 89,
"end_line": 379,
"start_col": 0,
"start_line": 375
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u']));
let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key')
/// We represent the following Dafny axiom with `insert_member_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m));
let insert_member_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
/// We represent the following Dafny axiom with `insert_nonmember_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// !Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m) + 1);
let insert_nonmember_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
not (FSet.mem key (domain m)) ==> cardinality (insert key value m) = cardinality m + 1
/// We represent the following Dafny axiom with `merge_domain_is_union_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V ::
/// { Map#Domain(Map#Merge(m, n)) }
/// Map#Domain(Map#Merge(m, n)) == Set#Union(Map#Domain(m), Map#Domain(n)));
let merge_domain_is_union_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b).{:pattern domain (merge m1 m2)}
domain (merge m1 m2) == FSet.union (domain m1) (domain m2)
/// We represent the following Dafny axiom with `merge_element_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V, u: U ::
/// { Map#Elements(Map#Merge(m, n))[u] }
/// Map#Domain(Map#Merge(m, n))[u] ==>
/// (!Map#Domain(n)[u] ==> Map#Elements(Map#Merge(m, n))[u] == Map#Elements(m)[u]) &&
/// (Map#Domain(n)[u] ==> Map#Elements(Map#Merge(m, n))[u] == Map#Elements(n)[u])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_imp",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.merge",
"Prims.l_and",
"Prims.op_Negation",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.FiniteMap.Base.elements"
] | [] | false | false | false | true | true | let merge_element_fact =
| forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b) (key: a).
{:pattern (elements (merge m1 m2)) key}
FSet.mem key (domain (merge m1 m2)) ==>
(not (FSet.mem key (domain m2)) ==>
FSet.mem key (domain m1) /\ (elements (merge m1 m2)) key == (elements m1) key) /\
(FSet.mem key (domain m2) ==> (elements (merge m1 m2)) key == (elements m2) key) | false |
|
STLC.Core.fst | STLC.Core.open_close | val open_close (e: stlc_exp) (x: var)
: Lemma (requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)] | val open_close (e: stlc_exp) (x: var)
: Lemma (requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)] | let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0 | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 79,
"start_col": 0,
"start_line": 74
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> x: STLC.Core.var
-> FStar.Pervasives.Lemma (requires STLC.Core.ln e)
(ensures STLC.Core.open_exp (STLC.Core.close_exp e x) x == e)
[SMTPat (STLC.Core.open_exp (STLC.Core.close_exp e x) x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.var",
"STLC.Core.open_close'",
"Prims.unit",
"Prims.b2t",
"STLC.Core.ln",
"Prims.squash",
"Prims.eq2",
"STLC.Core.open_exp",
"STLC.Core.close_exp",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.nat",
"STLC.Core.size",
"Prims.Nil"
] | [] | true | false | true | false | false | let open_close (e: stlc_exp) (x: var)
: Lemma (requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)] =
| open_close' e x 0 | false |
STLC.Core.fst | STLC.Core.ln' | val ln' (e: stlc_exp) (n: int) : bool | val ln' (e: stlc_exp) (n: int) : bool | let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 38,
"start_col": 0,
"start_line": 31
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> n: Prims.int -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.stlc_exp",
"Prims.int",
"STLC.Core.var",
"STLC.Core.index",
"Prims.op_LessThanOrEqual",
"STLC.Core.stlc_ty",
"STLC.Core.ln'",
"Prims.op_Addition",
"Prims.op_AmpAmp",
"Prims.bool"
] | [
"recursion"
] | false | false | false | true | false | let rec ln' (e: stlc_exp) (n: int) : bool =
| match e with
| EUnit | EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n | false |
STLC.Core.fst | STLC.Core.size | val size (e: stlc_exp) : nat | val size (e: stlc_exp) : nat | let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2 | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 29,
"start_col": 0,
"start_line": 22
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.index",
"STLC.Core.var",
"STLC.Core.stlc_ty",
"Prims.op_Addition",
"STLC.Core.size",
"Prims.nat"
] | [
"recursion"
] | false | false | false | true | false | let rec size (e: stlc_exp) : nat =
| match e with
| EUnit | EBVar _ | EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2 | false |
EverParse3d.Prelude.fst | EverParse3d.Prelude.parse_string | val parse_string
(#k: parser_kind true WeakKindStrongPrefix)
(#t: eqtype)
(p: parser k t)
(terminator: t)
: Tot (parser parse_string_kind (cstring t terminator)) | val parse_string
(#k: parser_kind true WeakKindStrongPrefix)
(#t: eqtype)
(p: parser k t)
(terminator: t)
: Tot (parser parse_string_kind (cstring t terminator)) | let parse_string
#k #t p terminator
=
LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind (LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ())) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 103,
"end_line": 266,
"start_col": 0,
"start_line": 262
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Prelude
friend EverParse3d.Kinds
module BF = LowParse.BitFields
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
module LPL = LowParse.Low.Base
module LPLC = LowParse.Low.Combinators
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser k t = LP.parser k t
let is_weaker_than #nz1 #wk1 (k:parser_kind nz1 wk1)
#nz2 #wk2 (k':parser_kind nz2 wk2) = k `LP.is_weaker_than` k'
let is_weaker_than_refl #nz #wk (k:parser_kind nz wk)
: Lemma (ensures (is_weaker_than k k))
[SMTPat (is_weaker_than k k)]
= ()
let is_weaker_than_glb #nz1 #wk1 (k1:parser_kind nz1 wk1)
#nz2 #wk2 (k2:parser_kind nz2 wk2)
: Lemma (is_weaker_than (glb k1 k2) k1 /\
is_weaker_than (glb k1 k2) k2)
[SMTPatOr
[[SMTPat (is_weaker_than (glb k1 k2) k1)];
[SMTPat (is_weaker_than (glb k1 k2) k2)]]]
= ()
/// Parser: return
inline_for_extraction noextract
let parse_ret #t (v:t)
: Tot (parser ret_kind t)
= LPC.parse_ret #t v
/// Parser: bind
inline_for_extraction noextract
let parse_dep_pair p1 p2
= LPC.parse_dtuple2 p1 p2
/// Parser: sequencing
inline_for_extraction noextract
let parse_pair p1 p2
= LPC.nondep_then p1 p2
/// Parser: map
let injective_map a b = (a -> Tot b) //{LPC.synth_injective f}
inline_for_extraction noextract
let parse_filter p f
= LPC.parse_filter p f
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken #nz #wk (#k:parser_kind nz wk) #t (p:parser k t)
#nz' #wk' (k':parser_kind nz' wk' {k' `is_weaker_than` k})
: Tot (parser k' t)
= LP.weaken k' p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_left #nz #wk #k p k'
= LP.weaken (glb k' k) p
/// Parser: weakening kinds
inline_for_extraction noextract
let parse_weaken_right #nz #wk #k p k'
= LP.weaken (glb k k') p
/// Parser: unreachable, for default cases of exhaustive pattern matching
inline_for_extraction noextract
let parse_impos ()
: parser impos_kind False
= let p : LP.bare_parser False = fun b -> None in
LP.parser_kind_prop_equiv impos_kind p;
p
let parse_ite e p1 p2
= if e then p1 () else p2 ()
let nlist (n:U32.t) (t:Type) = list t
inline_for_extraction noextract
let parse_nlist n #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false #WeakKindStrongPrefix #(parse_fldata_kind (U32.v n) parse_list_kind) #(list t)
(LowParse.Spec.FLData.parse_fldata (LowParse.Spec.List.parse_list p) (U32.v n))
#false kind_nlist
let all_bytes = Seq.seq LP.byte
let parse_all_bytes'
: LP.bare_parser all_bytes
= fun input -> Some (input, (Seq.length input <: LP.consumed_length input))
let parse_all_bytes =
LP.parser_kind_prop_equiv kind_all_bytes parse_all_bytes';
parse_all_bytes'
////////////////////////////////////////////////////////////////////////////////
module B32 = FStar.Bytes
let t_at_most (n:U32.t) (t:Type) = t & all_bytes
inline_for_extraction noextract
let parse_t_at_most n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
(LPC.nondep_then p parse_all_bytes)
(U32.v n))
#false
kind_t_at_most
////////////////////////////////////////////////////////////////////////////////
let t_exact (n:U32.t) (t:Type) = t
inline_for_extraction noextract
let parse_t_exact n #nz #wk #k #t p
= let open LowParse.Spec.FLData in
let open LowParse.Spec.List in
parse_weaken
#false
#WeakKindStrongPrefix
(LowParse.Spec.FLData.parse_fldata
p
(U32.v n))
#false
kind_t_exact
////////////////////////////////////////////////////////////////////////////////
// Readers
////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let reader p = LPLC.leaf_reader p
inline_for_extraction noextract
let read_filter p32 f
= LPLC.read_filter p32 f
let read_impos : reader (parse_impos()) =
fun #rrel #rel sl pos ->
let h = FStar.HyperStack.ST.get() in
assert (LPLC.valid (parse_impos()) h sl pos);
LowParse.Low.Base.Spec.valid_equiv (parse_impos()) h sl pos;
false_elim ()
// ////////////////////////////////////////////////////////////////////////////////
// // Validators
// ////////////////////////////////////////////////////////////////////////////////
inline_for_extraction noextract
let validator #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator #k #t p
inline_for_extraction noextract
let validator_no_read #nz #wk (#k:parser_kind nz wk) (#t:Type) (p:parser k t)
: Type
= LPL.validator_no_read #k #t p
let parse_nlist_total_fixed_size_aux
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
(x: LP.bytes)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
Seq.length x >= U32.v n
))
(ensures (
Some? (LP.parse (parse_nlist n p) x)
))
= let x' = Seq.slice x 0 (U32.v n) in
let cnt = (U32.v n / k.LP.parser_kind_low) in
FStar.Math.Lemmas.lemma_div_exact (U32.v n) k.LP.parser_kind_low;
FStar.Math.Lemmas.nat_over_pos_is_nat (U32.v n) k.LP.parser_kind_low;
LowParse.Spec.List.parse_list_total_constant_size p cnt x';
LP.parser_kind_prop_equiv LowParse.Spec.List.parse_list_kind (LowParse.Spec.List.parse_list p)
let parse_nlist_total_fixed_size_kind_correct
(n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t)
: Lemma
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
U32.v n % k.parser_kind_low == 0 /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
LP.parser_kind_prop (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)
))
= LP.parser_kind_prop_equiv (LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) (parse_nlist n p);
LP.parser_kind_prop_equiv (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p);
Classical.forall_intro (Classical.move_requires (parse_nlist_total_fixed_size_aux n p))
inline_for_extraction noextract
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t)
: Pure (validator_no_read (parse_nlist n p))
(requires (
let open LP in
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_metadata == Some ParserKindMetadataTotal /\
k.parser_kind_low < 4294967296 /\
U32.v n % k.LP.parser_kind_low == 0
))
(ensures (fun _ -> True))
=
(fun #rrel #rel sl len pos ->
let h = FStar.HyperStack.ST.get () in
[@inline_let]
let _ =
parse_nlist_total_fixed_size_kind_correct n p;
LPL.valid_facts (parse_nlist n p) h sl (LPL.uint64_to_uint32 pos);
LPL.valid_facts (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) h sl (LPL.uint64_to_uint32 pos)
in
LPL.validate_total_constant_size_no_read (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (FStar.Int.Cast.uint32_to_uint64 n) () sl len pos
)
module LUT = LowParse.Spec.ListUpTo
inline_for_extraction
noextract
let cond_string_up_to
(#t: eqtype)
(terminator: t)
(x: t)
: Tot bool
= x = terminator
let cstring
(t: eqtype)
(terminator: t)
: Tot Type0
= LUT.parse_list_up_to_t (cond_string_up_to terminator) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Bytes.fsti.checked",
"EverParse3d.Kinds.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Prelude.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": "LUT"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Combinators",
"short_module": "LPLC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Kinds",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude.StaticHeader",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: EverParse3d.Prelude.parser k t -> terminator: t
-> EverParse3d.Prelude.parser EverParse3d.Kinds.parse_string_kind
(EverParse3d.Prelude.cstring t terminator) | Prims.Tot | [
"total"
] | [] | [
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"Prims.eqtype",
"EverParse3d.Prelude.parser",
"LowParse.Spec.Base.weaken",
"EverParse3d.Kinds.parse_string_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"EverParse3d.Prelude.cond_string_up_to",
"LowParse.Spec.ListUpTo.parse_list_up_to",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.consumed_length",
"Prims.unit",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"EverParse3d.Prelude.cstring"
] | [] | false | false | false | false | false | let parse_string #k #t p terminator =
| LowParse.Spec.Base.parser_kind_prop_equiv k p;
LP.weaken parse_string_kind
(LUT.parse_list_up_to (cond_string_up_to terminator) p (fun _ _ _ -> ())) | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.subtract_element_fact | val subtract_element_fact : Prims.logical | let subtract_element_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (s: FSet.set a) (key: a).{:pattern (elements (subtract m s)) key}
FSet.mem key (domain (subtract m s)) ==> FSet.mem key (domain m) /\ (elements (subtract m s)) key == (elements m) key | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 121,
"end_line": 400,
"start_col": 0,
"start_line": 398
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u']));
let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key')
/// We represent the following Dafny axiom with `insert_member_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m));
let insert_member_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
/// We represent the following Dafny axiom with `insert_nonmember_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// !Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m) + 1);
let insert_nonmember_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
not (FSet.mem key (domain m)) ==> cardinality (insert key value m) = cardinality m + 1
/// We represent the following Dafny axiom with `merge_domain_is_union_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V ::
/// { Map#Domain(Map#Merge(m, n)) }
/// Map#Domain(Map#Merge(m, n)) == Set#Union(Map#Domain(m), Map#Domain(n)));
let merge_domain_is_union_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b).{:pattern domain (merge m1 m2)}
domain (merge m1 m2) == FSet.union (domain m1) (domain m2)
/// We represent the following Dafny axiom with `merge_element_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V, u: U ::
/// { Map#Elements(Map#Merge(m, n))[u] }
/// Map#Domain(Map#Merge(m, n))[u] ==>
/// (!Map#Domain(n)[u] ==> Map#Elements(Map#Merge(m, n))[u] == Map#Elements(m)[u]) &&
/// (Map#Domain(n)[u] ==> Map#Elements(Map#Merge(m, n))[u] == Map#Elements(n)[u]));
let merge_element_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b) (key: a).{:pattern (elements (merge m1 m2)) key}
FSet.mem key (domain (merge m1 m2)) ==>
(not (FSet.mem key (domain m2)) ==> FSet.mem key (domain m1) /\ (elements (merge m1 m2)) key == (elements m1) key)
/\ (FSet.mem key (domain m2) ==> (elements (merge m1 m2)) key == (elements m2) key)
/// We represent the following Dafny axiom with `subtract_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V, s: Set U ::
/// { Map#Domain(Map#Subtract(m, s)) }
/// Map#Domain(Map#Subtract(m, s)) == Set#Difference(Map#Domain(m), s));
let subtract_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (s: FSet.set a).{:pattern domain (subtract m s)}
domain (subtract m s) == FSet.difference (domain m) s
/// We represent the following Dafny axiom with `subtract_element_fact`:
///
/// axiom (forall<U, V> m: Map U V, s: Set U, u: U ::
/// { Map#Elements(Map#Subtract(m, s))[u] }
/// Map#Domain(Map#Subtract(m, s))[u] ==>
/// Map#Elements(Map#Subtract(m, s))[u] == Map#Elements(m)[u]); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"FStar.FiniteSet.Base.set",
"Prims.l_imp",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"FStar.FiniteMap.Base.subtract",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.FiniteMap.Base.elements"
] | [] | false | false | false | true | true | let subtract_element_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b) (s: FSet.set a) (key: a).
{:pattern (elements (subtract m s)) key}
FSet.mem key (domain (subtract m s)) ==>
FSet.mem key (domain m) /\ (elements (subtract m s)) key == (elements m) key | false |
|
STLC.Core.fst | STLC.Core.test_id | val test_id : _: Prims.unit -> Prims.unit | let test_id () = assert (foo () == ()) by (T.compute ()) | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 553,
"start_col": 0,
"start_line": 553
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0
let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m
let rec close_exp_ln (e:stlc_exp) (v:var) (n:nat)
: Lemma
(requires ln' e (n - 1))
(ensures ln' (close_exp' e v n) n)
[SMTPat (ln' (close_exp' e v n) n)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> close_exp_ln e v (n + 1)
| EApp e1 e2 -> close_exp_ln e1 v n; close_exp_ln e2 v n
let rec freevars (e:stlc_exp)
: Set.set var
= match e with
| EUnit
| EBVar _ -> Set.empty
| EVar x -> Set.singleton x
| ELam _ e -> freevars e
| EApp e1 e2 -> freevars e1 `Set.union` freevars e2
let rec closed (e:stlc_exp)
: b:bool { b <==> (freevars e `Set.equal` Set.empty) }
= match e with
| EUnit
| EBVar _ -> true
| EVar x ->
assert (x `Set.mem` freevars e);
false
| ELam _ e -> closed e
| EApp e1 e2 -> closed e1 && closed e2
let rec freevars_open (e:stlc_exp) (x:var) (n:nat)
: Lemma (freevars (open_exp' e x n) `Set.subset`
(freevars e `Set.union` Set.singleton x))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam _ e -> freevars_open e x (n + 1)
| EApp e1 e2 ->
freevars_open e1 x n;
freevars_open e2 x n
let stlc_env = list (var & stlc_ty)
let lookup (e:list (var & 'a)) (x:var)
: option 'a
= L.assoc x e
let max (n1 n2:nat) = if n1 < n2 then n2 else n1
let rec fresh (e:list (var & 'a))
: var
= match e with
| [] -> 0
| hd :: tl ->
max (fresh tl) (fst hd) + 1
let _ = assert (fresh [1,();2,();3,();4,()] == 8) // odd.. but ok
let rec fresh_not_mem (e:list (var & 'a)) (elt: (var & 'a))
: Lemma (ensures L.memP elt e ==> fresh e > fst elt)
= match e with
| [] -> ()
| hd :: tl -> fresh_not_mem tl elt
let lookup_mem (e:list (var & 'a)) (x:var)
: Lemma
(requires Some? (lookup e x))
(ensures exists elt. L.memP elt e /\ fst elt == x)
= let Some y = lookup e x in
List.Tot.Properties.assoc_memP_some x y e
let fresh_is_fresh (e:list (var & 'a))
: Lemma (None? (lookup e (fresh e)))
= match lookup e (fresh e) with
| None -> ()
| Some _ ->
lookup_mem e (fresh e);
FStar.Classical.forall_intro (fresh_not_mem e)
[@@erasable]
noeq
type stlc_typing : stlc_env -> stlc_exp -> stlc_ty -> Type =
| T_Unit :
g:stlc_env ->
stlc_typing g EUnit TUnit
| T_Var :
g:stlc_env ->
x:var { Some? (lookup g x) } ->
stlc_typing g (EVar x) (Some?.v (lookup g x))
| T_Lam :
g:stlc_env ->
t:stlc_ty ->
e:stlc_exp ->
t':stlc_ty ->
x:var { None? (lookup g x) /\ ~ (Set.mem x (freevars e)) } ->
stlc_typing ((x,t)::g) (open_exp e x) t' ->
stlc_typing g (ELam t e) (TArrow t t')
| T_App :
g:stlc_env ->
e1:stlc_exp ->
e2:stlc_exp ->
t:stlc_ty ->
t':stlc_ty ->
stlc_typing g e1 (TArrow t t') ->
stlc_typing g e2 t ->
stlc_typing g (EApp e1 e2) t'
let tun = R.pack_ln R.Tv_Unknown
let rec ty_to_string' should_paren (t:stlc_ty)
: Tot string (decreases t)
= match t with
| TUnit -> "unit"
| TArrow t1 t2 ->
let t = Printf.sprintf "%s -> %s"
(ty_to_string' true t1)
(ty_to_string' false t2) in
if should_paren
then Printf.sprintf "(%s)" t
else t
let ty_to_string = ty_to_string' false
let mem_intension_pat (#a:eqtype) (x:a) (f:(a -> Tot bool))
: Lemma
(ensures FStar.Set.(mem x (intension f) = f x))
[SMTPat FStar.Set.(mem x (intension f))]
= Set.mem_intension x f
let contains (sg:list (var & stlc_ty)) (x:var) =
Some? (lookup sg x)
let vars_of_env (sg:list (var & stlc_ty))
: GTot (Set.set var)
= Set.intension (contains sg)
let rec check (g:R.env)
(sg:list (var & stlc_ty))
(e:stlc_exp { ln e /\ (freevars e `Set.subset` vars_of_env sg)})
: T.Tac (t:stlc_ty &
stlc_typing sg e t)
= match e with
| EUnit ->
let d = T_Unit sg in
(| TUnit, d |)
| EVar n ->
begin
match lookup sg n with
| None -> T.fail "Ill-typed"
| Some t ->
let d = T_Var sg n in
(| t, d |)
end
| ELam t e ->
let x = fresh sg in
fresh_is_fresh sg;
freevars_open e x 0;
let (| tbody, dbody |) = check g ((x,t)::sg) (open_exp e x) in
(| TArrow t tbody,
T_Lam sg t e tbody x dbody |)
| EApp e1 e2 ->
let (| t1, d1 |) = check g sg e1 in
let (| t2, d2 |) = check g sg e2 in
match t1 with
| TArrow t2' t ->
if t2' = t2
then (| t, T_App _ _ _ _ _ d1 d2 |)
else T.fail
(Printf.sprintf "Expected argument of type %s got %s"
(ty_to_string t2')
(ty_to_string t2))
| _ ->
T.fail (Printf.sprintf "Expected an arrow, got %s"
(ty_to_string t1))
let rec elab_ty (t:stlc_ty)
: R.term
= let open R in
match t with
| TUnit ->
R.pack_ln (R.Tv_FVar (R.pack_fv unit_lid))
| TArrow t1 t2 ->
let t1 = elab_ty t1 in
let t2 = elab_ty t2 in
R.pack_ln
(R.Tv_Arrow
(RT.mk_simple_binder RT.pp_name_default t1)
(R.pack_comp (C_Total t2)))
let rec elab_exp (e:stlc_exp)
: Tot R.term (decreases (size e))
= let open R in
match e with
| EUnit ->
pack_ln (Tv_Const C_Unit)
| EBVar n ->
let bv = R.pack_bv (RT.make_bv n) in
R.pack_ln (Tv_BVar bv)
| EVar n ->
let bv = R.pack_namedv (RT.make_namedv n) in
R.pack_ln (Tv_Var bv)
| ELam t e ->
let t = elab_ty t in
let e = elab_exp e in
R.pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default t) e)
| EApp e1 e2 ->
let e1 = elab_exp e1 in
let e2 = elab_exp e2 in
R.pack_ln (Tv_App e1 (e2, Q_Explicit))
let extend_env_l (g:R.env) (sg:stlc_env) =
L.fold_right (fun (x, t) g -> RT.extend_env g x (elab_ty t)) sg g
let rec extend_env_l_lookup_bvar (g:R.env) (sg:stlc_env) (x:var)
: Lemma
(requires (forall x. RT.lookup_bvar g x == None))
(ensures (
match lookup sg x with
| Some t -> RT.lookup_bvar (extend_env_l g sg) x == Some (elab_ty t)
| None -> RT.lookup_bvar (extend_env_l g sg) x == None))
(decreases sg)
[SMTPat (RT.lookup_bvar (extend_env_l g sg) x)]
= match sg with
| [] -> ()
| hd :: tl -> extend_env_l_lookup_bvar g tl x
open FStar.Calc
//key lemma about STLC types: Their elaborations are closed
let rec stlc_types_are_closed_core (ty:stlc_ty) (ss:RT.subst)
: Lemma (ensures RT.subst_term (elab_ty ty) ss == elab_ty ty)
(decreases ty)
[SMTPat (RT.subst_term (elab_ty ty) ss)]
= match ty with
| TUnit -> ()
| TArrow t1 t2 ->
stlc_types_are_closed_core t1 ss;
stlc_types_are_closed_core t2 (RT.shift_subst ss)
let stlc_types_are_closed1 (ty:stlc_ty) (v:R.term)
: Lemma (RT.open_with (elab_ty ty) v == elab_ty ty)
[SMTPat (RT.open_with (elab_ty ty) v)]
= stlc_types_are_closed_core ty [ RT.DT 0 v ];
RT.open_with_spec (elab_ty ty) v
let stlc_types_are_closed2 (ty:stlc_ty) (x:R.var)
: Lemma (RT.close_term (elab_ty ty) x == elab_ty ty)
[SMTPat (RT.close_term (elab_ty ty) x)]
= stlc_types_are_closed_core ty [ RT.ND x 0 ];
RT.close_term_spec (elab_ty ty) x
let stlc_types_are_closed3 (ty:stlc_ty) (x:R.var)
: Lemma (RT.open_term (elab_ty ty) x == elab_ty ty)
[SMTPat (RT.open_term (elab_ty ty) x)]
= stlc_types_are_closed_core ty [ RT.DT 0 (RT.var_as_term x) ];
RT.open_term_spec (elab_ty ty) x
let rec elab_ty_freevars (ty:stlc_ty)
: Lemma (RT.freevars (elab_ty ty) `Set.equal` Set.empty)
= match ty with
| TUnit -> ()
| TArrow t1 t2 ->
elab_ty_freevars t1;
elab_ty_freevars t2
let rec elab_open_commute' (e:stlc_exp) (x:var) (n:nat)
: Lemma (ensures
RT.subst_term (elab_exp e) (RT.open_with_var x n) ==
elab_exp (open_exp' e x n))
(decreases e)
= match e with
| EUnit -> ()
| EBVar _ -> ()
| EVar _ -> ()
| EApp e1 e2 ->
elab_open_commute' e1 x n;
elab_open_commute' e2 x n
| ELam t e ->
calc (==) {
elab_exp (open_exp' (ELam t e) x n);
(==) {}
elab_exp (ELam t (open_exp' e x (n + 1)));
(==) { }
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t)) (elab_exp (open_exp' e x (n + 1)))));
(==) { elab_open_commute' e x (n + 1) }
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t))
(RT.subst_term (elab_exp e) RT.(open_with_var x (n + 1)))));
(==) { stlc_types_are_closed_core t (RT.open_with_var x n) }
RT.subst_term
R.(pack_ln (Tv_Abs (RT.mk_simple_binder RT.pp_name_default (elab_ty t)) (elab_exp e)))
RT.(open_with_var x n);
}
let elab_open_commute (e:stlc_exp) (x:var)
: Lemma (RT.open_term (elab_exp e) x == elab_exp (open_exp e x))
[SMTPat (RT.open_term (elab_exp e) x)]
= elab_open_commute' e x 0;
RT.open_term_spec (elab_exp e) x
let rec extend_env_l_lookup_fvar (g:R.env) (sg:stlc_env) (fv:R.fv)
: Lemma
(ensures
RT.lookup_fvar (extend_env_l g sg) fv ==
RT.lookup_fvar g fv)
[SMTPat (RT.lookup_fvar (extend_env_l g sg) fv)]
= match sg with
| [] -> ()
| hd::tl -> extend_env_l_lookup_fvar g tl fv
let rec elab_ty_soundness (g:RT.fstar_top_env)
(sg:stlc_env)
(t:stlc_ty)
: GTot (RT.tot_typing (extend_env_l g sg) (elab_ty t) (RT.tm_type RT.u_zero))
(decreases t)
= match t with
| TUnit ->
RT.T_FVar _ RT.unit_fv
| TArrow t1 t2 ->
let t1_ok = elab_ty_soundness g sg t1 in
let x = fresh sg in
fresh_is_fresh sg;
elab_ty_freevars t2;
let t2_ok = elab_ty_soundness g ((x, t1)::sg) t2 in
let arr_max
: RT.tot_typing
(extend_env_l g sg)
(elab_ty t)
(RT.tm_type RT.(u_max u_zero u_zero))
= RT.T_Arrow _ x (elab_ty t1) (elab_ty t2)
_ _ RT.pp_name_default R.Q_Explicit T.E_Total _ _ t1_ok t2_ok
in
RT.simplify_umax arr_max
let rec elab_exp_freevars (e:stlc_exp)
: Lemma (freevars e `Set.equal` RT.freevars (elab_exp e))
= match e with
| EUnit
| EBVar _
| EVar _ -> ()
| ELam t e ->
elab_ty_freevars t;
elab_exp_freevars e
| EApp e1 e2 ->
elab_exp_freevars e1;
elab_exp_freevars e2
let rec soundness (#sg:stlc_env)
(#se:stlc_exp)
(#st:stlc_ty)
(dd:stlc_typing sg se st)
(g:RT.fstar_top_env)
: GTot (RT.tot_typing (extend_env_l g sg)
(elab_exp se)
(elab_ty st))
(decreases dd)
= match dd with
| T_Unit _ ->
RT.T_Const _ _ _ RT.CT_Unit
| T_Var _ x ->
RT.T_Var _ (R.pack_namedv (RT.make_namedv x))
| T_Lam _ t e t' x de ->
let de : RT.tot_typing (extend_env_l g ((x,t)::sg))
(elab_exp (open_exp e x))
(elab_ty t')
= soundness de g
in
let de : RT.tot_typing (RT.extend_env (extend_env_l g sg) x (elab_ty t))
(elab_exp (open_exp e x))
(elab_ty t')
= de
in
fresh_is_fresh sg;
elab_exp_freevars e;
let dd
= RT.T_Abs (extend_env_l g sg)
x
(elab_ty t)
(elab_exp e)
(T.E_Total, elab_ty t')
_
RT.pp_name_default
R.Q_Explicit
_
(elab_ty_soundness g sg t)
de
in
dd
| T_App _ e1 e2 t t' d1 d2 ->
let dt1
: RT.tot_typing (extend_env_l g sg)
(elab_exp e1)
(elab_ty (TArrow t t'))
= soundness d1 g
in
let dt2
: RT.tot_typing (extend_env_l g sg)
(elab_exp e2)
(elab_ty t)
= soundness d2 g
in
let dt :
RT.tot_typing (extend_env_l g sg)
(elab_exp (EApp e1 e2))
(RT.open_with (elab_ty t') (elab_exp e2))
= RT.T_App _ _ _ _ _ _ dt1 dt2
in
dt
let soundness_lemma (sg:stlc_env)
(se:stlc_exp)
(st:stlc_ty)
(g:RT.fstar_top_env)
: Lemma
(requires stlc_typing sg se st)
(ensures RT.tot_typing (extend_env_l g sg)
(elab_exp se)
(elab_ty st))
= FStar.Squash.bind_squash
#(stlc_typing sg se st)
()
(fun dd -> FStar.Squash.return_squash (soundness dd g))
let main (nm:string) (src:stlc_exp) : RT.dsl_tac_t =
fun g ->
if ln src && closed src
then
let (| src_ty, d |) = check g [] src in
soundness_lemma [] src src_ty g;
[RT.mk_checked_let g nm (elab_exp src) (elab_ty src_ty)]
else T.fail "Not locally nameless"
(***** Tests *****)
%splice_t[foo] (main "foo" (ELam TUnit (EBVar 0))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": true,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"STLC.Core.foo",
"FStar.Tactics.V2.Derived.compute"
] | [] | false | false | false | true | false | let test_id () =
| FStar.Tactics.Effect.assert_by_tactic (foo () == ())
(fun _ ->
();
(T.compute ())) | false |
|
STLC.Core.fst | STLC.Core.open_close' | val open_close' (e: stlc_exp) (x: var) (n: nat{ln' e (n - 1)})
: Lemma (open_exp' (close_exp' e x n) x n == e) | val open_close' (e: stlc_exp) (x: var) (n: nat{ln' e (n - 1)})
: Lemma (open_exp' (close_exp' e x n) x n == e) | let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 72,
"start_col": 0,
"start_line": 63
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> x: STLC.Core.var -> n: Prims.nat{STLC.Core.ln' e (n - 1)}
-> FStar.Pervasives.Lemma (ensures STLC.Core.open_exp' (STLC.Core.close_exp' e x n) x n == e) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.var",
"Prims.nat",
"Prims.b2t",
"STLC.Core.ln'",
"Prims.op_Subtraction",
"STLC.Core.index",
"STLC.Core.stlc_ty",
"STLC.Core.open_close'",
"Prims.op_Addition",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"STLC.Core.open_exp'",
"STLC.Core.close_exp'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec open_close' (e: stlc_exp) (x: var) (n: nat{ln' e (n - 1)})
: Lemma (open_exp' (close_exp' e x n) x n == e) =
| match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.insert_member_cardinality_fact | val insert_member_cardinality_fact : Prims.logical | let insert_member_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 80,
"end_line": 346,
"start_col": 0,
"start_line": 344
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u']));
let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key')
/// We represent the following Dafny axiom with `insert_member_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m)); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_imp",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"Prims.op_Equality",
"Prims.nat",
"FStar.FiniteMap.Base.cardinality",
"FStar.FiniteMap.Base.insert"
] | [] | false | false | false | true | true | let insert_member_cardinality_fact =
| forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).
{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m | false |
|
STLC.Core.fst | STLC.Core.open_exp_ln | val open_exp_ln (e: stlc_exp) (v: var) (n: index) (m: int)
: Lemma (requires ln' e n /\ m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n); SMTPat (ln' (open_exp' e v n) m)] | val open_exp_ln (e: stlc_exp) (v: var) (n: index) (m: int)
: Lemma (requires ln' e n /\ m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n); SMTPat (ln' (open_exp' e v n) m)] | let rec open_exp_ln (e:stlc_exp) (v:var) (n:index) (m:int)
: Lemma
(requires ln' e n /\
m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n);
SMTPat (ln' (open_exp' e v n) m)]
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 -> open_exp_ln e1 v n m; open_exp_ln e2 v n m | {
"file_name": "examples/dsls/stlc/STLC.Core.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 62,
"end_line": 93,
"start_col": 0,
"start_line": 81
} | module STLC.Core
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module RT = FStar.Reflection.Typing
type stlc_ty =
| TUnit
| TArrow : stlc_ty -> stlc_ty -> stlc_ty
let var = nat
let index = nat
noeq
type stlc_exp =
| EUnit : stlc_exp
| EBVar : index -> stlc_exp
| EVar : var -> stlc_exp
| ELam : stlc_ty -> stlc_exp -> stlc_exp
| EApp : stlc_exp -> stlc_exp -> stlc_exp
let rec size (e:stlc_exp)
: nat
= match e with
| EUnit
| EBVar _
| EVar _ -> 1
| ELam _ e -> 1 + size e
| EApp e1 e2 -> 1 + size e1 + size e2
let rec ln' (e:stlc_exp) (n:int)
: bool
= match e with
| EUnit
| EVar _ -> true
| EBVar m -> m <= n
| ELam _ e -> ln' e (n + 1)
| EApp e1 e2 -> ln' e1 n && ln' e2 n
let ln e = ln' e (-1)
let rec open_exp' (e:stlc_exp) (v:var) (n:index)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> EVar m
| EBVar m -> if m = n then EVar v else EBVar m
| ELam t e -> ELam t (open_exp' e v (n + 1))
| EApp e1 e2 -> EApp (open_exp' e1 v n) (open_exp' e2 v n)
let rec close_exp' (e:stlc_exp) (v:var) (n:nat)
: e':stlc_exp { size e == size e'}
= match e with
| EUnit -> EUnit
| EVar m -> if m = v then EBVar n else EVar m
| EBVar m -> EBVar m
| ELam t e -> ELam t (close_exp' e v (n + 1))
| EApp e1 e2 -> EApp (close_exp' e1 v n) (close_exp' e2 v n)
let open_exp e v = open_exp' e v 0
let close_exp e v = close_exp' e v 0
let rec open_close' (e:stlc_exp) (x:var) (n:nat { ln' e (n - 1) })
: Lemma (open_exp' (close_exp' e x n) x n == e)
= match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_close' e x (n + 1)
| EApp e1 e2 ->
open_close' e1 x n;
open_close' e2 x n
let open_close (e:stlc_exp) (x:var)
: Lemma
(requires ln e)
(ensures open_exp (close_exp e x) x == e)
[SMTPat (open_exp (close_exp e x) x)]
= open_close' e x 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "STLC.Core.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "STLC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: STLC.Core.stlc_exp -> v: STLC.Core.var -> n: STLC.Core.index -> m: Prims.int
-> FStar.Pervasives.Lemma (requires STLC.Core.ln' e n /\ m == n - 1)
(ensures STLC.Core.ln' (STLC.Core.open_exp' e v n) m)
[SMTPat (STLC.Core.ln' e n); SMTPat (STLC.Core.ln' (STLC.Core.open_exp' e v n) m)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"STLC.Core.stlc_exp",
"STLC.Core.var",
"STLC.Core.index",
"Prims.int",
"STLC.Core.stlc_ty",
"STLC.Core.open_exp_ln",
"Prims.op_Addition",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"STLC.Core.ln'",
"Prims.eq2",
"Prims.op_Subtraction",
"Prims.squash",
"STLC.Core.open_exp'",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.bool",
"Prims.Nil"
] | [
"recursion"
] | false | false | true | false | false | let rec open_exp_ln (e: stlc_exp) (v: var) (n: index) (m: int)
: Lemma (requires ln' e n /\ m == n - 1)
(ensures ln' (open_exp' e v n) m)
[SMTPat (ln' e n); SMTPat (ln' (open_exp' e v n) m)] =
| match e with
| EUnit -> ()
| EVar _ -> ()
| EBVar m -> ()
| ELam _ e -> open_exp_ln e v (n + 1) (m + 1)
| EApp e1 e2 ->
open_exp_ln e1 v n m;
open_exp_ln e2 v n m | false |
FStar.FiniteMap.Base.fsti | FStar.FiniteMap.Base.map_equal_fact | val map_equal_fact : Prims.logical | let map_equal_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b).{:pattern equal m1 m2}
equal m1 m2 <==> (forall key. FSet.mem key (domain m1) = FSet.mem key (domain m2))
/\ (forall key. FSet.mem key (domain m1) ==> (elements m1) key == (elements m2) key) | {
"file_name": "ulib/FStar.FiniteMap.Base.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 103,
"end_line": 412,
"start_col": 0,
"start_line": 409
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite maps as they're modeled in Dafny.
@summary Type and functions for modeling finite maps
*)
module FStar.FiniteMap.Base
open FStar.FunctionalExtensionality
module FLT = FStar.List.Tot
module FSet = FStar.FiniteSet.Base
type setfun_t (a: eqtype)
(b: Type u#b)
(s: FSet.set a) =
f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)}
val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b)
: Type u#b
(**
We translate each Dafny sequence function prefixed with `Map#`
into an F* function.
**)
/// We represent the Dafny function `Map#Domain` with `domain`:
///
/// function Map#Domain<U,V>(Map U V) : Set U;
val domain (#a: eqtype) (#b: Type u#b) (m: map a b)
: FSet.set a
/// We represent the Dafny function `Map#Elements` with `elements`:
///
/// function Map#Elements<U,V>(Map U V) : [U]V;
val elements (#a: eqtype) (#b: Type u#b) (m: map a b)
: setfun_t a b (domain m)
/// We represent the Dafny operator `in` on maps with `mem`:
let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) =
FSet.mem key (domain m)
/// We can convert a map to a list of pairs with `map_as_list`:
let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool =
match items with
| [] -> false
| (k, v) :: tl -> key = k || key_in_item_list key tl
let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool =
match items with
| [] -> true
| (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
/// We represent the Dafny operator [] on maps with `lookup`:
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
: b =
Some?.v ((elements m) key)
/// We represent the Dafny function `Map#Card` with `cardinality`:
///
/// function Map#Card<U,V>(Map U V) : int;
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot nat
/// We represent the Dafny function `Map#Values` with `values`:
///
/// function Map#Values<U,V>(Map U V) : Set V;
val values (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot (b -> prop)
/// We represent the Dafny function `Map#Items` with `items`:
///
/// function Map#Items<U,V>(Map U V) : Set Box;
val items (#a: eqtype) (#b: Type u#b) (m: map a b)
: GTot ((a * b) -> prop)
/// We represent the Dafny function `Map#Empty` with `emptymap`:
///
/// function Map#Empty<U, V>(): Map U V;
val emptymap (#a: eqtype) (#b: Type u#b)
: map a b
/// We represent the Dafny function `Map#Glue` with `glue`.
///
/// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys)
: map a b
/// We represent the Dafny function `Map#Build` with `insert`:
///
/// function Map#Build<U, V>(Map U V, U, V): Map U V;
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b)
: map a b
/// We represent the Dafny function `Map#Merge` with `merge`:
///
/// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: map a b
/// We represent the Dafny function `Map#Subtract` with `subtract`:
///
/// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a)
: map a b
/// We represent the Dafny function `Map#Equal` with `equal`:
///
/// function Map#Equal<U, V>(Map U V, Map U V): bool;
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny function `Map#Disjoint` with `disjoint`:
///
/// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b)
: prop
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m})
: GTot (key: a{mem key m})
/// We add the utility functions `remove` and `notin`:
let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: map a b =
subtract m (FSet.singleton key)
let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b)
: bool =
not (mem key m)
(**
We translate each finite map axiom from the Dafny prelude into an F*
predicate ending in `_fact`.
**)
/// We don't need the following axiom since we return a nat from cardinality:
///
/// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m));
/// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Card(m) }
/// Map#Card(m) == 0 <==> m == Map#Empty());
let cardinality_zero_iff_empty_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m}
cardinality m = 0 <==> m == emptymap
/// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Domain(m) }
/// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k]));
let empty_or_domain_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m}
m == emptymap \/ (exists k.{:pattern mem k m} mem k m)
/// We represent the following Dafny axiom with `empty_or_values_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Values(m) }
/// m == Map#Empty() || (exists v: V :: Map#Values(m)[v]));
let empty_or_values_occupied_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m}
m == emptymap \/ (exists v. {:pattern values m v } (values m) v)
/// We represent the following Dafny axiom with `empty_or_items_occupied_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Map#Items(m) }
/// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))]));
let empty_or_items_occupied_fact =
forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m}
m == emptymap \/ (exists item. {:pattern items m item } (items m) item)
/// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Domain(m)) }
/// Set#Card(Map#Domain(m)) == Map#Card(m));
let map_cardinality_matches_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)}
FSet.cardinality (domain m) = cardinality m
/// We don't use the following Dafny axioms, which would require
/// treating the values and items as finite sets, which we can't do
/// because we want to allow non-eqtypes as values.
///
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Values(m)) }
/// Set#Card(Map#Values(m)) <= Map#Card(m));
/// axiom (forall<U, V> m: Map U V ::
/// { Set#Card(Map#Items(m)) }
/// Set#Card(Map#Items(m)) == Map#Card(m));
/// We represent the following Dafny axiom with `values_contains_fact`:
///
/// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] }
/// Map#Values(m)[v] ==
/// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] }
/// Map#Domain(m)[u] &&
/// v == Map#Elements(m)[u]));
let values_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v}
(values m) v <==>
(exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)}
FSet.mem u (domain m) /\ (elements m) u == Some v)
/// We represent the following Dafny axiom with `items_contains_fact`:
///
/// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] }
/// Map#Items(m)[item] <==>
/// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] &&
/// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item)));
let items_contains_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item}
(items m) item <==>
FSet.mem (fst item) (domain m)
/\ (elements m) (fst item) == Some (snd item)
/// We represent the following Dafny axiom with `empty_domain_empty_fact`:
///
/// axiom (forall<U, V> u: U ::
/// { Map#Domain(Map#Empty(): Map U V)[u] }
/// !Map#Domain(Map#Empty(): Map U V)[u]);
let empty_domain_empty_fact =
forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))}
not (FSet.mem u (domain (emptymap #a #b)))
/// We represent the following Dafny axiom with `glue_domain_fact`:
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Domain(Map#Glue(a, b, t)) }
/// Map#Domain(Map#Glue(a, b, t)) == a);
let glue_domain_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)}
domain (glue keys f) == keys
/// We represent the following Dafny axiom with `glue_elements_fact`.
/// But we have to change it because our version of `Map#Elements`
/// returns a map to an optional value.
///
/// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty ::
/// { Map#Elements(Map#Glue(a, b, t)) }
/// Map#Elements(Map#Glue(a, b, t)) == b);
let glue_elements_fact =
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)}
domain (glue keys f) == keys
/\ elements (glue keys f) == f
/// We don't need the following Dafny axiom since the type of `glue` implies it:
///
/// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty ::
/// { Map#Glue(a, b, TMap(t0, t1)) }
/// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts
/// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1))
/// ==>
/// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1)));
/// We represent the following Dafny axiom with `insert_elements_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V ::
/// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] }
/// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == v) &&
/// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] &&
/// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u']));
let insert_elements_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b).
{:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')}
(key' = key ==> FSet.mem key' (domain (insert key value m))
/\ (elements (insert key value m)) key' == Some value)
/\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m)
/\ (elements (insert key value m)) key' == (elements m) key')
/// We represent the following Dafny axiom with `insert_member_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m));
let insert_member_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
/// We represent the following Dafny axiom with `insert_nonmember_cardinality_fact`:
///
/// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) }
/// !Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m) + 1);
let insert_nonmember_cardinality_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)}
not (FSet.mem key (domain m)) ==> cardinality (insert key value m) = cardinality m + 1
/// We represent the following Dafny axiom with `merge_domain_is_union_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V ::
/// { Map#Domain(Map#Merge(m, n)) }
/// Map#Domain(Map#Merge(m, n)) == Set#Union(Map#Domain(m), Map#Domain(n)));
let merge_domain_is_union_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b).{:pattern domain (merge m1 m2)}
domain (merge m1 m2) == FSet.union (domain m1) (domain m2)
/// We represent the following Dafny axiom with `merge_element_fact`:
///
/// axiom (forall<U, V> m: Map U V, n: Map U V, u: U ::
/// { Map#Elements(Map#Merge(m, n))[u] }
/// Map#Domain(Map#Merge(m, n))[u] ==>
/// (!Map#Domain(n)[u] ==> Map#Elements(Map#Merge(m, n))[u] == Map#Elements(m)[u]) &&
/// (Map#Domain(n)[u] ==> Map#Elements(Map#Merge(m, n))[u] == Map#Elements(n)[u]));
let merge_element_fact =
forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b) (key: a).{:pattern (elements (merge m1 m2)) key}
FSet.mem key (domain (merge m1 m2)) ==>
(not (FSet.mem key (domain m2)) ==> FSet.mem key (domain m1) /\ (elements (merge m1 m2)) key == (elements m1) key)
/\ (FSet.mem key (domain m2) ==> (elements (merge m1 m2)) key == (elements m2) key)
/// We represent the following Dafny axiom with `subtract_domain_fact`:
///
/// axiom (forall<U, V> m: Map U V, s: Set U ::
/// { Map#Domain(Map#Subtract(m, s)) }
/// Map#Domain(Map#Subtract(m, s)) == Set#Difference(Map#Domain(m), s));
let subtract_domain_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (s: FSet.set a).{:pattern domain (subtract m s)}
domain (subtract m s) == FSet.difference (domain m) s
/// We represent the following Dafny axiom with `subtract_element_fact`:
///
/// axiom (forall<U, V> m: Map U V, s: Set U, u: U ::
/// { Map#Elements(Map#Subtract(m, s))[u] }
/// Map#Domain(Map#Subtract(m, s))[u] ==>
/// Map#Elements(Map#Subtract(m, s))[u] == Map#Elements(m)[u]);
let subtract_element_fact =
forall (a: eqtype) (b: Type u#b) (m: map a b) (s: FSet.set a) (key: a).{:pattern (elements (subtract m s)) key}
FSet.mem key (domain (subtract m s)) ==> FSet.mem key (domain m) /\ (elements (subtract m s)) key == (elements m) key
/// We represent the following Dafny axiom with `map_equal_fact`:
///
/// axiom (forall<U, V> m: Map U V, m': Map U V::
/// { Map#Equal(m, m') }
/// Map#Equal(m, m') <==> (forall u : U :: Map#Domain(m)[u] == Map#Domain(m')[u]) &&
/// (forall u : U :: Map#Domain(m)[u] ==> Map#Elements(m)[u] == Map#Elements(m')[u])); | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.FiniteSet.Base.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.FiniteMap.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.FiniteSet.Base",
"short_module": "FSet"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Forall",
"Prims.eqtype",
"FStar.FiniteMap.Base.map",
"Prims.l_iff",
"FStar.FiniteMap.Base.equal",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteMap.Base.domain",
"Prims.l_imp",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.FiniteMap.Base.elements"
] | [] | false | false | false | true | true | let map_equal_fact =
| forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b). {:pattern equal m1 m2}
equal m1 m2 <==>
(forall key. FSet.mem key (domain m1) = FSet.mem key (domain m2)) /\
(forall key. FSet.mem key (domain m1) ==> (elements m1) key == (elements m2) key) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.