effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
} | let comp_intro_pure (p: term) = | false | null | false | C_STGhost tm_emp_inames ({ u = u_zero; res = tm_unit; pre = tm_emp; post = tm_pure p }) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u_zero",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Base.tm_emp",
"Pulse.Syntax.Base.tm_pure",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_intro_pure : p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | [] | Pulse.Typing.comp_intro_pure | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | {
"end_col": 13,
"end_line": 313,
"start_col": 2,
"start_line": 307
} |
|
Prims.Tot | val comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
} | val comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp
let comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp = | false | null | false | C_STGhost tm_emp_inames
({
u = u;
res = mk_erased u t;
pre = tm_exists_sl u (as_binder t) p;
post = elim_exists_post u t p x
}) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.nvar",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Typing.mk_erased",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Base.as_binder",
"Pulse.Typing.elim_exists_post",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_elim_exists (u: universe) (t p: term) (x: nvar) : comp | [] | Pulse.Typing.comp_elim_exists | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
u111: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
p: Pulse.Syntax.Base.term ->
x: Pulse.Syntax.Base.nvar
-> Pulse.Syntax.Base.comp | {
"end_col": 15,
"end_line": 304,
"start_col": 4,
"start_line": 298
} |
Prims.Tot | val bind_comp_compatible (c1 c2: comp_st) : prop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False | val bind_comp_compatible (c1 c2: comp_st) : prop
let bind_comp_compatible (c1 c2: comp_st) : prop = | false | null | false | match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Prims.eq2",
"Prims.l_True",
"Prims.l_False",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_compatible (c1 c2: comp_st) : prop | [] | Pulse.Typing.bind_comp_compatible | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st -> Prims.prop | {
"end_col": 19,
"end_line": 222,
"start_col": 4,
"start_line": 219
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t) | let non_informative_t (g: env) (u: universe) (t: term) = | false | null | false | w: term & tot_typing g w (non_informative_witness_t u t) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Prims.dtuple2",
"Pulse.Typing.tot_typing",
"Pulse.Typing.non_informative_witness_t"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val non_informative_t : g: Pulse.Typing.Env.env -> u223: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Type0 | [] | Pulse.Typing.non_informative_t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> u223: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Type0 | {
"end_col": 57,
"end_line": 511,
"start_col": 2,
"start_line": 511
} |
|
Prims.Tot | val comp_while_cond (x: ppname) (inv: term) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
} | val comp_while_cond (x: ppname) (inv: term) : comp
let comp_while_cond (x: ppname) (inv: term) : comp = | false | null | false | C_ST ({ u = u0; res = tm_bool; pre = tm_exists_sl u0 (named_binder x tm_bool) inv; post = inv }) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_bool",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Typing.named_binder",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_while_cond (x: ppname) (inv: term) : comp | [] | Pulse.Typing.comp_while_cond | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.ppname -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | {
"end_col": 10,
"end_line": 345,
"start_col": 4,
"start_line": 340
} |
Prims.Tot | val mk_tuple2 (u1 u2: universe) (t1 t2: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2 | val mk_tuple2 (u1 u2: universe) (t1 t2: term) : term
let mk_tuple2 (u1 u2: universe) (t1 t2: term) : term = | false | null | false | tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.tuple2_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_tuple2 (u1 u2: universe) (t1 t2: term) : term | [] | Pulse.Typing.mk_tuple2 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
u1: Pulse.Syntax.Base.universe ->
u2: Pulse.Syntax.Base.universe ->
t1: Pulse.Syntax.Base.term ->
t2: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | {
"end_col": 20,
"end_line": 369,
"start_col": 2,
"start_line": 366
} |
Prims.Tot | val comp_while_body (x: ppname) (inv: term) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
} | val comp_while_body (x: ppname) (inv: term) : comp
let comp_while_body (x: ppname) (inv: term) : comp = | false | null | false | C_ST
({
u = u0;
res = tm_unit;
pre = open_term' inv tm_true 0;
post = tm_exists_sl u0 (named_binder x tm_bool) inv
}) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.tm_true",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Typing.named_binder",
"Pulse.Typing.tm_bool",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_while_body (x: ppname) (inv: term) : comp | [] | Pulse.Typing.comp_while_body | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.ppname -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | {
"end_col": 10,
"end_line": 354,
"start_col": 4,
"start_line": 349
} |
Prims.Tot | val comp_while (x: ppname) (inv: term) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
} | val comp_while (x: ppname) (inv: term) : comp
let comp_while (x: ppname) (inv: term) : comp = | false | null | false | C_ST
({
u = u0;
res = tm_unit;
pre = tm_exists_sl u0 (named_binder x tm_bool) inv;
post = open_term' inv tm_false 0
}) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Typing.named_binder",
"Pulse.Typing.tm_bool",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.tm_false",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_while (x: ppname) (inv: term) : comp | [] | Pulse.Typing.comp_while | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.ppname -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | {
"end_col": 10,
"end_line": 363,
"start_col": 4,
"start_line": 358
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u) | let universe_of (g: env) (t: term) (u: universe) = | false | null | false | tot_typing g t (tm_type u) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.universe",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Pure.tm_type"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val universe_of : g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> u221: Pulse.Syntax.Base.universe -> Type0 | [] | Pulse.Typing.universe_of | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> u221: Pulse.Syntax.Base.universe -> Type0 | {
"end_col": 28,
"end_line": 508,
"start_col": 2,
"start_line": 508
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) | let subtyping_token g t1 t2 = | false | null | false | T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Tactics.Types.subtyping_token",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subtyping_token : g: Pulse.Typing.Env.env -> t1: Pulse.Syntax.Base.term -> t2: Pulse.Syntax.Base.term -> Type0 | [] | Pulse.Typing.subtyping_token | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> t1: Pulse.Syntax.Base.term -> t2: Pulse.Syntax.Base.term -> Type0 | {
"end_col": 62,
"end_line": 651,
"start_col": 2,
"start_line": 651
} |
|
Prims.Tot | val mk_erased (u: universe) (t: term) : term | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t | val mk_erased (u: universe) (t: term) : term
let mk_erased (u: universe) (t: term) : term = | false | null | false | let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.erased_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_erased (u: universe) (t: term) : term | [] | Pulse.Typing.mk_erased | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | u5: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 22,
"end_line": 30,
"start_col": 44,
"start_line": 28
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tm_bool = tm_fvar (as_fv bool_lid) | let tm_bool = | false | null | false | tm_fvar (as_fv bool_lid) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.bool_lid"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tm_bool : Pulse.Syntax.Base.term | [] | Pulse.Typing.tm_bool | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Pulse.Syntax.Base.term | {
"end_col": 38,
"end_line": 19,
"start_col": 14,
"start_line": 19
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tm_unit = tm_fvar (as_fv unit_lid) | let tm_unit = | false | null | false | tm_fvar (as_fv unit_lid) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.unit_lid"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tm_unit : Pulse.Syntax.Base.term | [] | Pulse.Typing.tm_unit | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Pulse.Syntax.Base.term | {
"end_col": 38,
"end_line": 18,
"start_col": 14,
"start_line": 18
} |
|
Prims.Tot | val bind_comp_ghost_l_compatible (c1 c2: comp_st) : prop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False | val bind_comp_ghost_l_compatible (c1 c2: comp_st) : prop
let bind_comp_ghost_l_compatible (c1 c2: comp_st) : prop = | false | null | false | match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Prims.eq2",
"Prims.l_False",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_ghost_l_compatible (c1 c2: comp_st) : prop | [] | Pulse.Typing.bind_comp_ghost_l_compatible | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st -> Prims.prop | {
"end_col": 19,
"end_line": 241,
"start_col": 4,
"start_line": 239
} |
Prims.Tot | val mk_sq_eq2 (u: universe) (t e0 e1: term) : term | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) | val mk_sq_eq2 (u: universe) (t e0 e1: term) : term
let mk_sq_eq2 (u: universe) (t e0 e1: term) : term = | false | null | false | let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"FStar.Reflection.Const.squash_qn",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Typing.mk_eq2"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_sq_eq2 (u: universe) (t e0 e1: term) : term | [] | Pulse.Typing.mk_sq_eq2 | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
u19: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
e0: Pulse.Syntax.Base.term ->
e1: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | {
"end_col": 59,
"end_line": 55,
"start_col": 3,
"start_line": 54
} |
Prims.Tot | val comp_intro_exists (u: universe) (b: binder) (p e: term) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
} | val comp_intro_exists (u: universe) (b: binder) (p e: term) : comp
let comp_intro_exists (u: universe) (b: binder) (p e: term) : comp = | false | null | false | C_STGhost tm_emp_inames
({ u = u0; res = tm_unit; pre = open_term' p e 0; post = tm_exists_sl u b p }) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_intro_exists (u: universe) (b: binder) (p e: term) : comp | [] | Pulse.Typing.comp_intro_exists | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
u118: Pulse.Syntax.Base.universe ->
b: Pulse.Syntax.Base.binder ->
p: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.comp | {
"end_col": 15,
"end_line": 325,
"start_col": 4,
"start_line": 319
} |
Prims.Tot | val mk_snd (u1 u2: universe) (a1 a2 e: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e | val mk_snd (u1 u2: universe) (a1 a2 e: term) : term
let mk_snd (u1 u2: universe) (a1 a2 e: term) : term = | false | null | false | tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit)
a2)
None
e | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.snd_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.Implicit",
"FStar.Pervasives.Native.None"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_snd (u1 u2: universe) (a1 a2 e: term) : term | [] | Pulse.Typing.mk_snd | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
u1: Pulse.Syntax.Base.universe ->
u2: Pulse.Syntax.Base.universe ->
a1: Pulse.Syntax.Base.term ->
a2: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | {
"end_col": 14,
"end_line": 381,
"start_col": 2,
"start_line": 378
} |
Prims.Tot | val mk_array_length (a arr: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | val mk_array_length (a arr: term) : term
let mk_array_length (a arr: term) : term = | false | null | false | let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.array_length_lid"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_array_length (a arr: term) : term | [] | Pulse.Typing.mk_array_length | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Pulse.Syntax.Base.term -> arr: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 23,
"end_line": 426,
"start_col": 48,
"start_line": 423
} |
Prims.Tot | val comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))) | val comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop
let comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop = | false | null | false | tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Typing.mk_array_pts_to",
"Pulse.Typing.mk_seq_create",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.mk_szv",
"Pulse.Syntax.Base.tm_pure",
"Pulse.Typing.mk_array_is_full",
"Pulse.Typing.mk_eq2",
"Pulse.Typing.tm_nat",
"Pulse.Typing.mk_array_length"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_withlocal_array_body_pre (pre: vprop) (a arr init len: term) : vprop | [] | Pulse.Typing.comp_withlocal_array_body_pre | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
pre: Pulse.Syntax.Base.vprop ->
a: Pulse.Syntax.Base.term ->
arr: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term ->
len: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.vprop | {
"end_col": 95,
"end_line": 454,
"start_col": 2,
"start_line": 451
} |
Prims.Tot | val comp_withlocal_array_body_post (post a arr: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) | val comp_withlocal_array_body_post (post a arr: term) : term
let comp_withlocal_array_body_post (post a arr: term) : term = | false | null | false | tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Pure.u0",
"Pulse.Syntax.Base.as_binder",
"Pulse.Typing.mk_seq",
"Pulse.Typing.mk_array_pts_to",
"Pulse.Syntax.Pure.null_bvar"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_withlocal_array_body_post (post a arr: term) : term | [] | Pulse.Typing.comp_withlocal_array_body_post | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | post: Pulse.Syntax.Base.term -> a: Pulse.Syntax.Base.term -> arr: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | {
"end_col": 96,
"end_line": 461,
"start_col": 2,
"start_line": 461
} |
Prims.Tot | val mk_array (a: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a | val mk_array (a: term) : term
let mk_array (a: term) : term = | false | null | false | tm_pureapp (tm_fvar (as_fv array_lid)) None a | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.array_lid",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_array (a: term) : term | [] | Pulse.Typing.mk_array | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 76,
"end_line": 421,
"start_col": 31,
"start_line": 421
} |
Prims.Tot | val comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
} | val comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp
let comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp = | false | null | false | C_STGhost tm_emp_inames
({
u = u0;
res = tm_unit;
pre = open_term' p (mk_reveal u b.binder_ty e) 0;
post = tm_exists_sl u b p
}) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Pure.u0",
"Pulse.Typing.tm_unit",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Typing.mk_reveal",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_intro_exists_erased (u: universe) (b: binder) (p e: term) : comp | [] | Pulse.Typing.comp_intro_exists_erased | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
u122: Pulse.Syntax.Base.universe ->
b: Pulse.Syntax.Base.binder ->
p: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.comp | {
"end_col": 15,
"end_line": 335,
"start_col": 4,
"start_line": 329
} |
Prims.Tot | val mk_seq (u: universe) (a: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a | val mk_seq (u: universe) (a: term) : term
let mk_seq (u: universe) (a: term) : term = | false | null | false | let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.seq_lid",
"Prims.Cons",
"Prims.Nil"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len))))) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_seq (u: universe) (a: term) : term | [] | Pulse.Typing.mk_seq | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | u183: Pulse.Syntax.Base.universe -> a: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 21,
"end_line": 458,
"start_col": 41,
"start_line": 456
} |
Prims.Tot | val mk_szv (n: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n | val mk_szv (n: term) : term
let mk_szv (n: term) : term = | false | null | false | let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.szv_lid"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_szv (n: term) : term | [] | Pulse.Typing.mk_szv | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | n: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 21,
"end_line": 448,
"start_col": 28,
"start_line": 446
} |
Prims.Tot | val comp_withlocal_body_post (post init_t r: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) | val comp_withlocal_body_post (post init_t r: term) : term
let comp_withlocal_body_post (post init_t r: term) : term = | false | null | false | tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_exists_sl",
"Pulse.Syntax.Pure.u0",
"Pulse.Syntax.Base.as_binder",
"Pulse.Typing.mk_pts_to",
"Pulse.Syntax.Pure.null_bvar"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_withlocal_body_post (post init_t r: term) : term | [] | Pulse.Typing.comp_withlocal_body_post | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | post: Pulse.Syntax.Base.term -> init_t: Pulse.Syntax.Base.term -> r: Pulse.Syntax.Base.term
-> Pulse.Syntax.Base.term | {
"end_col": 86,
"end_line": 410,
"start_col": 2,
"start_line": 410
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t | let tot_typing (g: env) (e t: term) = | false | null | false | typing g e T.E_Total t | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.typing",
"FStar.Stubs.TypeChecker.Core.E_Total"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tot_typing : g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.term -> Type0 | [] | Pulse.Typing.tot_typing | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.term -> Type0 | {
"end_col": 24,
"end_line": 494,
"start_col": 2,
"start_line": 494
} |
|
Prims.Tot | val non_informative_witness_t (u: universe) (t: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t | val non_informative_witness_t (u: universe) (t: term) : term
let non_informative_witness_t (u: universe) (t: term) : term = | false | null | false | tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_uinst",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.non_informative_witness_lid",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val non_informative_witness_t (u: universe) (t: term) : term | [] | Pulse.Typing.non_informative_witness_t | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | u103: Pulse.Syntax.Base.universe -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 16,
"end_line": 288,
"start_col": 4,
"start_line": 286
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t | let ghost_typing (g: env) (e: term) (t: typ) = | false | null | false | typing g e T.E_Ghost t | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.typing",
"FStar.Stubs.TypeChecker.Core.E_Ghost"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_typing : g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.typ -> Type0 | [] | Pulse.Typing.ghost_typing | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> e: Pulse.Syntax.Base.term -> t: Pulse.Syntax.Base.typ -> Type0 | {
"end_col": 24,
"end_line": 497,
"start_col": 2,
"start_line": 497
} |
|
Prims.Tot | val mk_array_is_full (a arr: term) : term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | val mk_array_is_full (a arr: term) : term
let mk_array_is_full (a arr: term) : term = | false | null | false | let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.qualifier",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.Implicit",
"Pulse.Syntax.Pure.tm_fvar",
"Pulse.Syntax.Base.as_fv",
"Pulse.Reflection.Util.array_is_full_lid"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_array_is_full (a arr: term) : term | [] | Pulse.Typing.mk_array_is_full | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Pulse.Syntax.Base.term -> arr: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term | {
"end_col": 23,
"end_line": 438,
"start_col": 49,
"start_line": 435
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tr_bindings = L.map tr_binding | let tr_bindings = | false | null | false | L.map tr_binding | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"FStar.Reflection.V2.Data.binding",
"Pulse.Typing.tr_binding"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tr_bindings : x: Prims.list (Pulse.Syntax.Base.var * Pulse.Syntax.Base.typ)
-> Prims.list FStar.Reflection.V2.Data.binding | [] | Pulse.Typing.tr_bindings | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Prims.list (Pulse.Syntax.Base.var * Pulse.Syntax.Base.typ)
-> Prims.list FStar.Reflection.V2.Data.binding | {
"end_col": 34,
"end_line": 613,
"start_col": 18,
"start_line": 613
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let as_binder t = { binder_ty = t; binder_ppname = ppname_default } | let as_binder t = | false | null | false | { binder_ty = t; binder_ppname = ppname_default } | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.Mkbinder",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Syntax.Base.binder"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val as_binder : t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder | [] | Pulse.Typing.as_binder | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder | {
"end_col": 65,
"end_line": 516,
"start_col": 20,
"start_line": 516
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t) | let prop_validity (g: env) (t: term) = | false | null | false | FTB.prop_validity_token (elab_env g) (elab_term t) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Tactics.V2.Builtins.prop_validity_token",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val prop_validity : g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> Type0 | [] | Pulse.Typing.prop_validity | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> Type0 | {
"end_col": 52,
"end_line": 648,
"start_col": 2,
"start_line": 648
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c)) | let non_informative (g: env) (c: comp) = | false | null | false | my_erased (RT.non_informative (elab_env g) (elab_comp c)) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.comp",
"Pulse.Typing.my_erased",
"FStar.Reflection.Typing.non_informative",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val non_informative : g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp -> Type0 | [] | Pulse.Typing.non_informative | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp -> Type0 | {
"end_col": 59,
"end_line": 663,
"start_col": 2,
"start_line": 663
} |
|
Prims.Tot | val bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s | val bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st
let bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st = | false | null | false | let s:st_comp = { u = comp_u c2; res = comp_res c2; pre = comp_pre c1; post = comp_post c2 } in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.bind_comp_compatible",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Syntax.Base.comp_post"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_out (c1: comp_st) (c2: comp_st{bind_comp_compatible c1 c2}) : comp_st | [] | Pulse.Typing.bind_comp_out | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
c1: Pulse.Syntax.Base.comp_st ->
c2: Pulse.Syntax.Base.comp_st{Pulse.Typing.bind_comp_compatible c1 c2}
-> Pulse.Syntax.Base.comp_st | {
"end_col": 30,
"end_line": 235,
"start_col": 3,
"start_line": 232
} |
Prims.Tot | val comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
} | val comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp
let comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp = | false | null | false | let arr = null_var arr in
C_ST
({
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.comp",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_C_ST",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Typing.comp_withlocal_array_body_pre",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Typing.comp_withlocal_array_body_post",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Pure.null_var"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_withlocal_array_body (arr: var) (a init len: term) (c: comp{C_ST? c}) : comp | [] | Pulse.Typing.comp_withlocal_array_body | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
arr: Pulse.Syntax.Base.var ->
a: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term ->
len: Pulse.Syntax.Base.term ->
c: Pulse.Syntax.Base.comp{C_ST? c}
-> Pulse.Syntax.Base.comp | {
"end_col": 3,
"end_line": 470,
"start_col": 98,
"start_line": 463
} |
Prims.Tot | val add_frame (s: comp_st) (frame: term) : comp_st | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s) | val add_frame (s: comp_st) (frame: term) : comp_st
let add_frame (s: comp_st) (frame: term) : comp_st = | false | null | false | let add_frame_s (s: st_comp) : st_comp =
{ s with pre = tm_star s.pre frame; post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_frame (s: comp_st) (frame: term) : comp_st | [] | Pulse.Typing.add_frame | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Pulse.Syntax.Base.comp_st -> frame: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp_st | {
"end_col": 60,
"end_line": 210,
"start_col": 3,
"start_line": 203
} |
Prims.Tot | val comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
} | val comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp
let comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp = | false | null | false | let r = null_var r in
C_ST
({
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.comp",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_C_ST",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Typing.comp_withlocal_body_pre",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Typing.comp_withlocal_body_post",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Pure.null_var"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_withlocal_body (r: var) (init_t init: term) (c: comp{C_ST? c}) : comp | [] | Pulse.Typing.comp_withlocal_body | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
r: Pulse.Syntax.Base.var ->
init_t: Pulse.Syntax.Base.term ->
init: Pulse.Syntax.Base.term ->
c: Pulse.Syntax.Base.comp{C_ST? c}
-> Pulse.Syntax.Base.comp | {
"end_col": 3,
"end_line": 419,
"start_col": 84,
"start_line": 412
} |
Prims.Tot | val bind_comp_pre (x: var) (c1 c2: comp_st) : prop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2 | val bind_comp_pre (x: var) (c1 c2: comp_st) : prop
let bind_comp_pre (x: var) (c1 c2: comp_st) : prop = | false | null | false | open_term (comp_post c1) x == comp_pre c2 /\ (~(x `Set.mem` (freevars (comp_post c2)))) /\
bind_comp_compatible c1 c2 | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.comp_st",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.open_term",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Base.comp_pre",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Pulse.Syntax.Naming.freevars",
"Pulse.Typing.bind_comp_compatible",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_pre (x: var) (c1 c2: comp_st) : prop | [] | Pulse.Typing.bind_comp_pre | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.var -> c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st
-> Prims.prop | {
"end_col": 30,
"end_line": 228,
"start_col": 4,
"start_line": 226
} |
Prims.Tot | val comp_admit (c: ctag) (s: st_comp) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s | val comp_admit (c: ctag) (s: st_comp) : comp
let comp_admit (c: ctag) (s: st_comp) : comp = | false | null | false | match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.comp"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_admit (c: ctag) (s: st_comp) : comp | [] | Pulse.Typing.comp_admit | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.ctag -> s: Pulse.Syntax.Base.st_comp -> Pulse.Syntax.Base.comp | {
"end_col": 42,
"end_line": 484,
"start_col": 2,
"start_line": 481
} |
Prims.Tot | val wtag (ct: option ctag) (t: st_term') : st_term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } | val wtag (ct: option ctag) (t: st_term') : st_term
let wtag (ct: option ctag) (t: st_term') : st_term = | false | null | false | { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.st_term'",
"Pulse.Syntax.Base.Mkst_term",
"FStar.Range.range_0",
"FStar.Sealed.seal",
"Pulse.Syntax.Base.st_term"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c)) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val wtag (ct: option ctag) (t: st_term') : st_term | [] | Pulse.Typing.wtag | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ct: FStar.Pervasives.Native.option Pulse.Syntax.Base.ctag -> t: Pulse.Syntax.Base.st_term'
-> Pulse.Syntax.Base.st_term | {
"end_col": 126,
"end_line": 591,
"start_col": 54,
"start_line": 591
} |
Prims.Tot | val tr_binding (vt: var & typ) : Tot R.binding | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
} | val tr_binding (vt: var & typ) : Tot R.binding
let tr_binding (vt: var & typ) : Tot R.binding = | false | null | false | let v, t = vt in
{ uniq = v; sort = elab_term t; ppname = ppname_default.name } | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"FStar.Reflection.V2.Data.Mkbinding",
"Pulse.Elaborate.Pure.elab_term",
"Pulse.Syntax.Base.__proj__Mkppname__item__name",
"Pulse.Syntax.Base.ppname_default",
"FStar.Reflection.V2.Data.binding"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tr_binding (vt: var & typ) : Tot R.binding | [] | Pulse.Typing.tr_binding | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | vt: (Pulse.Syntax.Base.var * Pulse.Syntax.Base.typ) -> FStar.Reflection.V2.Data.binding | {
"end_col": 2,
"end_line": 611,
"start_col": 49,
"start_line": 605
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g | let post_hint_for_env_p (g: env) (p: post_hint_t) = | false | null | false | g `env_extends` p.g | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.post_hint_t",
"Pulse.Typing.Env.env_extends",
"Pulse.Typing.__proj__Mkpost_hint_t__item__g",
"Prims.logical"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=(close_comp c x)}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
tot_typing g e t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { ctag=c; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_TotBind:
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
tot_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_GhostBind: // see the comment on T_STGhostApp regarding the non-informative judgment
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
ghost_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
non_informative (push_binding g x ppname_default t1) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
uc:universe ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing g c uc) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing g cL (comp_u cL) ->
comp_typing g cR (comp_u cR) ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder=as_binder (mk_ref init_t); initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder=as_binder (mk_array a); initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
noeq
type post_hint_t = {
g:env;
ctag_hint:option ctag;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val post_hint_for_env_p : g: Pulse.Typing.Env.env -> p: Pulse.Typing.post_hint_t -> Prims.logical | [] | Pulse.Typing.post_hint_for_env_p | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> p: Pulse.Typing.post_hint_t -> Prims.logical | {
"end_col": 69,
"end_line": 1054,
"start_col": 50,
"start_line": 1054
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let post_hint_for_env (g:env) = p:post_hint_t { post_hint_for_env_p g p } | let post_hint_for_env (g: env) = | false | null | false | p: post_hint_t{post_hint_for_env_p g p} | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.post_hint_t",
"Pulse.Typing.post_hint_for_env_p"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=(close_comp c x)}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
tot_typing g e t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { ctag=c; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_TotBind:
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
tot_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_GhostBind: // see the comment on T_STGhostApp regarding the non-informative judgment
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
ghost_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
non_informative (push_binding g x ppname_default t1) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
uc:universe ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing g c uc) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing g cL (comp_u cL) ->
comp_typing g cR (comp_u cR) ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder=as_binder (mk_ref init_t); initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder=as_binder (mk_array a); initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
noeq
type post_hint_t = {
g:env;
ctag_hint:option ctag;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
}
let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
= env_extends_push g x ppname_default b | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val post_hint_for_env : g: Pulse.Typing.Env.env -> Type0 | [] | Pulse.Typing.post_hint_for_env | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> Type0 | {
"end_col": 73,
"end_line": 1063,
"start_col": 32,
"start_line": 1063
} |
|
Prims.Tot | val push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs | val push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs)
let rec push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs) = | false | null | false | match bs with
| [] -> g
| (x, t) :: bs -> push_bindings (push_binding g x ppname_default t) bs | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total",
""
] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Typing.Env.binding",
"Pulse.Typing.all_fresh",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.push_bindings",
"Pulse.Typing.Env.push_binding",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Typing.Env.env_extends"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val push_bindings (g: env) (bs: list binding {all_fresh g bs})
: Tot (g': env{env_extends g' g}) (decreases bs) | [
"recursion"
] | Pulse.Typing.push_bindings | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> bs: Prims.list Pulse.Typing.Env.binding {Pulse.Typing.all_fresh g bs}
-> Prims.Tot (g': Pulse.Typing.Env.env{Pulse.Typing.Env.env_extends g' g}) | {
"end_col": 69,
"end_line": 117,
"start_col": 2,
"start_line": 115
} |
Prims.Tot | val comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | val comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp
let comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp = | false | null | false | let post_maybe_eq =
if use_eq
then
let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post
in
match c with
| STT -> C_ST ({ u = u; res = t; pre = open_term' post e 0; post = post_maybe_eq })
| STT_Atomic ->
C_STAtomic tm_emp_inames ({ u = u; res = t; pre = open_term' post e 0; post = post_maybe_eq })
| STT_Ghost ->
C_STGhost tm_emp_inames ({ u = u; res = t; pre = open_term' post e 0; post = post_maybe_eq }) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.ctag",
"Prims.bool",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.tm_emp_inames",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Naming.close_term",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_pure",
"Pulse.Typing.mk_eq2",
"Pulse.Syntax.Pure.null_var"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_return (c: ctag) (use_eq: bool) (u: universe) (t e post: term) (x: var) : comp | [] | Pulse.Typing.comp_return | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
c: Pulse.Syntax.Base.ctag ->
use_eq: Prims.bool ->
u34: Pulse.Syntax.Base.universe ->
t: Pulse.Syntax.Base.term ->
e: Pulse.Syntax.Base.term ->
post: Pulse.Syntax.Base.term ->
x: Pulse.Syntax.Base.var
-> Pulse.Syntax.Base.comp | {
"end_col": 69,
"end_line": 87,
"start_col": 10,
"start_line": 70
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 | let tm_prop = | false | null | false | with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.with_range",
"Pulse.Syntax.Base.Tm_FStar",
"FStar.Reflection.Typing.tm_prop",
"FStar.Range.range_0"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tm_prop : Pulse.Syntax.Base.term | [] | Pulse.Typing.tm_prop | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Pulse.Syntax.Base.term | {
"end_col": 81,
"end_line": 26,
"start_col": 14,
"start_line": 26
} |
|
Prims.Tot | val all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs | val all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs)
let rec all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs) = | false | null | false | match xs with
| [] -> True
| x :: xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total",
""
] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Typing.Env.binding",
"Prims.l_True",
"Prims.l_and",
"Pulse.Typing.freshv",
"FStar.Pervasives.Native.fst",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.all_fresh",
"Pulse.Typing.Env.push_binding",
"Pulse.Syntax.Base.ppname_default",
"FStar.Pervasives.Native.snd",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val all_fresh (g: env) (xs: list binding) : Tot prop (decreases xs) | [
"recursion"
] | Pulse.Typing.all_fresh | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> xs: Prims.list Pulse.Typing.Env.binding -> Prims.Tot Prims.prop | {
"end_col": 93,
"end_line": 112,
"start_col": 2,
"start_line": 110
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_post_matches_hint (c:comp_st) (post_hint:option post_hint_t) =
match post_hint with
| None -> True
| Some post_hint ->
comp_res c == post_hint.ret_ty /\
comp_u c == post_hint.u /\
comp_post c == post_hint.post | let comp_post_matches_hint (c: comp_st) (post_hint: option post_hint_t) = | false | null | false | match post_hint with
| None -> True
| Some post_hint ->
comp_res c == post_hint.ret_ty /\ comp_u c == post_hint.u /\ comp_post c == post_hint.post | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"FStar.Pervasives.Native.option",
"Pulse.Typing.post_hint_t",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.comp_res",
"Pulse.Typing.__proj__Mkpost_hint_t__item__ret_ty",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.comp_u",
"Pulse.Typing.__proj__Mkpost_hint_t__item__u",
"Pulse.Syntax.Base.comp_post",
"Pulse.Typing.__proj__Mkpost_hint_t__item__post",
"Prims.logical"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=(close_comp c x)}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
tot_typing g e t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { ctag=c; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_TotBind:
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
tot_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_GhostBind: // see the comment on T_STGhostApp regarding the non-informative judgment
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
ghost_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
non_informative (push_binding g x ppname_default t1) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
uc:universe ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing g c uc) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing g cL (comp_u cL) ->
comp_typing g cR (comp_u cR) ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder=as_binder (mk_ref init_t); initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder=as_binder (mk_array a); initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
noeq
type post_hint_t = {
g:env;
ctag_hint:option ctag;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
}
let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
= env_extends_push g x ppname_default b
let post_hint_for_env (g:env) = p:post_hint_t { post_hint_for_env_p g p }
let post_hint_opt (g:env) = o:option post_hint_t { None? o \/ post_hint_for_env_p g (Some?.v o) }
noeq
type post_hint_typing_t (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) = {
ty_typing:universe_of g p.ret_ty p.u;
post_typing:tot_typing (push_binding g x ppname_default p.ret_ty) (open_term p.post x) tm_vprop
}
let fresh_wrt (x:var) (g:env) (vars:_) =
None? (lookup g x) /\ ~(x `Set.mem` vars)
let post_hint_typing (g:env)
(p:post_hint_for_env g)
(x:var { fresh_wrt x g (freevars p.post) })
: post_hint_typing_t g p x =
{
ty_typing = magic ();
post_typing = magic ();
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_post_matches_hint : c: Pulse.Syntax.Base.comp_st -> post_hint: FStar.Pervasives.Native.option Pulse.Typing.post_hint_t
-> Prims.logical | [] | Pulse.Typing.comp_post_matches_hint | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp_st -> post_hint: FStar.Pervasives.Native.option Pulse.Typing.post_hint_t
-> Prims.logical | {
"end_col": 33,
"end_line": 1091,
"start_col": 2,
"start_line": 1086
} |
|
Prims.Tot | val bind_comp_ghost_l_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_l_compatible c1 c2}) : comp_st | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s | val bind_comp_ghost_l_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_l_compatible c1 c2}) : comp_st
let bind_comp_ghost_l_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_l_compatible c1 c2}) : comp_st = | false | null | false | let s:st_comp = { u = comp_u c2; res = comp_res c2; pre = comp_pre c1; post = comp_post c2 } in
match c1, c2 with | C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.bind_comp_ghost_l_compatible",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Syntax.Base.comp_post"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2}) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_ghost_l_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_l_compatible c1 c2}) : comp_st | [] | Pulse.Typing.bind_comp_ghost_l_out | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
c1: Pulse.Syntax.Base.comp_st ->
c2: Pulse.Syntax.Base.comp_st{Pulse.Typing.bind_comp_ghost_l_compatible c1 c2}
-> Pulse.Syntax.Base.comp_st | {
"end_col": 63,
"end_line": 253,
"start_col": 3,
"start_line": 251
} |
Prims.Tot | val bind_comp_ghost_l_pre (x: var) (c1 c2: comp_st) : prop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2 | val bind_comp_ghost_l_pre (x: var) (c1 c2: comp_st) : prop
let bind_comp_ghost_l_pre (x: var) (c1 c2: comp_st) : prop = | false | null | false | open_term (comp_post c1) x == comp_pre c2 /\ (~(x `Set.mem` (freevars (comp_post c2)))) /\
bind_comp_ghost_l_compatible c1 c2 | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.comp_st",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.open_term",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Base.comp_pre",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Pulse.Syntax.Naming.freevars",
"Pulse.Typing.bind_comp_ghost_l_compatible",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_ghost_l_pre (x: var) (c1 c2: comp_st) : prop | [] | Pulse.Typing.bind_comp_ghost_l_pre | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.var -> c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st
-> Prims.prop | {
"end_col": 38,
"end_line": 247,
"start_col": 4,
"start_line": 245
} |
Prims.Tot | val st_equiv_pre (c1 c2: comp_st) : prop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False) | val st_equiv_pre (c1 c2: comp_st) : prop
let st_equiv_pre (c1 c2: comp_st) : prop = | false | null | false | comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.comp_u",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.st_comp",
"Prims.l_True",
"Pulse.Syntax.Base.term",
"Prims.l_False",
"Prims.logical",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val st_equiv_pre (c1 c2: comp_st) : prop | [] | Pulse.Typing.st_equiv_pre | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st -> Prims.prop | {
"end_col": 20,
"end_line": 282,
"start_col": 4,
"start_line": 275
} |
Prims.Tot | val bind_comp_ghost_r_pre (x: var) (c1 c2: comp_st) : prop | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2 | val bind_comp_ghost_r_pre (x: var) (c1 c2: comp_st) : prop
let bind_comp_ghost_r_pre (x: var) (c1 c2: comp_st) : prop = | false | null | false | open_term (comp_post c1) x == comp_pre c2 /\ (~(x `Set.mem` (freevars (comp_post c2)))) /\
bind_comp_ghost_r_compatible c1 c2 | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.comp_st",
"Prims.l_and",
"Prims.eq2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.open_term",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Base.comp_pre",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Pulse.Syntax.Naming.freevars",
"Pulse.Typing.bind_comp_ghost_r_compatible",
"Prims.prop"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_ghost_r_pre (x: var) (c1 c2: comp_st) : prop | [] | Pulse.Typing.bind_comp_ghost_r_pre | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.var -> c1: Pulse.Syntax.Base.comp_st -> c2: Pulse.Syntax.Base.comp_st
-> Prims.prop | {
"end_col": 38,
"end_line": 265,
"start_col": 4,
"start_line": 263
} |
Prims.Tot | val bind_comp_ghost_r_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_r_compatible c1 c2}) : comp_st | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s | val bind_comp_ghost_r_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_r_compatible c1 c2}) : comp_st
let bind_comp_ghost_r_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_r_compatible c1 c2}) : comp_st = | false | null | false | let s:st_comp = { u = comp_u c2; res = comp_res c2; pre = comp_pre c1; post = comp_post c2 } in
match c1, c2 with | C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.bind_comp_ghost_r_compatible",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Syntax.Base.comp_post"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2}) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bind_comp_ghost_r_out (c1: comp_st) (c2: comp_st{bind_comp_ghost_r_compatible c1 c2}) : comp_st | [] | Pulse.Typing.bind_comp_ghost_r_out | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
c1: Pulse.Syntax.Base.comp_st ->
c2: Pulse.Syntax.Base.comp_st{Pulse.Typing.bind_comp_ghost_r_compatible c1 c2}
-> Pulse.Syntax.Base.comp_st | {
"end_col": 63,
"end_line": 271,
"start_col": 3,
"start_line": 269
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fresh_wrt (x:var) (g:env) (vars:_) =
None? (lookup g x) /\ ~(x `Set.mem` vars) | let fresh_wrt (x: var) (g: env) (vars: _) = | false | null | false | None? (lookup g x) /\ ~(x `Set.mem` vars) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.var",
"Pulse.Typing.Env.env",
"FStar.Set.set",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_None",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.Env.lookup",
"Prims.l_not",
"FStar.Set.mem",
"Prims.logical"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=(close_comp c x)}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
tot_typing g e t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { ctag=c; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_TotBind:
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
tot_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_GhostBind: // see the comment on T_STGhostApp regarding the non-informative judgment
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
ghost_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
non_informative (push_binding g x ppname_default t1) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
uc:universe ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing g c uc) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing g cL (comp_u cL) ->
comp_typing g cR (comp_u cR) ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder=as_binder (mk_ref init_t); initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder=as_binder (mk_array a); initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
noeq
type post_hint_t = {
g:env;
ctag_hint:option ctag;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
}
let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
= env_extends_push g x ppname_default b
let post_hint_for_env (g:env) = p:post_hint_t { post_hint_for_env_p g p }
let post_hint_opt (g:env) = o:option post_hint_t { None? o \/ post_hint_for_env_p g (Some?.v o) }
noeq
type post_hint_typing_t (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) = {
ty_typing:universe_of g p.ret_ty p.u;
post_typing:tot_typing (push_binding g x ppname_default p.ret_ty) (open_term p.post x) tm_vprop
} | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fresh_wrt : x: Pulse.Syntax.Base.var -> g: Pulse.Typing.Env.env -> vars: FStar.Set.set Pulse.Syntax.Base.var
-> Prims.logical | [] | Pulse.Typing.fresh_wrt | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Pulse.Syntax.Base.var -> g: Pulse.Typing.Env.env -> vars: FStar.Set.set Pulse.Syntax.Base.var
-> Prims.logical | {
"end_col": 46,
"end_line": 1073,
"start_col": 4,
"start_line": 1073
} |
|
Prims.Tot | val comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
} | val comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp
let comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp = | false | null | false | let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST
({ u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post = post }) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_C_ST",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Typing.mk_tuple2",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Syntax.Base.term",
"Pulse.Typing.par_post",
"Pulse.Syntax.Base.comp_post",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.comp_u"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val comp_par (cL: comp{C_ST? cL}) (cR: comp{C_ST? cR}) (x: var) : comp | [] | Pulse.Typing.comp_par | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
cL: Pulse.Syntax.Base.comp{C_ST? cL} ->
cR: Pulse.Syntax.Base.comp{C_ST? cR} ->
x: Pulse.Syntax.Base.var
-> Pulse.Syntax.Base.comp | {
"end_col": 3,
"end_line": 404,
"start_col": 69,
"start_line": 391
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c) | let non_informative_c (g: env) (c: comp_st) = | false | null | false | non_informative_t g (comp_u c) (comp_res c) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.non_informative_t",
"Pulse.Syntax.Base.comp_u",
"Pulse.Syntax.Base.comp_res"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val non_informative_c : g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0 | [] | Pulse.Typing.non_informative_c | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0 | {
"end_col": 45,
"end_line": 514,
"start_col": 2,
"start_line": 514
} |
|
Prims.Tot | val lift_typing_to_ghost_typing
(#g: env)
(#e: term)
(#eff: T.tot_or_ghost)
(#t: term)
(d: typing g e eff t)
: ghost_typing g e t | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) | val lift_typing_to_ghost_typing
(#g: env)
(#e: term)
(#eff: T.tot_or_ghost)
(#t: term)
(d: typing g e eff t)
: ghost_typing g e t
let lift_typing_to_ghost_typing
(#g: env)
(#e: term)
(#eff: T.tot_or_ghost)
(#t: term)
(d: typing g e eff t)
: ghost_typing g e t = | false | null | false | if eff = T.E_Ghost
then d
else
let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"Pulse.Typing.typing",
"Prims.op_Equality",
"FStar.Stubs.TypeChecker.Core.E_Ghost",
"Prims.bool",
"FStar.Reflection.Typing.typing",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.Types.typ",
"Pulse.Typing.E",
"FStar.Reflection.Typing.T_Sub",
"FStar.Reflection.Typing.Relc_total_ghost",
"Pulse.Typing.ghost_typing"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lift_typing_to_ghost_typing
(#g: env)
(#e: term)
(#eff: T.tot_or_ghost)
(#t: term)
(d: typing g e eff t)
: ghost_typing g e t | [] | Pulse.Typing.lift_typing_to_ghost_typing | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | d: Pulse.Typing.typing g e eff t -> Pulse.Typing.ghost_typing g e t | {
"end_col": 55,
"end_line": 505,
"start_col": 2,
"start_line": 502
} |
Prims.Tot | val wr (ct: comp_st) (t: st_term') : st_term | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } | val wr (ct: comp_st) (t: st_term') : st_term
let wr (ct: comp_st) (t: st_term') : st_term = | false | null | false | { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Syntax.Base.st_term'",
"Pulse.Syntax.Base.Mkst_term",
"FStar.Range.range_0",
"Pulse.Syntax.Base.as_effect_hint",
"Pulse.Syntax.Base.ctag_of_comp_st",
"Pulse.Syntax.Base.st_term"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c)) | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val wr (ct: comp_st) (t: st_term') : st_term | [] | Pulse.Typing.wr | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ct: Pulse.Syntax.Base.comp_st -> t: Pulse.Syntax.Base.st_term' -> Pulse.Syntax.Base.st_term | {
"end_col": 134,
"end_line": 590,
"start_col": 47,
"start_line": 590
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let post_hint_opt (g:env) = o:option post_hint_t { None? o \/ post_hint_for_env_p g (Some?.v o) } | let post_hint_opt (g: env) = | false | null | false | o: option post_hint_t {None? o \/ post_hint_for_env_p g (Some?.v o)} | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"total"
] | [
"Pulse.Typing.Env.env",
"FStar.Pervasives.Native.option",
"Pulse.Typing.post_hint_t",
"Prims.l_or",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_None",
"Pulse.Typing.post_hint_for_env_p",
"FStar.Pervasives.Native.__proj__Some__item__v"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=(close_comp c x)}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
tot_typing g e t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { ctag=c; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_TotBind:
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
tot_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_GhostBind: // see the comment on T_STGhostApp regarding the non-informative judgment
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
ghost_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
non_informative (push_binding g x ppname_default t1) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
uc:universe ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing g c uc) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing g cL (comp_u cL) ->
comp_typing g cR (comp_u cR) ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder=as_binder (mk_ref init_t); initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder=as_binder (mk_array a); initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
noeq
type post_hint_t = {
g:env;
ctag_hint:option ctag;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
}
let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
= env_extends_push g x ppname_default b | false | true | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val post_hint_opt : g: Pulse.Typing.Env.env -> Type0 | [] | Pulse.Typing.post_hint_opt | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | g: Pulse.Typing.Env.env -> Type0 | {
"end_col": 97,
"end_line": 1064,
"start_col": 28,
"start_line": 1064
} |
|
FStar.Pervasives.Lemma | val post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ)
: Lemma (requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "FTB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
= env_extends_push g x ppname_default b | val post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ)
: Lemma (requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
let post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ)
: Lemma (requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] = | false | null | true | env_extends_push g x ppname_default b | {
"checked_file": "Pulse.Typing.fst.checked",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Sealed.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.fst"
} | [
"lemma"
] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.post_hint_t",
"Pulse.Syntax.Base.var",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Pulse.Typing.Env.dom",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.Env.env_extends_push",
"Pulse.Syntax.Base.ppname_default",
"Prims.unit",
"Pulse.Typing.post_hint_for_env_p",
"Prims.squash",
"Pulse.Typing.Env.push_binding",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil"
] | [] | module Pulse.Typing
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
open Pulse.Reflection.Util
open FStar.List.Tot
open Pulse.Syntax
module L = FStar.List.Tot
module FTB = FStar.Tactics.V2
module RU = Pulse.RuntimeUtils
module T= FStar.Tactics.V2
include Pulse.Typing.Env
let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) level
then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ()))
let tm_unit = tm_fvar (as_fv unit_lid)
let tm_bool = tm_fvar (as_fv bool_lid)
let tm_int = tm_fvar (as_fv int_lid)
let tm_nat = tm_fvar (as_fv nat_lid)
let tm_szt = tm_fvar (as_fv szt_lid)
let tm_true = tm_constant R.C_True
let tm_false = tm_constant R.C_False
let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0
let mk_erased (u:universe) (t:term) : term =
let hd = tm_uinst (as_fv erased_lid) [u] in
tm_pureapp hd None t
let mk_reveal (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv reveal_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_hide (u:universe) (t:term) (e:term) : term =
let hd = tm_uinst (as_fv hide_lid) [u] in
let hd = tm_pureapp hd (Some Implicit) t in
tm_pureapp hd None e
let mk_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= tm_pureapp
(tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t)
None e0) None e1
let mk_sq_eq2 (u:universe)
(t:term)
(e0 e1:term)
: term
= let eq = mk_eq2 u t e0 e1 in
(tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq)
let mk_vprop_eq (e0 e1:term) : term =
mk_eq2 u2 tm_vprop e0 e1
let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t
let mk_pts_to (ty:term) (r:term) (v:term) : term =
let t = tm_fvar (as_fv pts_to_lid) in
let t = tm_pureapp t (Some Implicit) ty in
let t = tm_pureapp t None r in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var)
: comp =
let post_maybe_eq =
if use_eq
then let post = open_term' post (null_var x) 0 in
let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in
close_term post x
else post in
match c with
| STT ->
C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Atomic ->
C_STAtomic tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
| STT_Ghost ->
C_STGhost tm_emp_inames
{ u; res = t; pre = open_term' post e 0; post = post_maybe_eq }
module L = FStar.List.Tot
let extend_env_l (f:R.env) (g:env_bindings) : R.env =
L.fold_right
(fun (x, b) g ->
let t = elab_term b in
RT.extend_env g x t)
g
f
let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e)
(*
* If I call this fresh, I get:
* Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers
* What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*...
*)
let freshv (g:env) (x:var) : prop =
None? (lookup g x)
let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) =
match xs with
| [] -> True
| x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs
let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) =
match bs with
| [] -> g
| (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs
let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ)
: Lemma (elab_env (push_binding g x ppname_default t) ==
RT.extend_env (elab_env g) x (elab_term t)) = ()
[@@ erasable; no_auto_projectors]
noeq
type vprop_equiv : env -> term -> term -> Type =
| VE_Refl:
g:env ->
t:term ->
vprop_equiv g t t
| VE_Sym:
g:env ->
t1:term ->
t2:term ->
vprop_equiv g t1 t2 ->
vprop_equiv g t2 t1
| VE_Trans:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g t0 t1 ->
vprop_equiv g t1 t2 ->
vprop_equiv g t0 t2
| VE_Ctxt:
g:env ->
t0:term ->
t1:term ->
t0':term ->
t1':term ->
vprop_equiv g t0 t0' ->
vprop_equiv g t1 t1' ->
vprop_equiv g (tm_star t0 t1) (tm_star t0' t1')
| VE_Unit: (* *)
g:env ->
t:term ->
vprop_equiv g (tm_star tm_emp t) t
| VE_Comm:
g:env ->
t0:term ->
t1:term ->
vprop_equiv g (tm_star t0 t1) (tm_star t1 t0)
| VE_Assoc:
g:env ->
t0:term ->
t1:term ->
t2:term ->
vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2)
| VE_Ext:
g:env ->
t0:term ->
t1:term ->
FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) ->
vprop_equiv g t0 t1
// | VE_Ex:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1)
// | VE_Fa:
// g:env ->
// x:var { None? (lookup_ty g x) } ->
// ty:term ->
// t0:term ->
// t1:term ->
// vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) ->
// vprop_equiv f g (Tm_ForallSL ty t0) (Tm_ForallSL ty t1)
let add_frame (s:comp_st) (frame:term)
: comp_st
= let add_frame_s (s:st_comp) : st_comp =
{ s with pre = tm_star s.pre frame;
post = tm_star s.post frame }
in
match s with
| C_ST s -> C_ST (add_frame_s s)
| C_STAtomic inames s -> C_STAtomic inames (add_frame_s s)
| C_STGhost inames s -> C_STGhost inames (add_frame_s s)
//
// TODO: there is a observability flag upcoming in the underlying steel framework
// the bind will then also allow for (statomic unobservable, statomic observable)
// and the symmetric one
//
let bind_comp_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| C_ST _, C_ST _ -> True
| _, _ -> False
let bind_comp_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_compatible c1 c2
let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STGhost _ _ -> C_STGhost inames s
| C_ST _, C_ST _ -> C_ST s
let bind_comp_ghost_l_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STGhost inames1 _, C_STAtomic inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_l_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_l_compatible c1 c2
let bind_comp_ghost_l_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_l_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STGhost inames _, C_STAtomic _ _ -> C_STAtomic inames s
let bind_comp_ghost_r_compatible (c1 c2:comp_st)
: prop
= match c1, c2 with
| C_STAtomic inames1 _, C_STGhost inames2 _ -> inames1 == inames2
| _, _ -> False
let bind_comp_ghost_r_pre (x:var) (c1 c2:comp_st)
: prop
= open_term (comp_post c1) x == comp_pre c2 /\
(~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type
bind_comp_ghost_r_compatible c1 c2
let bind_comp_ghost_r_out (c1:comp_st) (c2:comp_st{bind_comp_ghost_r_compatible c1 c2})
: comp_st
= let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in
match c1, c2 with
| C_STAtomic inames _, C_STGhost _ _ -> C_STAtomic inames s
let st_equiv_pre (c1 c2:comp_st)
: prop
= comp_u c1 == comp_u c2 /\
(match c1, c2 with
| C_ST _, C_ST _ -> True
| C_STAtomic inames1 _, C_STAtomic inames2 _ ->
inames1 == inames2
| C_STGhost inames1 _, C_STGhost inames2 _ ->
inames1 == inames2
| _, _ -> False)
let non_informative_witness_t (u:universe) (t:term)
: term
= tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u])
None
t
let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar)
: term
= let x_tm = term_of_nvar x in
let p = open_term' p (mk_reveal u t x_tm) 0 in
close_term p (snd x)
let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar)
: comp
= C_STGhost tm_emp_inames
{
u=u;
res=mk_erased u t;
pre=tm_exists_sl u (as_binder t) p;
post=elim_exists_post u t p x
}
let comp_intro_pure (p:term) =
C_STGhost tm_emp_inames
{
u=u_zero;
res=tm_unit;
pre=tm_emp;
post=tm_pure p
}
let named_binder (x:ppname) (t:term) = { binder_ppname = x; binder_ty = t}
let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p e 0;
post=tm_exists_sl u b p
}
let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term)
: comp
= C_STGhost tm_emp_inames
{
u=u0;
res=tm_unit;
pre=open_term' p (mk_reveal u b.binder_ty e) 0;
post=tm_exists_sl u b p
}
let comp_while_cond (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_bool;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=inv
}
let comp_while_body (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=open_term' inv tm_true 0;
post=tm_exists_sl u0 (named_binder x tm_bool) inv
}
let comp_while (x:ppname) (inv:term)
: comp
= C_ST {
u=u0;
res=tm_unit;
pre=tm_exists_sl u0 (named_binder x tm_bool) inv;
post=open_term' inv tm_false 0
}
let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term =
tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2])
None
t1)
None t2
let mk_fst (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let mk_snd (u1 u2:universe) (a1 a2 e:term) : term =
tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1)
(Some Implicit) a2)
None
e
let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term =
let x_tm = term_of_no_name_var x in
let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in
let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in
let post = tm_star postL postR in
close_term post x
let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp =
let uL = comp_u cL in
let uR = comp_u cR in
let aL = comp_res cL in
let aR = comp_res cR in
let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in
C_ST {
u = uL;
res = mk_tuple2 uL uR aL aR;
pre = tm_star (comp_pre cL) (comp_pre cR);
post
}
let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop =
tm_star pre (mk_pts_to init_t r init)
let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term =
tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0)))
let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp =
let r = null_var r in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_body_pre (comp_pre c) init_t r init;
post = comp_withlocal_body_post (comp_post c) init_t r
}
let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a
let mk_array_length (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_length_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_array_pts_to (a:term) (arr:term) (v:term) : term =
let t = tm_fvar (as_fv array_pts_to_lid) in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None arr in
let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in
tm_pureapp t None v
let mk_array_is_full (a:term) (arr:term) : term =
let t = tm_fvar (as_fv array_is_full_lid) in
let t = tm_pureapp t (Some Implicit) a in
tm_pureapp t None arr
let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term =
let t = tm_uinst (as_fv seq_create_lid) [u] in
let t = tm_pureapp t (Some Implicit) a in
let t = tm_pureapp t None len in
tm_pureapp t None v
let mk_szv (n:term) : term =
let t = tm_fvar (as_fv szv_lid) in
tm_pureapp t None n
let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop =
tm_star pre
(tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init))
(tm_star (tm_pure (mk_array_is_full a arr))
(tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))))
let mk_seq (u:universe) (a:term) : term =
let t = tm_uinst (as_fv seq_lid) [u] in
tm_pureapp t None a
let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term =
tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0)))
let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp =
let arr = null_var arr in
C_ST {
u = comp_u c;
res = comp_res c;
pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len;
post = comp_withlocal_array_body_post (comp_post c) a arr
}
let comp_rewrite (p q:vprop) : comp =
C_STGhost tm_emp_inames {
u = u0;
res = tm_unit;
pre = p;
post = q;
}
let comp_admit (c:ctag) (s:st_comp) : comp =
match c with
| STT -> C_ST s
| STT_Atomic -> C_STAtomic tm_emp_inames s
| STT_Ghost -> C_STGhost tm_emp_inames s
[@@erasable]
noeq
type my_erased (a:Type) = | E of a
let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) =
my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t))
let tot_typing (g:env) (e:term) (t:term) =
typing g e T.E_Total t
let ghost_typing (g:env) (e:term) (t:typ) =
typing g e T.E_Ghost t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term)
(d:typing g e eff t)
: ghost_typing g e t =
if eff = T.E_Ghost
then d
else let E d = d in
E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
let universe_of (g:env) (t:term) (u:universe) =
tot_typing g t (tm_type u)
let non_informative_t (g:env) (u:universe) (t:term) =
w:term & tot_typing g w (non_informative_witness_t u t)
let non_informative_c (g:env) (c:comp_st) =
non_informative_t g (comp_u c) (comp_res c)
let as_binder t = { binder_ty = t; binder_ppname = ppname_default }
[@@ no_auto_projectors]
noeq
type st_equiv : env -> comp -> comp -> Type =
| ST_VPropEquiv :
g:env ->
c1:comp_st ->
c2:comp_st { st_equiv_pre c1 c2 } ->
x:var { None? (lookup g x) /\
~(x `Set.mem` freevars (comp_post c1)) /\
~(x `Set.mem` freevars (comp_post c2)) } ->
tot_typing g (comp_pre c1) tm_vprop ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) ->
tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop ->
RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) ->
vprop_equiv g (comp_pre c1) (comp_pre c2) ->
vprop_equiv (push_binding g x ppname_default (comp_res c1))
(open_term (comp_post c1) x)
(open_term (comp_post c2) x) ->
st_equiv g c1 c2
[@@ no_auto_projectors]
noeq
type bind_comp : env -> var -> comp -> comp -> comp -> Type =
| Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_pre x c1 c2} ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_out c1 c2)
| Bind_comp_ghost_l : // (C_STGhost and C_STAtomic)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_l_pre x c1 c2} ->
non_informative_c1:non_informative_c g c1 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_l_out c1 c2)
| Bind_comp_ghost_r : // (C_STAtomic and C_STGhost)
g:env ->
x:var { None? (lookup g x) } ->
c1:comp_st ->
c2:comp_st {bind_comp_ghost_r_pre x c1 c2} ->
non_informative_c2:non_informative_c g c2 ->
universe_of g (comp_res c2) (comp_u c2) ->
//or in the result post; free var check isn't enough; we need typability
y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } ->
tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop ->
bind_comp g x c1 c2 (bind_comp_ghost_r_out c1 c2)
[@@ no_auto_projectors]
noeq
type lift_comp : env -> comp -> comp -> Type =
| Lift_STAtomic_ST :
g:env ->
c:comp_st{C_STAtomic? c /\ comp_inames c == tm_emp_inames} ->
lift_comp g c (C_ST (st_comp_of_comp c))
| Lift_STGhost_STAtomic :
g:env ->
c:comp_st{C_STGhost? c} ->
non_informative_c:non_informative_c g c ->
lift_comp g c (C_STAtomic (comp_inames c) (st_comp_of_comp c))
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
[@@ no_auto_projectors]
noeq
type st_comp_typing : env -> st_comp -> Type =
| STC:
g:env ->
st:st_comp ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } ->
universe_of g st.res st.u ->
tot_typing g st.pre tm_vprop ->
tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop ->
st_comp_typing g st
let tr_binding (vt : var & typ) : Tot R.binding =
let v, t = vt in
{
uniq = v;
sort = elab_term t;
ppname = ppname_default.name;
}
let tr_bindings = L.map tr_binding
[@@ no_auto_projectors]
noeq
type comp_typing : env -> comp -> universe -> Type =
| CT_Tot :
g:env ->
t:term ->
u:universe ->
universe_of g t u ->
comp_typing g (C_Tot t) u
| CT_ST :
g:env ->
st:st_comp ->
st_comp_typing g st ->
comp_typing g (C_ST st) st.u
| CT_STAtomic :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STAtomic inames st) st.u
| CT_STGhost :
g:env ->
inames:term ->
st:st_comp ->
tot_typing g inames tm_inames ->
st_comp_typing g st ->
comp_typing g (C_STGhost inames st) st.u
let prop_validity (g:env) (t:term) =
FTB.prop_validity_token (elab_env g) (elab_term t)
let subtyping_token g t1 t2 =
T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2)
val readback_binding : R.binding -> binding
let readback_binding b =
assume (host_term == R.term); // fixme! expose this fact
match readback_ty b.sort with
| Some sort -> (b.uniq, sort)
| None ->
let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in
(b.uniq, sort)
let non_informative (g:env) (c:comp) =
my_erased (RT.non_informative (elab_env g) (elab_comp c))
[@@ no_auto_projectors]
noeq
type st_typing : env -> st_term -> comp -> Type =
| T_Abs:
g:env ->
x:var { None? (lookup g x) } ->
q:option qualifier ->
b:binder ->
u:universe ->
body:st_term {~ (x `Set.mem` freevars_st body) } ->
c:comp ->
tot_typing g b.binder_ty (tm_type u) ->
st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c ->
st_typing g (wtag None (Tm_Abs { b; q; body; ascription=(close_comp c x)}))
(C_Tot (tm_arrow b q (close_comp c x)))
| T_STApp :
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
tot_typing g head (tm_arrow (as_binder ty) q res) ->
tot_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
//
// this rule requires a non-informative judgment
// for C_STGhost, this will always be the case
// however, when doing the soundness proof,
// we cannot call into the reflection API to get the token
// may be there is another way to make it so that we can get this once-and-for-all
// for C_STGhost
//
| T_STGhostApp:
g:env ->
head:term ->
ty:term ->
q:option qualifier ->
res:comp_st ->
arg:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } ->
ghost_typing g head (tm_arrow (as_binder ty) q res) ->
non_informative (push_binding g x ppname_default ty)
(open_comp_with res (null_var x)) ->
ghost_typing g arg ty ->
st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg}))
(open_comp_with res arg)
| T_Return:
g:env ->
c:ctag ->
use_eq:bool ->
u:universe ->
t:term ->
e:term ->
post:term ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } ->
universe_of g t u ->
tot_typing g e t ->
tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop ->
st_typing g (wtag (Some c) (Tm_Return { ctag=c; insert_eq=use_eq; term=e }))
(comp_return c use_eq u t e post x)
| T_Lift:
g:env ->
e:st_term ->
c1:comp_st ->
c2:comp_st ->
st_typing g e c1 ->
lift_comp g c1 c2 ->
st_typing g e c2
| T_Bind:
g:env ->
e1:st_term ->
e2:st_term ->
c1:comp_st ->
c2:comp_st ->
b:binder { b.binder_ty == comp_res c1 }->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } ->
c:comp ->
st_typing g e1 c1 ->
tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead
st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 ->
bind_comp g x c1 c2 c ->
st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c
| T_TotBind:
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
tot_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_GhostBind: // see the comment on T_STGhostApp regarding the non-informative judgment
g:env ->
e1:term ->
e2:st_term ->
t1:term ->
c2:comp_st ->
b:binder { b.binder_ty == t1 } ->
x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_st e2) } ->
ghost_typing g e1 t1 ->
st_typing (push_binding g x ppname_default t1) (open_st_term_nv e2 (v_as_nv x)) c2 ->
non_informative (push_binding g x ppname_default t1) c2 ->
st_typing g (wr c2 (Tm_TotBind { binder = b; head = e1; body = e2 }))
(open_comp_with (close_comp c2 x) e1)
| T_If:
g:env ->
b:term ->
e1:st_term ->
e2:st_term ->
c:comp_st ->
uc:universe ->
(* This is a little weird, we introduce a name hyp in the environment,
but the branches are not allowed to use it (except perhaps in a silent way for proofs).
Maybe more natural to have one free var in e1,e2 and to open it with hyp?
But that's also a change to FStar.Reflection.Typing
*)
hyp:var { None? (lookup g hyp) /\
~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2))
} ->
tot_typing g b tm_bool ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c ->
st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c ->
my_erased (comp_typing g c uc) ->
st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c
| T_Match :
g:env ->
sc_u:universe ->
sc_ty:typ ->
sc:term ->
tot_typing g sc_ty (tm_type sc_u) ->
tot_typing g sc sc_ty ->
c:comp_st ->
brs:list (pattern & st_term) ->
brs_typing g sc_u sc_ty sc brs c ->
pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) ->
st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c
| T_Frame:
g:env ->
e:st_term ->
c:comp_st ->
frame:term ->
tot_typing g frame tm_vprop ->
st_typing g e c ->
st_typing g e (add_frame c frame)
| T_Equiv:
g:env ->
e:st_term ->
c:comp ->
c':comp ->
st_typing g e c ->
st_equiv g c c' ->
st_typing g e c'
| T_IntroPure:
g:env ->
p:term ->
tot_typing g p tm_prop ->
prop_validity g p ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p }))
(comp_intro_pure p)
| T_ElimExists:
g:env ->
u:universe ->
t:term ->
p:term ->
x:var { None? (lookup g x) } ->
tot_typing g t (tm_type u) ->
tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop ->
st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p }))
(comp_elim_exists u t p (v_as_nv x))
| T_IntroExists:
g:env ->
u:universe ->
b:binder ->
p:term ->
e:term ->
tot_typing g b.binder_ty (tm_type u) ->
tot_typing g (tm_exists_sl u b p) tm_vprop ->
ghost_typing g e b.binder_ty ->
st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p;
witnesses= [e] }))
(comp_intro_exists u b p e)
| T_While:
g:env ->
inv:term ->
cond:st_term ->
body:st_term ->
tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop ->
st_typing g cond (comp_while_cond ppname_default inv) ->
st_typing g body (comp_while_body ppname_default inv) ->
st_typing g (wtag (Some STT) (Tm_While { invariant = inv;
condition = cond;
body;
condition_var = ppname_default } ))
(comp_while ppname_default inv)
| T_Par:
g:env ->
eL:st_term ->
cL:comp { C_ST? cL } ->
eR:st_term ->
cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } ->
x:var { None? (lookup g x) } ->
// TODO: can comp_typing come from inversion of eL : cL and eR : cR?
comp_typing g cL (comp_u cL) ->
comp_typing g cR (comp_u cR) ->
st_typing g eL cL ->
st_typing g eR cR ->
st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown;
pre2=tm_unknown; body2=eR; post2=tm_unknown }))
(comp_par cL cR x)
| T_WithLocal:
g:env ->
init:term ->
body:st_term ->
init_t:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g init init_t ->
universe_of g init_t u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_ref init_t))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_body x init_t init c) ->
st_typing g (wr c (Tm_WithLocal { binder=as_binder (mk_ref init_t); initializer=init; body } )) c
| T_WithLocalArray:
g:env ->
initializer:term ->
length:term ->
body:st_term ->
a:term ->
c:comp { C_ST? c } ->
x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } ->
tot_typing g initializer a ->
tot_typing g length tm_szt ->
universe_of g a u0 ->
comp_typing g c (comp_u c) ->
st_typing (push_binding g x ppname_default (mk_array a))
(open_st_term_nv body (v_as_nv x))
(comp_withlocal_array_body x a initializer length c) ->
st_typing g (wr c (Tm_WithLocalArray { binder=as_binder (mk_array a); initializer; length; body } )) c
| T_Rewrite:
g:env ->
p:vprop ->
q:vprop ->
tot_typing g p tm_vprop ->
vprop_equiv g p q ->
st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } ))
(comp_rewrite p q)
| T_Admit:
g:env ->
s:st_comp ->
c:ctag ->
st_comp_typing g s ->
st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None }))
(comp_admit c s)
and pats_complete : env -> term -> typ -> list R.pattern -> Type0 =
// just check the elaborated term with the core tc
| PC_Elab :
g:env ->
sc:term ->
sc_ty:typ ->
pats:list R.pattern ->
bnds:list (list R.binding) ->
RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds ->
pats_complete g sc sc_ty pats
and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type =
| TBRS_0 :
c:comp_st ->
brs_typing g sc_u sc_ty sc [] c
| TBRS_1 :
c:comp_st ->
p:pattern ->
e:st_term ->
br_typing g sc_u sc_ty sc p e c ->
rest:list branch ->
brs_typing g sc_u sc_ty sc rest c ->
brs_typing g sc_u sc_ty sc ((p,e)::rest) c
and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type =
| TBR :
g:env ->
sc_u : universe ->
sc_ty : typ ->
sc:term ->
c:comp_st ->
p:pattern ->
e:st_term ->
bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} ->
_ : squash (all_fresh g (L.map readback_binding bs)) ->
_ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) ->
_ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat
hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} ->
st_typing (
push_binding (push_bindings g (L.map readback_binding bs))
hyp
({name=Sealed.seal "branch equality"; range=FStar.Range.range_0})
(mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0))
) e c ->
br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c
(* this requires some metatheory on FStar.Reflection.Typing
G |- fv e : t
G(fv) = t0 -> t1
G |- e : t0
G |- t1 <: t
G |- e0 e1 : t ==>
exists t0 t1.
G |- e0 : t0 -> t1 /\
G |- e1 : t0
*)
let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t0 tm_vprop
= admit ()
let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: tot_typing g t1 tm_vprop
= admit ()
let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop)
: GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop)
= admit ()
let vprop_eq_typing_inversion g (t0 t1:term)
(token:FTB.equiv_token (elab_env g)
(elab_term t0)
(elab_term t1))
: GTot (tot_typing g t0 tm_vprop &
tot_typing g t1 tm_vprop)
= admit ()
(* These I can easily prove *)
let star_typing (#g:_) (#t0 #t1:term)
(d0:tot_typing g t0 tm_vprop)
(d1:tot_typing g t1 tm_vprop)
: tot_typing g (tm_star t0 t1) tm_vprop
= admit ()
let emp_typing (#g:_)
: tot_typing g tm_emp tm_vprop
= admit ()
noeq
type post_hint_t = {
g:env;
ctag_hint:option ctag;
ret_ty:term;
u:universe;
ty_typing:universe_of g ret_ty u;
post:term;
post_typing:
FStar.Ghost.erased (RT.tot_typing (elab_env g)
(RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post)))
(RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop)))
}
let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ)
: Lemma
(requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p) | false | false | Pulse.Typing.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ)
: Lemma (requires post_hint_for_env_p g p)
(ensures post_hint_for_env_p (push_binding g x ppname_default b) p)
[SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] | [] | Pulse.Typing.post_hint_for_env_extends | {
"file_name": "lib/steel/pulse/Pulse.Typing.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
g: Pulse.Typing.Env.env ->
p: Pulse.Typing.post_hint_t ->
x: Pulse.Syntax.Base.var{~(FStar.Set.mem x (Pulse.Typing.Env.dom g))} ->
b: Pulse.Syntax.Base.typ
-> FStar.Pervasives.Lemma (requires Pulse.Typing.post_hint_for_env_p g p)
(ensures
Pulse.Typing.post_hint_for_env_p (Pulse.Typing.Env.push_binding g
x
Pulse.Syntax.Base.ppname_default
b)
p)
[
SMTPat (Pulse.Typing.post_hint_for_env_p (Pulse.Typing.Env.push_binding g
x
Pulse.Syntax.Base.ppname_default
b)
p)
] | {
"end_col": 41,
"end_line": 1061,
"start_col": 4,
"start_line": 1061
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) | let vale_p = | false | null | false | let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Prims.l_and",
"Prims.b2t",
"Vale.X64.CPU_Features_s.adx_enabled",
"Vale.X64.CPU_Features_s.bmi2_enabled"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vale_p : Prims.logical | [] | Hacl.HPKE.Interface.DH.vale_p | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.logical | {
"end_col": 65,
"end_line": 84,
"start_col": 38,
"start_line": 84
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul | let nsize_key (a: DH.algorithm) = | false | null | false | match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Spec.Agile.DH.algorithm",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.t"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val nsize_key : a: Spec.Agile.DH.algorithm -> FStar.UInt32.t | [] | Hacl.HPKE.Interface.DH.nsize_key | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.DH.algorithm -> FStar.UInt32.t | {
"end_col": 22,
"end_line": 20,
"start_col": 2,
"start_line": 18
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul | let nsize_public (a: DH.algorithm) = | false | null | false | match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Spec.Agile.DH.algorithm",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.t"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val nsize_public : a: Spec.Agile.DH.algorithm -> FStar.UInt32.t | [] | Hacl.HPKE.Interface.DH.nsize_public | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.DH.algorithm -> FStar.UInt32.t | {
"end_col": 22,
"end_line": 26,
"start_col": 2,
"start_line": 24
} |
|
Prims.Tot | val secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul | val secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True
let secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True = | false | null | false | fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_Curve25519",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.t",
"Prims.unit",
"Hacl.Curve25519_51.secret_to_public"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **) | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True | [] | Hacl.HPKE.Interface.DH.secret_to_public_c51 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HPKE.Interface.DH.secret_to_public_st Spec.Agile.DH.DH_Curve25519 Prims.l_True | {
"end_col": 5,
"end_line": 73,
"start_col": 73,
"start_line": 71
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False)) | let secret_to_public_st (a: DH.algorithm) (p: Type0) = | false | null | false | o: lbuffer uint8 (nsize_public a) -> i: lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i)
(ensures
fun h0 result h1 ->
modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ (as_seq h1 o) `Seq.equal` (Some?.v output)
| 1ul -> None? output
| _ -> False)) | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Spec.Agile.DH.algorithm",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.Agile.DH.serialized_point",
"FStar.Seq.Base.equal",
"Lib.Buffer.as_seq",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.uu___is_None",
"Prims.l_False",
"Prims.logical",
"FStar.Pervasives.Native.option",
"Spec.Agile.DH.secret_to_public"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val secret_to_public_st : a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0 | [] | Hacl.HPKE.Interface.DH.secret_to_public_st | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0 | {
"end_col": 20,
"end_line": 58,
"start_col": 4,
"start_line": 47
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False)) | let dh_st (a: DH.algorithm) (p: Type0) = | false | null | false |
o: lbuffer uint8 (nsize_public a) ->
k: lbuffer uint8 (nsize_key a) ->
i: lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k)
(ensures
fun h0 result h1 ->
modifies (loc o) h0 h1 /\
(let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ (as_seq h1 o) `Seq.equal` (Some?.v output)
| 1ul -> None? output
| _ -> False)) | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Spec.Agile.DH.algorithm",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.Agile.DH.serialized_point",
"FStar.Seq.Base.equal",
"Lib.Buffer.as_seq",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.Pervasives.Native.uu___is_None",
"Prims.l_False",
"Prims.logical",
"FStar.Pervasives.Native.option",
"Spec.Agile.DH.dh"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val dh_st : a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0 | [] | Hacl.HPKE.Interface.DH.dh_st | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0 | {
"end_col": 21,
"end_line": 43,
"start_col": 5,
"start_line": 30
} |
|
Prims.Pure | val change_error_code (r: uint64)
: Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let change_error_code (r:uint64) : Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
= let r' = logand r (u64 1) in
logand_mask r (u64 1) 1;
let r' = cast U32 SEC r' in
Lib.RawIntTypes.u32_to_UInt32 r' | val change_error_code (r: uint64)
: Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
let change_error_code (r: uint64)
: Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) = | false | null | false | let r' = logand r (u64 1) in
logand_mask r (u64 1) 1;
let r' = cast U32 SEC r' in
Lib.RawIntTypes.u32_to_UInt32 r' | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [] | [
"Lib.IntTypes.uint64",
"Lib.RawIntTypes.u32_to_UInt32",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.op_At_Percent_Dot",
"Lib.IntTypes.U64",
"Lib.IntTypes.cast",
"Prims.unit",
"Lib.IntTypes.logand_mask",
"Lib.IntTypes.u64",
"Lib.IntTypes.logand",
"FStar.UInt32.t",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"Prims.l_iff"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
inline_for_extraction noextract
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
// TODO: After unification of error codes, this should be removed
inline_for_extraction noextract
let change_error_code (r:uint64) : Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1) | false | false | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val change_error_code (r: uint64)
: Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) | [] | Hacl.HPKE.Interface.DH.change_error_code | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | r: Lib.IntTypes.uint64 -> Prims.Pure FStar.UInt32.t | {
"end_col": 36,
"end_line": 107,
"start_col": 3,
"start_line": 104
} |
Prims.Tot | val secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul | val secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p
let secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p = | false | null | false | fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_Curve25519",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.t",
"Prims.unit",
"Hacl.Curve25519_64.secret_to_public"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p | [] | Hacl.HPKE.Interface.DH.secret_to_public_c64 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HPKE.Interface.DH.secret_to_public_st Spec.Agile.DH.DH_Curve25519 Hacl.HPKE.Interface.DH.vale_p | {
"end_col": 5,
"end_line": 89,
"start_col": 75,
"start_line": 87
} |
Prims.Tot | val secret_to_public_p256:secret_to_public_st (DH.DH_P256) True | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let secret_to_public_p256 : secret_to_public_st (DH.DH_P256) True = fun o i ->
let res = Hacl.Impl.P256.DH.ecp256dh_i o i in
if res then 0ul else 1ul | val secret_to_public_p256:secret_to_public_st (DH.DH_P256) True
let secret_to_public_p256:secret_to_public_st (DH.DH_P256) True = | false | null | false | fun o i ->
let res = Hacl.Impl.P256.DH.ecp256dh_i o i in
if res then 0ul else 1ul | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_P256",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.UInt32.t",
"Hacl.Impl.P256.DH.ecp256dh_i"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
inline_for_extraction noextract
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
// TODO: After unification of error codes, this should be removed
inline_for_extraction noextract
let change_error_code (r:uint64) : Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
= let r' = logand r (u64 1) in
logand_mask r (u64 1) 1;
let r' = cast U32 SEC r' in
Lib.RawIntTypes.u32_to_UInt32 r' | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val secret_to_public_p256:secret_to_public_st (DH.DH_P256) True | [] | Hacl.HPKE.Interface.DH.secret_to_public_p256 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HPKE.Interface.DH.secret_to_public_st Spec.Agile.DH.DH_P256 Prims.l_True | {
"end_col": 26,
"end_line": 112,
"start_col": 68,
"start_line": 110
} |
FStar.Pervasives.Lemma | val nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0)))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0) | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec nat_from_bytes_le_zero_is_zero (n:size_nat{n >= 1}) (s:Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` Lib.Sequence.create n (u8 0))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
= let open Lib.Sequence in
let open Lib.ByteSequence in
if n = 1 then nat_from_intseq_le_lemma0 s
else (
nat_from_intseq_le_slice_lemma s 1;
nat_from_bytes_le_zero_is_zero (n-1) (slice s 1 n);
nat_from_intseq_le_lemma0 (slice s 0 1)
) | val nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0)))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
let rec nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0)))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0) = | false | null | true | let open Lib.Sequence in
let open Lib.ByteSequence in
if n = 1
then nat_from_intseq_le_lemma0 s
else
(nat_from_intseq_le_slice_lemma s 1;
nat_from_bytes_le_zero_is_zero (n - 1) (slice s 1 n);
nat_from_intseq_le_lemma0 (slice s 0 1)) | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.ByteSequence.lbytes",
"Prims.op_Equality",
"Prims.int",
"Lib.ByteSequence.nat_from_intseq_le_lemma0",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.bool",
"Lib.Sequence.slice",
"Lib.IntTypes.uint_t",
"Prims.unit",
"Hacl.HPKE.Interface.DH.nat_from_bytes_le_zero_is_zero",
"Prims.op_Subtraction",
"Lib.ByteSequence.nat_from_intseq_le_slice_lemma",
"FStar.Seq.Base.equal",
"Lib.Sequence.create",
"Lib.IntTypes.u8",
"Prims.squash",
"Prims.eq2",
"Lib.ByteSequence.nat_from_bytes_le",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
inline_for_extraction noextract
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
// TODO: After unification of error codes, this should be removed
inline_for_extraction noextract
let change_error_code (r:uint64) : Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
= let r' = logand r (u64 1) in
logand_mask r (u64 1) 1;
let r' = cast U32 SEC r' in
Lib.RawIntTypes.u32_to_UInt32 r'
inline_for_extraction noextract
let secret_to_public_p256 : secret_to_public_st (DH.DH_P256) True = fun o i ->
let res = Hacl.Impl.P256.DH.ecp256dh_i o i in
if res then 0ul else 1ul
(* change_error_code res *)
let rec nat_from_bytes_le_zero_is_zero (n:size_nat{n >= 1}) (s:Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` Lib.Sequence.create n (u8 0)) | false | false | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0)))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0) | [
"recursion"
] | Hacl.HPKE.Interface.DH.nat_from_bytes_le_zero_is_zero | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | n: Lib.IntTypes.size_nat{n >= 1} -> s: Lib.ByteSequence.lbytes n
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.equal s (Lib.Sequence.create n (Lib.IntTypes.u8 0)))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0) | {
"end_col": 4,
"end_line": 125,
"start_col": 4,
"start_line": 118
} |
Prims.Tot | val dh_c51:dh_st (DH.DH_Curve25519) True | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res | val dh_c51:dh_st (DH.DH_Curve25519) True
let dh_c51:dh_st (DH.DH_Curve25519) True = | false | null | false | fun o k i ->
push_frame ();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame ();
res | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_Curve25519",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Lib.ByteBuffer.lbytes_eq",
"Hacl.Curve25519_51.scalarmult",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val dh_c51:dh_st (DH.DH_Curve25519) True | [] | Hacl.HPKE.Interface.DH.dh_c51 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HPKE.Interface.DH.dh_st Spec.Agile.DH.DH_Curve25519 Prims.l_True | {
"end_col": 5,
"end_line": 81,
"start_col": 45,
"start_line": 75
} |
Prims.Tot | val dh_c64:dh_st (DH.DH_Curve25519) vale_p | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res | val dh_c64:dh_st (DH.DH_Curve25519) vale_p
let dh_c64:dh_st (DH.DH_Curve25519) vale_p = | false | null | false | fun o k i ->
push_frame ();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame ();
res | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_Curve25519",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Lib.ByteBuffer.lbytes_eq",
"Hacl.Curve25519_64.scalarmult",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
inline_for_extraction noextract
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val dh_c64:dh_st (DH.DH_Curve25519) vale_p | [] | Hacl.HPKE.Interface.DH.dh_c64 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HPKE.Interface.DH.dh_st Spec.Agile.DH.DH_Curve25519 Hacl.HPKE.Interface.DH.vale_p | {
"end_col": 5,
"end_line": 97,
"start_col": 47,
"start_line": 91
} |
Prims.Tot | val dh_p256:dh_st (DH.DH_P256) True | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let dh_p256 : dh_st (DH.DH_P256) True = fun o k i ->
push_frame();
let tmp = create (size 64) (u8 0) in
(**) let h0 = HyperStack.ST.get() in
(**) nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 0) (size 32)));
(**) nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 32) (size 32)));
let res = Hacl.Impl.P256.DH.ecp256dh_r tmp i k in
copy o tmp;
pop_frame();
(* change_error_code res *)
if res then 0ul else 1ul | val dh_p256:dh_st (DH.DH_P256) True
let dh_p256:dh_st (DH.DH_P256) True = | false | null | false | fun o k i ->
push_frame ();
let tmp = create (size 64) (u8 0) in
let h0 = HyperStack.ST.get () in
nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 0) (size 32)));
nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 32) (size 32)));
let res = Hacl.Impl.P256.DH.ecp256dh_r tmp i k in
copy o tmp;
pop_frame ();
if res then 0ul else 1ul | {
"checked_file": "Hacl.HPKE.Interface.DH.fst.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
"total"
] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_P256",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.UInt32.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Hacl.Impl.P256.DH.ecp256dh_r",
"Hacl.HPKE.Interface.DH.nat_from_bytes_le_zero_is_zero",
"Lib.Buffer.as_seq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.size",
"Lib.Buffer.gsub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
inline_for_extraction noextract
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
// TODO: After unification of error codes, this should be removed
inline_for_extraction noextract
let change_error_code (r:uint64) : Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
= let r' = logand r (u64 1) in
logand_mask r (u64 1) 1;
let r' = cast U32 SEC r' in
Lib.RawIntTypes.u32_to_UInt32 r'
inline_for_extraction noextract
let secret_to_public_p256 : secret_to_public_st (DH.DH_P256) True = fun o i ->
let res = Hacl.Impl.P256.DH.ecp256dh_i o i in
if res then 0ul else 1ul
(* change_error_code res *)
let rec nat_from_bytes_le_zero_is_zero (n:size_nat{n >= 1}) (s:Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` Lib.Sequence.create n (u8 0))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
= let open Lib.Sequence in
let open Lib.ByteSequence in
if n = 1 then nat_from_intseq_le_lemma0 s
else (
nat_from_intseq_le_slice_lemma s 1;
nat_from_bytes_le_zero_is_zero (n-1) (slice s 1 n);
nat_from_intseq_le_lemma0 (slice s 0 1)
) | false | true | Hacl.HPKE.Interface.DH.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val dh_p256:dh_st (DH.DH_P256) True | [] | Hacl.HPKE.Interface.DH.dh_p256 | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HPKE.Interface.DH.dh_st Spec.Agile.DH.DH_P256 Prims.l_True | {
"end_col": 26,
"end_line": 138,
"start_col": 40,
"start_line": 128
} |
Prims.Tot | val compare_int : int -> int -> order | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_int i j = order_from_int (i - j) | val compare_int : int -> int -> order
let compare_int i j = | false | null | false | order_from_int (i - j) | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"Prims.int",
"FStar.Order.order_from_int",
"Prims.op_Subtraction",
"FStar.Order.order"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt
val eq : order -> bool
let eq o = o = Eq
// Lexicographical combination, thunked to be lazy
val lex : order -> (unit -> order) -> order
let lex o1 o2 =
match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt
val order_from_int : int -> order
let order_from_int i =
if i < 0 then Lt
else if i = 0 then Eq
else Gt
val int_of_order : order -> int
let int_of_order = function
| Lt -> (-1)
| Eq -> 0
| Gt -> 1 | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_int : int -> int -> order | [] | FStar.Order.compare_int | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.int -> j: Prims.int -> FStar.Order.order | {
"end_col": 44,
"end_line": 61,
"start_col": 22,
"start_line": 61
} |
Prims.Tot | val order_from_int : int -> order | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let order_from_int i =
if i < 0 then Lt
else if i = 0 then Eq
else Gt | val order_from_int : int -> order
let order_from_int i = | false | null | false | if i < 0 then Lt else if i = 0 then Eq else Gt | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"Prims.int",
"Prims.op_LessThan",
"FStar.Order.Lt",
"Prims.bool",
"Prims.op_Equality",
"FStar.Order.Eq",
"FStar.Order.Gt",
"FStar.Order.order"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt
val eq : order -> bool
let eq o = o = Eq
// Lexicographical combination, thunked to be lazy
val lex : order -> (unit -> order) -> order
let lex o1 o2 =
match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt
val order_from_int : int -> order | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val order_from_int : int -> order | [] | FStar.Order.order_from_int | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.int -> FStar.Order.order | {
"end_col": 11,
"end_line": 52,
"start_col": 4,
"start_line": 50
} |
Prims.Tot | val le : order -> bool | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let le o = o <> Gt | val le : order -> bool
let le o = | false | null | false | o <> Gt | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_disEquality",
"FStar.Order.Gt",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val le : order -> bool | [] | FStar.Order.le | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Order.order -> Prims.bool | {
"end_col": 18,
"end_line": 25,
"start_col": 11,
"start_line": 25
} |
Prims.Tot | val ge : order -> bool | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ge o = o <> Lt | val ge : order -> bool
let ge o = | false | null | false | o <> Lt | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_disEquality",
"FStar.Order.Lt",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ge : order -> bool | [] | FStar.Order.ge | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Order.order -> Prims.bool | {
"end_col": 18,
"end_line": 22,
"start_col": 11,
"start_line": 22
} |
Prims.Tot | val ne : order -> bool | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ne o = o <> Eq | val ne : order -> bool
let ne o = | false | null | false | o <> Eq | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_disEquality",
"FStar.Order.Eq",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ne : order -> bool | [] | FStar.Order.ne | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Order.order -> Prims.bool | {
"end_col": 18,
"end_line": 28,
"start_col": 11,
"start_line": 28
} |
Prims.Tot | val gt : order -> bool | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gt o = o = Gt | val gt : order -> bool
let gt o = | false | null | false | o = Gt | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_Equality",
"FStar.Order.Gt",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency... | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gt : order -> bool | [] | FStar.Order.gt | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Order.order -> Prims.bool | {
"end_col": 17,
"end_line": 32,
"start_col": 11,
"start_line": 32
} |
Prims.Tot | val eq : order -> bool | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eq o = o = Eq | val eq : order -> bool
let eq o = | false | null | false | o = Eq | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_Equality",
"FStar.Order.Eq",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eq : order -> bool | [] | FStar.Order.eq | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Order.order -> Prims.bool | {
"end_col": 17,
"end_line": 38,
"start_col": 11,
"start_line": 38
} |
Prims.Tot | val compare_option : ('a -> 'a -> order) -> option 'a -> option 'a -> order | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_option f x y =
match x, y with
| None , None -> Eq
| None , Some _ -> Lt
| Some _ , None -> Gt
| Some x , Some y -> f x y | val compare_option : ('a -> 'a -> order) -> option 'a -> option 'a -> order
let compare_option f x y = | false | null | false | match x, y with
| None, None -> Eq
| None, Some _ -> Lt
| Some _, None -> Gt
| Some x, Some y -> f x y | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Order.Eq",
"FStar.Order.Lt",
"FStar.Order.Gt"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt
val eq : order -> bool
let eq o = o = Eq
// Lexicographical combination, thunked to be lazy
val lex : order -> (unit -> order) -> order
let lex o1 o2 =
match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt
val order_from_int : int -> order
let order_from_int i =
if i < 0 then Lt
else if i = 0 then Eq
else Gt
val int_of_order : order -> int
let int_of_order = function
| Lt -> (-1)
| Eq -> 0
| Gt -> 1
val compare_int : int -> int -> order
let compare_int i j = order_from_int (i - j)
(*
* It promises to call the comparator in strictly smaller elements
* Useful when writing a comparator for an inductive type,
* that contains the list of itself as an argument to one of its
* data constructors
*)
let rec compare_list (#a:Type)
(l1 l2:list a)
(f:(x:a{x << l1} -> y:a{y << l2} -> order))
: order
= match l1, l2 with
| [], [] -> Eq
| [], _ -> Lt
| _, [] -> Gt
| x::xs, y::ys -> lex (f x y) (fun _ -> compare_list xs ys f)
val compare_option : ('a -> 'a -> order) -> option 'a -> option 'a -> order | false | false | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_option : ('a -> 'a -> order) -> option 'a -> option 'a -> order | [] | FStar.Order.compare_option | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: 'a -> _: 'a -> FStar.Order.order) ->
x: FStar.Pervasives.Native.option 'a ->
y: FStar.Pervasives.Native.option 'a
-> FStar.Order.order | {
"end_col": 30,
"end_line": 85,
"start_col": 4,
"start_line": 81
} |
Prims.Tot | val lex : order -> (unit -> order) -> order | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lex o1 o2 =
match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt | val lex : order -> (unit -> order) -> order
let lex o1 o2 = | false | null | false | match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.unit",
"FStar.Order.Lt",
"FStar.Order.Gt"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt
val eq : order -> bool
let eq o = o = Eq
// Lexicographical combination, thunked to be lazy
val lex : order -> (unit -> order) -> order | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lex : order -> (unit -> order) -> order | [] | FStar.Order.lex | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o1: FStar.Order.order -> o2: (_: Prims.unit -> FStar.Order.order) -> FStar.Order.order | {
"end_col": 14,
"end_line": 46,
"start_col": 4,
"start_line": 43
} |
Prims.Tot | val int_of_order : order -> int | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let int_of_order = function
| Lt -> (-1)
| Eq -> 0
| Gt -> 1 | val int_of_order : order -> int
let int_of_order = | false | null | false | function
| Lt -> (- 1)
| Eq -> 0
| Gt -> 1 | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_Minus",
"Prims.int"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt
val eq : order -> bool
let eq o = o = Eq
// Lexicographical combination, thunked to be lazy
val lex : order -> (unit -> order) -> order
let lex o1 o2 =
match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt
val order_from_int : int -> order
let order_from_int i =
if i < 0 then Lt
else if i = 0 then Eq
else Gt | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val int_of_order : order -> int | [] | FStar.Order.int_of_order | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Order.order -> Prims.int | {
"end_col": 13,
"end_line": 58,
"start_col": 19,
"start_line": 55
} |
Prims.Tot | val lt : order -> bool | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lt o = o = Lt | val lt : order -> bool
let lt o = | false | null | false | o = Lt | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"FStar.Order.order",
"Prims.op_Equality",
"FStar.Order.Lt",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt | false | true | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lt : order -> bool | [] | FStar.Order.lt | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Order.order -> Prims.bool | {
"end_col": 17,
"end_line": 35,
"start_col": 11,
"start_line": 35
} |
Prims.Tot | val compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order)) : order | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec compare_list (#a:Type)
(l1 l2:list a)
(f:(x:a{x << l1} -> y:a{y << l2} -> order))
: order
= match l1, l2 with
| [], [] -> Eq
| [], _ -> Lt
| _, [] -> Gt
| x::xs, y::ys -> lex (f x y) (fun _ -> compare_list xs ys f) | val compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order)) : order
let rec compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order))
: order = | false | null | false | match l1, l2 with
| [], [] -> Eq
| [], _ -> Lt
| _, [] -> Gt
| x :: xs, y :: ys -> lex (f x y) (fun _ -> compare_list xs ys f) | {
"checked_file": "FStar.Order.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Order.fst"
} | [
"total"
] | [
"Prims.list",
"Prims.precedes",
"FStar.Order.order",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Order.Eq",
"FStar.Order.Lt",
"FStar.Order.Gt",
"FStar.Order.lex",
"Prims.unit",
"FStar.Order.compare_list"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Order
type order = | Lt | Eq | Gt
// Some derived checks
val ge : order -> bool
let ge o = o <> Lt
val le : order -> bool
let le o = o <> Gt
val ne : order -> bool
let ne o = o <> Eq
// Just for completeness and consistency...
val gt : order -> bool
let gt o = o = Gt
val lt : order -> bool
let lt o = o = Lt
val eq : order -> bool
let eq o = o = Eq
// Lexicographical combination, thunked to be lazy
val lex : order -> (unit -> order) -> order
let lex o1 o2 =
match o1 with
| Lt -> Lt
| Eq -> o2 ()
| Gt -> Gt
val order_from_int : int -> order
let order_from_int i =
if i < 0 then Lt
else if i = 0 then Eq
else Gt
val int_of_order : order -> int
let int_of_order = function
| Lt -> (-1)
| Eq -> 0
| Gt -> 1
val compare_int : int -> int -> order
let compare_int i j = order_from_int (i - j)
(*
* It promises to call the comparator in strictly smaller elements
* Useful when writing a comparator for an inductive type,
* that contains the list of itself as an argument to one of its
* data constructors
*)
let rec compare_list (#a:Type)
(l1 l2:list a)
(f:(x:a{x << l1} -> y:a{y << l2} -> order)) | false | false | FStar.Order.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order)) : order | [
"recursion"
] | FStar.Order.compare_list | {
"file_name": "ulib/FStar.Order.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l1: Prims.list a -> l2: Prims.list a -> f: (x: a{x << l1} -> y: a{y << l2} -> FStar.Order.order)
-> FStar.Order.order | {
"end_col": 65,
"end_line": 77,
"start_col": 4,
"start_line": 73
} |
FStar.Pervasives.Lemma | val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2 | val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0)
let lemma_pow2_is_divisible_by_2 l = | false | null | true | Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2 | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"FStar.Pervasives.assert_norm",
"FStar.Math.Lemmas.pow2_plus"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp
val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0) | [] | Hacl.Impl.Exponentiation.lemma_pow2_is_divisible_by_2 | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | l: Prims.pos -> FStar.Pervasives.Lemma (ensures Prims.pow2 l % 2 = 0) | {
"end_col": 54,
"end_line": 513,
"start_col": 2,
"start_line": 510
} |
Prims.Tot | val lprecomp_get_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp | val lprecomp_get_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len)
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp = | false | null | false | PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"FStar.Ghost.erased",
"Lib.Sequence.lseq",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.op_LessThan",
"Prims.pow2",
"Hacl.Impl.PrecompTable.lprecomp_get_vartime",
"Prims.unit"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//------------------------------------- | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lprecomp_get_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | [] | Hacl.Impl.Exponentiation.lprecomp_get_vartime | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len
-> Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t
len
ctx_len
k
l
table_len
(Hacl.Impl.Exponentiation.table_inv_precomp len ctx_len k l table_len) | {
"end_col": 73,
"end_line": 501,
"start_col": 2,
"start_line": 501
} |
Prims.Tot | val lprecomp_get_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp | val lprecomp_get_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len)
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp = | false | null | false | PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"FStar.Ghost.erased",
"Lib.Sequence.lseq",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.op_LessThan",
"Prims.pow2",
"Hacl.Impl.PrecompTable.lprecomp_get_consttime",
"Prims.unit"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lprecomp_get_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | [] | Hacl.Impl.Exponentiation.lprecomp_get_consttime | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len
-> Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t
len
ctx_len
k
l
table_len
(Hacl.Impl.Exponentiation.table_inv_precomp len ctx_len k l table_len) | {
"end_col": 75,
"end_line": 505,
"start_col": 2,
"start_line": 505
} |
Prims.Tot | val lexp_fw_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_fw_consttime #a_t len ctx_len k l ctx a bLen bBits b acc =
[@inline_let]
let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len
(lprecomp_get_consttime len ctx_len k l table_len)
ctx a bLen bBits b acc | val lexp_fw_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l
let lexp_fw_consttime #a_t len ctx_len k l ctx a bLen bBits b acc = | false | null | false | [@@ inline_let ]let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len (lprecomp_get_consttime len ctx_len k l table_len) ctx a
bLen bBits b acc | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Hacl.Impl.Exponentiation.lexp_fw_gen",
"Hacl.Impl.Exponentiation.lprecomp_get_consttime",
"Prims.unit",
"Prims._assert",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.pow2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp
val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0)
let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2
inline_for_extraction noextract
val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l
let lexp_fw_gen #a_t len ctx_len k l table_len lprecomp_get ctx a bLen bBits b res =
push_frame ();
Math.Lemmas.pow2_lt_compat 32 (v l);
lemma_pow2_is_divisible_by_2 (v l);
let table = create (table_len *! len) (uint #a_t #SEC 0) in
PT.lprecomp_table #a_t len ctx_len k ctx a table_len table;
[@inline_let]
let table_inv : table_inv_t a_t len table_len =
table_inv_precomp len ctx_len k l table_len in
let h1 = ST.get () in
assert (table_inv (as_seq h1 a) (as_seq h1 table));
mk_lexp_fw_table len ctx_len k l table_len
table_inv lprecomp_get
ctx a bLen bBits b (to_const table) res;
pop_frame ()
let lexp_fw_vartime #a_t len ctx_len k l ctx a bLen bBits b acc =
[@inline_let]
let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len
(lprecomp_get_vartime len ctx_len k l table_len)
ctx a bLen bBits b acc | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_fw_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | [] | Hacl.Impl.Exponentiation.lexp_fw_consttime | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len
-> Hacl.Impl.Exponentiation.lexp_fw_st a_t len ctx_len k l | {
"end_col": 26,
"end_line": 569,
"start_col": 2,
"start_line": 561
} |
FStar.Pervasives.Lemma | val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL) | val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b = | false | null | true | match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"lemma"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt32.t",
"FStar.UInt32.logxor",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.IntTypes.logxor_spec",
"FStar.UInt64.t",
"FStar.UInt64.logxor",
"FStar.UInt64.__uint_to_t"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2) | [] | Hacl.Impl.Exponentiation.lemma_bit_xor_is_sum_mod2 | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC -> b: Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma (requires Lib.IntTypes.v a <= 1 /\ Lib.IntTypes.v b <= 1)
(ensures Lib.IntTypes.v (a ^. b) == (Lib.IntTypes.v a + Lib.IntTypes.v b) % 2) | {
"end_col": 46,
"end_line": 98,
"start_col": 2,
"start_line": 86
} |
FStar.HyperStack.ST.Stack | val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2))) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2) | val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 = | true | null | false | let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"Lib.Buffer.lbuffer",
"Hacl.Spec.Bignum.cswap2_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Hacl.Bignum.cswap2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2))) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2))) | [] | Hacl.Impl.Exponentiation.cswap2 | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
bit: Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC {Lib.IntTypes.v bit <= 1} ->
p1: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
p2: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 51,
"end_line": 78,
"start_col": 41,
"start_line": 75
} |
Prims.Tot | val lexp_fw_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_fw_vartime #a_t len ctx_len k l ctx a bLen bBits b acc =
[@inline_let]
let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len
(lprecomp_get_vartime len ctx_len k l table_len)
ctx a bLen bBits b acc | val lexp_fw_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l
let lexp_fw_vartime #a_t len ctx_len k l ctx a bLen bBits b acc = | false | null | false | [@@ inline_let ]let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len (lprecomp_get_vartime len ctx_len k l table_len) ctx a
bLen bBits b acc | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Hacl.Impl.Exponentiation.lexp_fw_gen",
"Hacl.Impl.Exponentiation.lprecomp_get_vartime",
"Prims.unit",
"Prims._assert",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.pow2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp
val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0)
let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2
inline_for_extraction noextract
val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l
let lexp_fw_gen #a_t len ctx_len k l table_len lprecomp_get ctx a bLen bBits b res =
push_frame ();
Math.Lemmas.pow2_lt_compat 32 (v l);
lemma_pow2_is_divisible_by_2 (v l);
let table = create (table_len *! len) (uint #a_t #SEC 0) in
PT.lprecomp_table #a_t len ctx_len k ctx a table_len table;
[@inline_let]
let table_inv : table_inv_t a_t len table_len =
table_inv_precomp len ctx_len k l table_len in
let h1 = ST.get () in
assert (table_inv (as_seq h1 a) (as_seq h1 table));
mk_lexp_fw_table len ctx_len k l table_len
table_inv lprecomp_get
ctx a bLen bBits b (to_const table) res;
pop_frame () | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_fw_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | [] | Hacl.Impl.Exponentiation.lexp_fw_vartime | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len
-> Hacl.Impl.Exponentiation.lexp_fw_st a_t len ctx_len k l | {
"end_col": 26,
"end_line": 557,
"start_col": 2,
"start_line": 549
} |
Prims.Tot | val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp | val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f
#a_t
len
ctx_len
k
l
table_len
table_inv
pow_a_to_small_b
ctx
a
bLen
bBits
b
table
i
acc
tmp
= | false | null | false | lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b
table i acc tmp | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Hacl.Impl.Exponentiation.lmul_acc_pow_a_bits_l",
"Prims.unit",
"Hacl.Impl.Exponentiation.lexp_pow2_in_place"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv | [] | Hacl.Impl.Exponentiation.lexp_fw_f | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
pow_a_to_small_b:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv
-> Hacl.Impl.Exponentiation.lexp_fw_f_st a_t len ctx_len k l table_len table_inv | {
"end_col": 116,
"end_line": 368,
"start_col": 2,
"start_line": 367
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)) | let lexp_fw_acc0_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
= | false | null | false |
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
acc: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
v bBits % v l <> 0 /\ live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\ disjoint acc ctx /\
disjoint acc table /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.exp_fw_acc0",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_fw_acc0_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | [] | Hacl.Impl.Exponentiation.lexp_fw_acc0_st | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | {
"end_col": 92,
"end_line": 469,
"start_col": 4,
"start_line": 451
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc))) | let lexp_fw_loop_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
= | false | null | false |
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
acc: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\ disjoint a acc /\
disjoint a ctx /\ disjoint b acc /\ disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\ table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l)
(S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
(k.to.refl (as_seq h0 acc))) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_fw_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_fw_loop_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | [] | Hacl.Impl.Exponentiation.lexp_fw_loop_st | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | {
"end_col": 66,
"end_line": 399,
"start_col": 4,
"start_line": 380
} |
|
FStar.HyperStack.ST.Stack | val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc) | val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b = | true | null | false | let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@@ inline_let ]let spec h0 = S.sqr k.to.comm_monoid in
[@@ inline_let ]let inv h (i: nat{i <= v b}) =
modifies (loc acc) h0 h /\ k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0)
in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul
b
inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lsqr",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeat",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.LoopCombinators.eq_repeat0",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeat",
"Lib.Exponentiation.Definition.sqr",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Prims.int",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | [] | Hacl.Impl.Exponentiation.lexp_pow2_in_place | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
ctx: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) ctx_len ->
a: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
b: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 23,
"end_line": 186,
"start_col": 53,
"start_line": 169
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc))) | let lmul_acc_pow_a_bits_l_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
= | false | null | false |
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
i: size_t{v i < v bBits / v l} ->
acc: lbuffer (uint_t a_t SEC) len ->
tmp: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\ live h tmp /\
disjoint tmp a /\ disjoint tmp b /\ disjoint tmp acc /\ disjoint tmp ctx /\
disjoint tmp table /\ disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\ BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc |+| loc tmp) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec
k.to.comm_monoid
(k.to.refl (as_seq h0 a))
(v bBits)
(BD.bn_v h0 b)
(v l)
(v i)
(k.to.refl (as_seq h0 acc))) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.mul_acc_pow_a_bits_l",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lmul_acc_pow_a_bits_l_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | [] | Hacl.Impl.Exponentiation.lmul_acc_pow_a_bits_l_st | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | {
"end_col": 71,
"end_line": 290,
"start_col": 4,
"start_line": 266
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc))) | let lexp_fw_f_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
= | false | null | false |
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
i: size_t{v i < v bBits / v l} ->
acc: lbuffer (uint_t a_t SEC) len ->
tmp: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\ live h tmp /\
disjoint tmp a /\ disjoint tmp b /\ disjoint tmp acc /\ disjoint tmp ctx /\
disjoint tmp table /\ disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\ BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc |+| loc tmp) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec
k.to.comm_monoid
(k.to.refl (as_seq h0 a))
(v bBits)
(BD.bn_v h0 b)
(v l)
(v i)
(k.to.refl (as_seq h0 acc))) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.exp_fw_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_fw_f_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | [] | Hacl.Impl.Exponentiation.lexp_fw_f_st | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | {
"end_col": 71,
"end_line": 350,
"start_col": 4,
"start_line": 326
} |
|
FStar.HyperStack.ST.Stack | val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res) | val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
let lexp_pow2 #a_t len ctx_len k ctx a b res = | true | null | false | copy res a;
let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@@ inline_let ]let spec h0 = S.sqr k.to.comm_monoid in
[@@ inline_let ]let inv h (i: nat{i <= v b}) =
modifies (loc res) h0 h /\ k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0)
in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul
b
inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res) | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lsqr",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeat",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.LoopCombinators.eq_repeat0",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeat",
"Lib.Exponentiation.Definition.sqr",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Prims.int",
"FStar.HyperStack.ST.get",
"Lib.Buffer.copy"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame () | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | [] | Hacl.Impl.Exponentiation.lexp_pow2 | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
ctx: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) ctx_len ->
a: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
b: Lib.IntTypes.size_t ->
res: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 23,
"end_line": 166,
"start_col": 2,
"start_line": 149
} |
FStar.HyperStack.ST.Stack | val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l)) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l | val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l = | true | null | false | Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == (v bBits / v l) * v l);
let i = bBits /. l *! l in
assert (v i == (v bBits / v l) * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l | {
"checked_file": "Hacl.Impl.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.op_Modulus",
"Hacl.Bignum.bn_get_bits",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"Hacl.Spec.Bignum.bn_get_bits_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims._assert",
"FStar.Math.Lemmas.lemma_div_le",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.op_Slash_Dot",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l)) | false | false | Hacl.Impl.Exponentiation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l)) | [] | Hacl.Impl.Exponentiation.bn_get_bits_c | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
bLen: Lib.IntTypes.size_t ->
bBits:
Lib.IntTypes.size_t{(Lib.IntTypes.v bBits - 1) / Lib.IntTypes.bits b_t < Lib.IntTypes.v bLen} ->
b: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t b_t Lib.IntTypes.SEC) bLen ->
l:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits b_t /\
0 < Lib.IntTypes.v bBits % Lib.IntTypes.v l }
-> FStar.HyperStack.ST.Stack (Lib.IntTypes.uint_t b_t Lib.IntTypes.SEC) | {
"end_col": 27,
"end_line": 253,
"start_col": 2,
"start_line": 242
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.