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
val comp_inames (c: comp{C_STAtomic? c \/ C_STGhost? c}) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_inames (c:comp { C_STAtomic? c \/ C_STGhost? c }) : term = match c with | C_STAtomic inames _ | C_STGhost inames _ -> inames
val comp_inames (c: comp{C_STAtomic? c \/ C_STGhost? c}) : term let comp_inames (c: comp{C_STAtomic? c \/ C_STGhost? c}) : term =
false
null
false
match c with | C_STAtomic inames _ | C_STGhost inames _ -> inames
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.l_or", "Prims.b2t", "Pulse.Syntax.Base.uu___is_C_STAtomic", "Pulse.Syntax.Base.uu___is_C_STGhost", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.st_comp" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s let comp_u (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u let comp_pre (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.pre let comp_post (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.post
false
false
Pulse.Syntax.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val comp_inames (c: comp{C_STAtomic? c \/ C_STGhost? c}) : term
[]
Pulse.Syntax.Base.comp_inames
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp{C_STAtomic? c \/ C_STGhost? c} -> Pulse.Syntax.Base.term
{ "end_col": 32, "end_line": 366, "start_col": 2, "start_line": 364 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_u (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u
let comp_u (c: comp{stateful_comp c}) =
false
null
false
match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Pulse.Syntax.Base.stateful_comp", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.__proj__Mkst_comp__item__u", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.universe" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s
false
false
Pulse.Syntax.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val comp_u : c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.universe
[]
Pulse.Syntax.Base.comp_u
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.universe
{ "end_col": 24, "end_line": 349, "start_col": 2, "start_line": 346 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_post (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.post
let comp_post (c: comp{stateful_comp c}) =
false
null
false
match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.post
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Pulse.Syntax.Base.stateful_comp", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.__proj__Mkst_comp__item__post", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.vprop" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s let comp_u (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u let comp_pre (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.pre
false
false
Pulse.Syntax.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val comp_post : c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.vprop
[]
Pulse.Syntax.Base.comp_post
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.vprop
{ "end_col": 27, "end_line": 361, "start_col": 2, "start_line": 358 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_pre (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.pre
let comp_pre (c: comp{stateful_comp c}) =
false
null
false
match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.pre
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Pulse.Syntax.Base.stateful_comp", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.__proj__Mkst_comp__item__pre", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.vprop" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s let comp_u (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u
false
false
Pulse.Syntax.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val comp_pre : c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.vprop
[]
Pulse.Syntax.Base.comp_pre
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.vprop
{ "end_col": 26, "end_line": 355, "start_col": 2, "start_line": 352 }
Prims.Tot
val test1_plaintext:b: lbuffer uint8 3ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l
val test1_plaintext:b: lbuffer uint8 3ul {recallable b} let test1_plaintext:b: lbuffer uint8 3ul {recallable b} =
false
null
false
let open Lib.RawIntTypes in [@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } =
false
false
Hacl.Test.SHA2.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 test1_plaintext:b: lbuffer uint8 3ul {recallable b}
[]
Hacl.Test.SHA2.test1_plaintext
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 3 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 61, "start_col": 2, "start_line": 56 }
Prims.Tot
val u8: n:nat{n < 0x100} -> uint8
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let u8 n = u8 n
val u8: n:nat{n < 0x100} -> uint8 let u8 n =
false
null
false
u8 n
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.u8", "Lib.IntTypes.uint8" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract
false
false
Hacl.Test.SHA2.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 u8: n:nat{n < 0x100} -> uint8
[]
Hacl.Test.SHA2.u8
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Prims.nat{n < 0x100} -> Lib.IntTypes.uint8
{ "end_col": 15, "end_line": 49, "start_col": 11, "start_line": 49 }
Prims.Tot
val test2_plaintext:b: lbuffer uint8 0ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l
val test2_plaintext:b: lbuffer uint8 0ul {recallable b} let test2_plaintext:b: lbuffer uint8 0ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 //
false
false
Hacl.Test.SHA2.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 test2_plaintext:b: lbuffer uint8 0ul {recallable b}
[]
Hacl.Test.SHA2.test2_plaintext
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 0 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 115, "start_col": 2, "start_line": 110 }
Prims.Tot
val test1_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
val test1_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} let test1_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad ]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test1_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[]
Hacl.Test.SHA2.test1_expected_sha2_256
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 32 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 81, "start_col": 2, "start_line": 74 }
Prims.Tot
val test3_plaintext:b: lbuffer uint8 56ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l
val test3_plaintext:b: lbuffer uint8 56ul {recallable b} let test3_plaintext:b: lbuffer uint8 56ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71 ]) in assert_norm (List.Tot.length l == 56); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 //
false
false
Hacl.Test.SHA2.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 test3_plaintext:b: lbuffer uint8 56ul {recallable b}
[]
Hacl.Test.SHA2.test3_plaintext
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 56 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 173, "start_col": 2, "start_line": 164 }
Prims.Tot
val test1_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
val test1_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} let test1_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7 ]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test1_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[]
Hacl.Test.SHA2.test1_expected_sha2_224
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 28 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 71, "start_col": 2, "start_line": 64 }
Prims.Tot
val test2_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
val test2_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} let test2_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f ]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test2_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[]
Hacl.Test.SHA2.test2_expected_sha2_224
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 28 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 125, "start_col": 2, "start_line": 118 }
Prims.Tot
val test2_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
val test2_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} let test2_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55 ]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test2_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[]
Hacl.Test.SHA2.test2_expected_sha2_256
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 32 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 135, "start_col": 2, "start_line": 128 }
Prims.Tot
val test1_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
val test1_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} let test1_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7 ]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test1_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[]
Hacl.Test.SHA2.test1_expected_sha2_384
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 48 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 92, "start_col": 2, "start_line": 84 }
Prims.Tot
val test2_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
val test2_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} let test2_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e ]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test2_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[]
Hacl.Test.SHA2.test2_expected_sha2_512
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 64 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 158, "start_col": 2, "start_line": 149 }
Prims.Tot
val test3_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
val test3_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} let test3_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25 ]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test3_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[]
Hacl.Test.SHA2.test3_expected_sha2_224
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 28 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 183, "start_col": 2, "start_line": 176 }
Prims.Tot
val test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
val test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} let test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b ]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[]
Hacl.Test.SHA2.test3_expected_sha2_384
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 48 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 204, "start_col": 2, "start_line": 196 }
Prims.Tot
val test4_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
val test4_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} let test4_expected_sha2_224:b: lbuffer uint8 28ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3 ]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test4_expected_sha2_224:b: lbuffer uint8 28ul {recallable b}
[]
Hacl.Test.SHA2.test4_expected_sha2_224
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 28 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 244, "start_col": 2, "start_line": 237 }
Prims.Tot
val test3_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
val test3_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} let test3_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1 ]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test3_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[]
Hacl.Test.SHA2.test3_expected_sha2_256
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 32 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 193, "start_col": 2, "start_line": 186 }
Prims.Tot
val test2_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
val test2_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} let test2_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b ]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test2_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[]
Hacl.Test.SHA2.test2_expected_sha2_384
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 48 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 146, "start_col": 2, "start_line": 138 }
Prims.Tot
val test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test4_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
val test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} let test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39 ]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
[]
Hacl.Test.SHA2.test4_expected_sha2_384
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 48 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 265, "start_col": 2, "start_line": 257 }
Prims.Tot
val test1_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
val test1_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} let test1_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f ]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test1_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[]
Hacl.Test.SHA2.test1_expected_sha2_512
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 64 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 104, "start_col": 2, "start_line": 95 }
Prims.Tot
val test4_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
val test4_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} let test4_expected_sha2_256:b: lbuffer uint8 32ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1 ]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test4_expected_sha2_256:b: lbuffer uint8 32ul {recallable b}
[]
Hacl.Test.SHA2.test4_expected_sha2_256
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 32 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 254, "start_col": 2, "start_line": 247 }
Prims.Tot
val test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
val test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} let test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45 ]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[]
Hacl.Test.SHA2.test3_expected_sha2_512
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 64 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 216, "start_col": 2, "start_line": 207 }
Prims.Tot
val test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test4_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x8e; 0x95; 0x9b; 0x75; 0xda; 0xe3; 0x13; 0xda; 0x8c; 0xf4; 0xf7; 0x28; 0x14; 0xfc; 0x14; 0x3f; 0x8f; 0x77; 0x79; 0xc6; 0xeb; 0x9f; 0x7f; 0xa1; 0x72; 0x99; 0xae; 0xad; 0xb6; 0x88; 0x90; 0x18; 0x50; 0x1d; 0x28; 0x9e; 0x49; 0x00; 0xf7; 0xe4; 0x33; 0x1b; 0x99; 0xde; 0xc4; 0xb5; 0x43; 0x3a; 0xc7; 0xd3; 0x29; 0xee; 0xb6; 0xdd; 0x26; 0x54; 0x5e; 0x96; 0xe5; 0x5b; 0x87; 0x4b; 0xe9; 0x09]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
val test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} let test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x8e; 0x95; 0x9b; 0x75; 0xda; 0xe3; 0x13; 0xda; 0x8c; 0xf4; 0xf7; 0x28; 0x14; 0xfc; 0x14; 0x3f; 0x8f; 0x77; 0x79; 0xc6; 0xeb; 0x9f; 0x7f; 0xa1; 0x72; 0x99; 0xae; 0xad; 0xb6; 0x88; 0x90; 0x18; 0x50; 0x1d; 0x28; 0x9e; 0x49; 0x00; 0xf7; 0xe4; 0x33; 0x1b; 0x99; 0xde; 0xc4; 0xb5; 0x43; 0x3a; 0xc7; 0xd3; 0x29; 0xee; 0xb6; 0xdd; 0x26; 0x54; 0x5e; 0x96; 0xe5; 0x5b; 0x87; 0x4b; 0xe9; 0x09 ]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test4_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
false
false
Hacl.Test.SHA2.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 test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
[]
Hacl.Test.SHA2.test4_expected_sha2_512
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 64 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 277, "start_col": 2, "start_line": 268 }
Prims.Tot
val test4_plaintext:b: lbuffer uint8 112ul {recallable b}
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l
val test4_plaintext:b: lbuffer uint8 112ul {recallable b} let test4_plaintext:b: lbuffer uint8 112ul {recallable b} =
false
null
false
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75 ]) in assert_norm (List.Tot.length l == 112); createL_mglobal l
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ "total" ]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 //
false
false
Hacl.Test.SHA2.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 test4_plaintext:b: lbuffer uint8 112ul {recallable b}
[]
Hacl.Test.SHA2.test4_plaintext
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (FStar.UInt32.uint_to_t 112 <: FStar.UInt32.t) {Lib.Buffer.recallable b}
{ "end_col": 19, "end_line": 234, "start_col": 2, "start_line": 222 }
FStar.HyperStack.ST.St
val main: unit -> St C.exit_code
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let main () = C.String.print (C.String.of_literal "\nTEST 1. SHA2\n"); recall test1_expected_sha2_224; recall test1_expected_sha2_256; recall test1_expected_sha2_384; recall test1_expected_sha2_512; recall test1_plaintext; test_sha2 3ul test1_plaintext test1_expected_sha2_224 test1_expected_sha2_256 test1_expected_sha2_384 test1_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 2. SHA2\n"); recall test2_expected_sha2_224; recall test2_expected_sha2_256; recall test2_expected_sha2_384; recall test2_expected_sha2_512; recall test2_plaintext; test_sha2 0ul test2_plaintext test2_expected_sha2_224 test2_expected_sha2_256 test2_expected_sha2_384 test2_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 3. SHA2\n"); recall test3_expected_sha2_224; recall test3_expected_sha2_256; recall test3_expected_sha2_384; recall test3_expected_sha2_512; recall test3_plaintext; test_sha2 56ul test3_plaintext test3_expected_sha2_224 test3_expected_sha2_256 test3_expected_sha2_384 test3_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 4. SHA2\n"); recall test4_expected_sha2_224; recall test4_expected_sha2_256; recall test4_expected_sha2_384; recall test4_expected_sha2_512; recall test4_plaintext; test_sha2 112ul test4_plaintext test4_expected_sha2_224 test4_expected_sha2_256 test4_expected_sha2_384 test4_expected_sha2_512; C.EXIT_SUCCESS
val main: unit -> St C.exit_code let main () =
true
null
false
C.String.print (C.String.of_literal "\nTEST 1. SHA2\n"); recall test1_expected_sha2_224; recall test1_expected_sha2_256; recall test1_expected_sha2_384; recall test1_expected_sha2_512; recall test1_plaintext; test_sha2 3ul test1_plaintext test1_expected_sha2_224 test1_expected_sha2_256 test1_expected_sha2_384 test1_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 2. SHA2\n"); recall test2_expected_sha2_224; recall test2_expected_sha2_256; recall test2_expected_sha2_384; recall test2_expected_sha2_512; recall test2_plaintext; test_sha2 0ul test2_plaintext test2_expected_sha2_224 test2_expected_sha2_256 test2_expected_sha2_384 test2_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 3. SHA2\n"); recall test3_expected_sha2_224; recall test3_expected_sha2_256; recall test3_expected_sha2_384; recall test3_expected_sha2_512; recall test3_plaintext; test_sha2 56ul test3_plaintext test3_expected_sha2_224 test3_expected_sha2_256 test3_expected_sha2_384 test3_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 4. SHA2\n"); recall test4_expected_sha2_224; recall test4_expected_sha2_256; recall test4_expected_sha2_384; recall test4_expected_sha2_512; recall test4_plaintext; test_sha2 112ul test4_plaintext test4_expected_sha2_224 test4_expected_sha2_256 test4_expected_sha2_384 test4_expected_sha2_512; C.EXIT_SUCCESS
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[]
[ "Prims.unit", "C.EXIT_SUCCESS", "C.exit_code", "Hacl.Test.SHA2.test_sha2", "FStar.UInt32.__uint_to_t", "Hacl.Test.SHA2.test4_plaintext", "Hacl.Test.SHA2.test4_expected_sha2_224", "Hacl.Test.SHA2.test4_expected_sha2_256", "Hacl.Test.SHA2.test4_expected_sha2_384", "Hacl.Test.SHA2.test4_expected_sha2_512", "Lib.Buffer.recall", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "C.String.print", "C.String.of_literal", "Hacl.Test.SHA2.test3_plaintext", "Hacl.Test.SHA2.test3_expected_sha2_224", "Hacl.Test.SHA2.test3_expected_sha2_256", "Hacl.Test.SHA2.test3_expected_sha2_384", "Hacl.Test.SHA2.test3_expected_sha2_512", "Hacl.Test.SHA2.test2_plaintext", "Hacl.Test.SHA2.test2_expected_sha2_224", "Hacl.Test.SHA2.test2_expected_sha2_256", "Hacl.Test.SHA2.test2_expected_sha2_384", "Hacl.Test.SHA2.test2_expected_sha2_512", "Hacl.Test.SHA2.test1_plaintext", "Hacl.Test.SHA2.test1_expected_sha2_224", "Hacl.Test.SHA2.test1_expected_sha2_256", "Hacl.Test.SHA2.test1_expected_sha2_384", "Hacl.Test.SHA2.test1_expected_sha2_512" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test4_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test4_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x8e; 0x95; 0x9b; 0x75; 0xda; 0xe3; 0x13; 0xda; 0x8c; 0xf4; 0xf7; 0x28; 0x14; 0xfc; 0x14; 0x3f; 0x8f; 0x77; 0x79; 0xc6; 0xeb; 0x9f; 0x7f; 0xa1; 0x72; 0x99; 0xae; 0xad; 0xb6; 0x88; 0x90; 0x18; 0x50; 0x1d; 0x28; 0x9e; 0x49; 0x00; 0xf7; 0xe4; 0x33; 0x1b; 0x99; 0xde; 0xc4; 0xb5; 0x43; 0x3a; 0xc7; 0xd3; 0x29; 0xee; 0xb6; 0xdd; 0x26; 0x54; 0x5e; 0x96; 0xe5; 0x5b; 0x87; 0x4b; 0xe9; 0x09]) in assert_norm (List.Tot.length l == 64); createL_mglobal l val main: unit -> St C.exit_code
false
false
Hacl.Test.SHA2.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 main: unit -> St C.exit_code
[]
Hacl.Test.SHA2.main
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.HyperStack.ST.St C.exit_code
{ "end_col": 16, "end_line": 333, "start_col": 2, "start_line": 281 }
FStar.HyperStack.ST.Stack
val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True)
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame()
val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 =
true
null
false
Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame (); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 msg msg_len (test224 <: lbuffer uint8 28ul); hash_256 msg msg_len (test256 <: lbuffer uint8 32ul); hash_384 msg msg_len (test384 <: lbuffer uint8 48ul); hash_512 msg msg_len (test512 <: lbuffer uint8 64ul); if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame ()
{ "checked_file": "Hacl.Test.SHA2.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[]
[ "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "C.exit", "FStar.Int32.__int_to_t", "Prims.bool", "Prims.op_Negation", "Lib.PrintBuffer.result_compare_display", "Lib.Buffer.to_const", "Lib.Buffer.MUT", "Hacl.Streaming.SHA2.hash_512", "Hacl.Streaming.SHA2.hash_384", "Hacl.Streaming.SHA2.hash_256", "Hacl.Streaming.SHA2.hash_224", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame", "FStar.Math.Lemmas.pow2_lt_compat" ]
[]
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True)
false
false
Hacl.Test.SHA2.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 test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True)
[]
Hacl.Test.SHA2.test_sha2
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> expected224: Lib.Buffer.lbuffer Lib.IntTypes.uint8 28ul -> expected256: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> expected384: Lib.Buffer.lbuffer Lib.IntTypes.uint8 48ul -> expected512: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 44, "start_col": 2, "start_line": 28 }
Prims.Tot
val hkdf_expand512:HK.expand_st Hash.SHA2_512
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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 hkdf_expand512 : HK.expand_st Hash.SHA2_512 = Hacl.HKDF.expand_sha2_512
val hkdf_expand512:HK.expand_st Hash.SHA2_512 let hkdf_expand512:HK.expand_st Hash.SHA2_512 =
false
null
false
Hacl.HKDF.expand_sha2_512
{ "checked_file": "Hacl.HPKE.Interface.HKDF.fst.checked", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ "total" ]
[ "Hacl.HKDF.expand_sha2_512" ]
[]
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **) inline_for_extraction noextract let hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256 inline_for_extraction noextract let hkdf_expand256 : HK.expand_st Hash.SHA2_256 = Hacl.HKDF.expand_sha2_256 inline_for_extraction noextract let hkdf_extract512 : HK.extract_st Hash.SHA2_512 = Hacl.HKDF.extract_sha2_512
false
true
Hacl.HPKE.Interface.HKDF.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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hkdf_expand512:HK.expand_st Hash.SHA2_512
[]
Hacl.HPKE.Interface.HKDF.hkdf_expand512
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.HKDF.expand_st Spec.Hash.Definitions.SHA2_512
{ "end_col": 75, "end_line": 33, "start_col": 50, "start_line": 33 }
Prims.Tot
val hkdf_extract512:HK.extract_st Hash.SHA2_512
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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 hkdf_extract512 : HK.extract_st Hash.SHA2_512 = Hacl.HKDF.extract_sha2_512
val hkdf_extract512:HK.extract_st Hash.SHA2_512 let hkdf_extract512:HK.extract_st Hash.SHA2_512 =
false
null
false
Hacl.HKDF.extract_sha2_512
{ "checked_file": "Hacl.HPKE.Interface.HKDF.fst.checked", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ "total" ]
[ "Hacl.HKDF.extract_sha2_512" ]
[]
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **) inline_for_extraction noextract let hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256 inline_for_extraction noextract let hkdf_expand256 : HK.expand_st Hash.SHA2_256 = Hacl.HKDF.expand_sha2_256
false
true
Hacl.HPKE.Interface.HKDF.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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hkdf_extract512:HK.extract_st Hash.SHA2_512
[]
Hacl.HPKE.Interface.HKDF.hkdf_extract512
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.HKDF.extract_st Spec.Hash.Definitions.SHA2_512
{ "end_col": 78, "end_line": 31, "start_col": 52, "start_line": 31 }
Prims.Tot
val hkdf_extract256:HK.extract_st Hash.SHA2_256
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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 hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256
val hkdf_extract256:HK.extract_st Hash.SHA2_256 let hkdf_extract256:HK.extract_st Hash.SHA2_256 =
false
null
false
Hacl.HKDF.extract_sha2_256
{ "checked_file": "Hacl.HPKE.Interface.HKDF.fst.checked", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ "total" ]
[ "Hacl.HKDF.extract_sha2_256" ]
[]
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **)
false
true
Hacl.HPKE.Interface.HKDF.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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hkdf_extract256:HK.extract_st Hash.SHA2_256
[]
Hacl.HPKE.Interface.HKDF.hkdf_extract256
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.HKDF.extract_st Spec.Hash.Definitions.SHA2_256
{ "end_col": 78, "end_line": 26, "start_col": 52, "start_line": 26 }
Prims.Tot
val hkdf_expand256:HK.expand_st Hash.SHA2_256
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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 hkdf_expand256 : HK.expand_st Hash.SHA2_256 = Hacl.HKDF.expand_sha2_256
val hkdf_expand256:HK.expand_st Hash.SHA2_256 let hkdf_expand256:HK.expand_st Hash.SHA2_256 =
false
null
false
Hacl.HKDF.expand_sha2_256
{ "checked_file": "Hacl.HPKE.Interface.HKDF.fst.checked", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ "total" ]
[ "Hacl.HKDF.expand_sha2_256" ]
[]
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **) inline_for_extraction noextract let hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256
false
true
Hacl.HPKE.Interface.HKDF.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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hkdf_expand256:HK.expand_st Hash.SHA2_256
[]
Hacl.HPKE.Interface.HKDF.hkdf_expand256
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.HKDF.expand_st Spec.Hash.Definitions.SHA2_256
{ "end_col": 75, "end_line": 28, "start_col": 50, "start_line": 28 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x
let symmetry #a (equals: (a -> a -> prop)) =
false
null
false
forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.l_imp", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here.
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val symmetry : equals: (_: a -> _: a -> Prims.prop) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.symmetry
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
equals: (_: a -> _: a -> Prims.prop) -> Prims.logical
{ "end_col": 33, "end_line": 62, "start_col": 2, "start_line": 61 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1)
let depends_only_on_0 (#heap #hprop: Type) (interp: (hprop -> heap -> prop)) (disjoint: (heap -> heap -> prop)) (join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap)) (q: (heap -> prop)) (fp: hprop) =
false
null
false
forall (h0: fp_heap_0 interp fp) (h1: heap{disjoint h0 h1}). q h0 <==> q (join h0 h1)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_heap_0", "Prims.l_iff", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val depends_only_on_0 : interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> q: (_: heap -> Prims.prop) -> fp: hprop -> Prims.logical
[]
Steel.Semantics.Hoare.MST.depends_only_on_0
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> q: (_: heap -> Prims.prop) -> fp: hprop -> Prims.logical
{ "end_col": 85, "end_line": 99, "start_col": 2, "start_line": 99 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z
let transitive #a (equals: (a -> a -> prop)) =
false
null
false
forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val transitive : equals: (_: a -> _: a -> Prims.prop) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.transitive
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
equals: (_: a -> _: a -> Prims.prop) -> Prims.logical
{ "end_col": 61, "end_line": 65, "start_col": 2, "start_line": 65 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y
let is_unit #a (x: a) (equals: (a -> a -> prop)) (f: (a -> a -> a)) =
false
null
false
forall y. {:pattern f x y\/f y x} (f x y) `equals` y /\ (f y x) `equals` y
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.l_and", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_unit : x: a -> equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.is_unit
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
x: a -> equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
{ "end_col": 20, "end_line": 78, "start_col": 2, "start_line": 76 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z
let associative #a (equals: (a -> a -> prop)) (f: (a -> a -> a)) =
false
null
false
forall x y z. (f x (f y z)) `equals` (f (f x y) z)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val associative : equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.associative
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
{ "end_col": 36, "end_line": 69, "start_col": 2, "start_line": 68 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h}
let fp_heap_0 (#heap #hprop: Type) (interp: (hprop -> heap -> prop)) (pre: hprop) =
false
null
false
h: heap{interp pre h}
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fp_heap_0 : interp: (_: hprop -> _: heap -> Prims.prop) -> pre: hprop -> Type
[]
Steel.Semantics.Hoare.MST.fp_heap_0
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
interp: (_: hprop -> _: heap -> Prims.prop) -> pre: hprop -> Type
{ "end_col": 22, "end_line": 89, "start_col": 2, "start_line": 89 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp
let fp_prop (#st: st0) (fp: st.hprop) =
false
null
false
fp_prop_0 st.interp st.disjoint st.join fp
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.fp_prop_0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fp_prop : fp: Mkst0?.hprop st -> Type
[]
Steel.Semantics.Hoare.MST.fp_prop
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
fp: Mkst0?.hprop st -> Type
{ "end_col": 44, "end_line": 173, "start_col": 2, "start_line": 173 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp}
let fp_prop_0 (#heap #hprop: Type) (interp: (hprop -> heap -> prop)) (disjoint: (heap -> heap -> prop)) (join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap)) (fp: hprop) =
false
null
false
p: (heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp}
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Steel.Semantics.Hoare.MST.depends_only_on_0" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fp_prop_0 : interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> fp: hprop -> Type
[]
Steel.Semantics.Hoare.MST.fp_prop_0
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> fp: hprop -> Type
{ "end_col": 67, "end_line": 109, "start_col": 2, "start_line": 109 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post}
let fp_prop2 (#st: st0) (#a: Type) (fp_pre: st.hprop) (fp_post: (a -> st.hprop)) =
false
null
false
q: (st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post}
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.depends_only_on2" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fp_prop2 : fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Type
[]
Steel.Semantics.Hoare.MST.fp_prop2
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Type
{ "end_col": 70, "end_line": 273, "start_col": 2, "start_line": 273 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post}
let fp_prop_0_2 (#a #heap #hprop: Type) (interp: (hprop -> heap -> prop)) (disjoint: (heap -> heap -> prop)) (join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap)) (fp_pre: hprop) (fp_post: (a -> hprop)) =
false
null
false
q: (heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post}
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Steel.Semantics.Hoare.MST.depends_only_on_0_2" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fp_prop_0_2 : interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> fp_pre: hprop -> fp_post: (_: a -> hprop) -> Type
[]
Steel.Semantics.Hoare.MST.fp_prop_0_2
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> fp_pre: hprop -> fp_post: (_: a -> hprop) -> Type
{ "end_col": 90, "end_line": 261, "start_col": 2, "start_line": 261 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let l_pre (#st:st) (pre:st.hprop) = fp_prop pre
let l_pre (#st: st) (pre: st.hprop) =
false
null
false
fp_prop pre
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.fp_prop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val l_pre : pre: Mkst0?.hprop st -> Type
[]
Steel.Semantics.Hoare.MST.l_pre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
pre: Mkst0?.hprop st -> Type
{ "end_col": 47, "end_line": 221, "start_col": 36, "start_line": 221 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s
let affine (st: st0) =
false
null
false
forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s)} st.interp (r0 `st.star` r1) s ==> st.interp r0 s
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h
false
true
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val affine : st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
[]
Steel.Semantics.Hoare.MST.affine
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
{ "end_col": 52, "end_line": 165, "start_col": 2, "start_line": 164 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let full_mem (st:st) = m:st.mem{st.full_mem_pred m}
let full_mem (st: st) =
false
null
false
m: st.mem{st.full_mem_pred m}
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__full_mem_pred" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****)
false
true
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val full_mem : st: Steel.Semantics.Hoare.MST.st -> Type
[]
Steel.Semantics.Hoare.MST.full_mem
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st -> Type
{ "end_col": 51, "end_line": 284, "start_col": 23, "start_line": 284 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp
let depends_only_on (#st: st0) (q: (st.mem -> prop)) (fp: st.hprop) =
false
null
false
depends_only_on_0 st.interp st.disjoint st.join q fp
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.depends_only_on_0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s ////////////////////////////////////////////////////////////////////////////////
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val depends_only_on : q: (_: Mkst0?.mem st -> Prims.prop) -> fp: Mkst0?.hprop st -> Prims.logical
[]
Steel.Semantics.Hoare.MST.depends_only_on
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
q: (_: Mkst0?.mem st -> Prims.prop) -> fp: Mkst0?.hprop st -> Prims.logical
{ "end_col": 54, "end_line": 170, "start_col": 2, "start_line": 170 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h
let stronger_post (#st: st) (#a: Type u#a) (post next_post: post_t st a) =
false
null
false
forall (x: a) (h: st.mem) (frame: st.hprop). st.interp ((next_post x) `st.star` frame) h ==> st.interp ((post x) `st.star` frame) h
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.post_t", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stronger_post : post: Steel.Semantics.Hoare.MST.post_t st a -> next_post: Steel.Semantics.Hoare.MST.post_t st a -> Prims.logical
[]
Steel.Semantics.Hoare.MST.stronger_post
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
post: Steel.Semantics.Hoare.MST.post_t st a -> next_post: Steel.Semantics.Hoare.MST.post_t st a -> Prims.logical
{ "end_col": 40, "end_line": 438, "start_col": 2, "start_line": 436 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
let action_t (#st: st) (#a: Type) (pre: st.hprop) (post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) =
false
null
false
frame: st.hprop -> Mst a (requires fun m0 -> st.interp ((pre `st.star` frame) `st.star` (st.locks_invariant m0)) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.post_preserves_frame" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val action_t : pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
[]
Steel.Semantics.Hoare.MST.action_t
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
{ "end_col": 42, "end_line": 322, "start_col": 4, "start_line": 315 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1)
let weakening_ok (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#wpre: st.hprop) (#wpost: post_t st a) (wlpre: l_pre wpre) (wlpost: l_post wpre wpost) =
false
null
false
weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Prims.l_and", "Steel.Semantics.Hoare.MST.weaker_pre", "Steel.Semantics.Hoare.MST.stronger_post", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val weakening_ok : lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> wlpre: Steel.Semantics.Hoare.MST.l_pre wpre -> wlpost: Steel.Semantics.Hoare.MST.l_post wpre wpost -> Prims.logical
[]
Steel.Semantics.Hoare.MST.weakening_ok
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> wlpre: Steel.Semantics.Hoare.MST.l_pre wpre -> wlpost: Steel.Semantics.Hoare.MST.l_post wpre wpost -> Prims.logical
{ "end_col": 52, "end_line": 455, "start_col": 2, "start_line": 452 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final
let stronger_lpost (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (#next_pre: st.hprop) #next_post (next_lpost: l_post next_pre next_post) (m0: st.mem) (m1: st.mem) =
false
null
false
forall (x: a) (h_final: st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_Forall", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stronger_lpost : lpost: Steel.Semantics.Hoare.MST.l_post pre post -> next_lpost: Steel.Semantics.Hoare.MST.l_post next_pre next_post -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
[]
Steel.Semantics.Hoare.MST.stronger_lpost
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpost: Steel.Semantics.Hoare.MST.l_post pre post -> next_lpost: Steel.Semantics.Hoare.MST.l_post next_pre next_post -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
{ "end_col": 32, "end_line": 618, "start_col": 2, "start_line": 616 }
Prims.Tot
val step_ens: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> step_result st a -> st.mem -> Type0
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1
val step_ens: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> step_result st a -> st.mem -> Type0 let step_ens (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 =
false
null
false
fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.step_result", "Prims.l_and", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.stronger_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.weaker_lpre", "Steel.Semantics.Hoare.MST.stronger_lpost" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_ens: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> step_result st a -> st.mem -> Type0
[]
Steel.Semantics.Hoare.MST.step_ens
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost -> _: Mkst0?.mem st -> _: Steel.Semantics.Hoare.MST.step_result st a -> _: Mkst0?.mem st -> Type0
{ "end_col": 41, "end_line": 639, "start_col": 4, "start_line": 631 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x
let commutative #a (equals: (a -> a -> prop)) (f: (a -> a -> a)) =
false
null
false
forall x y. {:pattern f x y} (f x y) `equals` (f y x)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val commutative : equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.commutative
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
{ "end_col": 24, "end_line": 73, "start_col": 2, "start_line": 72 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y
let equals_ext #a (equals: (a -> a -> prop)) (f: (a -> a -> a)) =
false
null
false
forall x1 x2 y. x1 `equals` x2 ==> (f x1 y) `equals` (f x2 y)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.l_imp", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val equals_ext : equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.equals_ext
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
equals: (_: a -> _: a -> Prims.prop) -> f: (_: a -> _: a -> a) -> Prims.logical
{ "end_col": 59, "end_line": 81, "start_col": 2, "start_line": 81 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0
let disjoint_sym (st: st0) =
false
null
false
forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric
false
true
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_sym : st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
[]
Steel.Semantics.Hoare.MST.disjoint_sym
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
{ "end_col": 56, "end_line": 136, "start_col": 2, "start_line": 136 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h
let interp_extensionality #r #s (equals: (r -> r -> prop)) (f: (r -> s -> prop)) =
false
null
false
forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 ////////////////////////////////////////////////////////////////////////////////
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val interp_extensionality : equals: (_: r -> _: r -> Prims.prop) -> f: (_: r -> _: s -> Prims.prop) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.interp_extensionality
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
equals: (_: r -> _: r -> Prims.prop) -> f: (_: r -> _: s -> Prims.prop) -> Prims.logical
{ "end_col": 74, "end_line": 161, "start_col": 2, "start_line": 161 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h))
let depends_only_on_0_2 (#a #heap #hprop: Type) (interp: (hprop -> heap -> prop)) (disjoint: (heap -> heap -> prop)) (join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap)) (q: (heap -> a -> heap -> prop)) (fp_pre: hprop) (fp_post: (a -> hprop)) =
false
null
false
(forall x (h_pre: fp_heap_0 interp fp_pre) h_post (h: heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ (forall x h_pre (h_post: fp_heap_0 interp (fp_post x)) (h: heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h))
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Prims.prop", "Prims.l_and", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_heap_0", "Prims.l_iff", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val depends_only_on_0_2 : interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> q: (_: heap -> _: a -> _: heap -> Prims.prop) -> fp_pre: hprop -> fp_post: (_: a -> hprop) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.depends_only_on_0_2
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> q: (_: heap -> _: a -> _: heap -> Prims.prop) -> fp_pre: hprop -> fp_post: (_: a -> hprop) -> Prims.logical
{ "end_col": 53, "end_line": 248, "start_col": 2, "start_line": 244 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_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 = s:st0 { st_laws s }
let st =
false
null
false
s: st0{st_laws s}
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.st_laws" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st
false
true
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val st : Type
[]
Steel.Semantics.Hoare.MST.st
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type
{ "end_col": 28, "end_line": 201, "start_col": 9, "start_line": 201 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post
let l_post (#st: st) (#a: Type) (pre: st.hprop) (post: post_t st a) =
false
null
false
fp_prop2 pre post
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.fp_prop2" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val l_post : pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> Type
[]
Steel.Semantics.Hoare.MST.l_post
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> Type
{ "end_col": 83, "end_line": 277, "start_col": 66, "start_line": 277 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post
let depends_only_on2 (#st: st0) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp_pre: st.hprop) (fp_post: (a -> st.hprop)) =
false
null
false
depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.depends_only_on_0_2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val depends_only_on2 : q: (_: Mkst0?.mem st -> _: a -> _: Mkst0?.mem st -> Prims.prop) -> fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Prims.logical
[]
Steel.Semantics.Hoare.MST.depends_only_on2
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
q: (_: Mkst0?.mem st -> _: a -> _: Mkst0?.mem st -> Prims.prop) -> fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Prims.logical
{ "end_col": 68, "end_line": 270, "start_col": 2, "start_line": 270 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_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_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1))
let post_preserves_frame (#st: st) (post frame: st.hprop) (m0 m1: st.mem) =
false
null
false
st.interp ((post `st.star` frame) `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame: fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1))
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_prop", "Prims.eq2", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val post_preserves_frame : post: Mkst0?.hprop st -> frame: Mkst0?.hprop st -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
[]
Steel.Semantics.Hoare.MST.post_preserves_frame
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
post: Mkst0?.hprop st -> frame: Mkst0?.hprop st -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
{ "end_col": 80, "end_line": 306, "start_col": 2, "start_line": 305 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
let action_t_tot (#st: st) (#a: Type) (pre: st.hprop) (post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) =
false
null
false
frame: st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` (st.locks_invariant m0)) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.post_preserves_frame" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val action_t_tot : pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
[]
Steel.Semantics.Hoare.MST.action_t_tot
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
{ "end_col": 42, "end_line": 338, "start_col": 4, "start_line": 331 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h
let weaker_pre (#st: st) (pre next_pre: st.hprop) =
false
null
false
forall (h: st.mem) (frame: st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val weaker_pre : pre: Mkst0?.hprop st -> next_pre: Mkst0?.hprop st -> Prims.logical
[]
Steel.Semantics.Hoare.MST.weaker_pre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
pre: Mkst0?.hprop st -> next_pre: Mkst0?.hprop st -> Prims.logical
{ "end_col": 42, "end_line": 433, "start_col": 2, "start_line": 431 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1)
let weaker_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#next_pre: st.hprop) (next_lpre: l_pre next_pre) (m0 m1: st.mem) =
false
null
false
lpre (st.core m0) ==> next_lpre (st.core m1)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val weaker_lpre : lpre: Steel.Semantics.Hoare.MST.l_pre pre -> next_lpre: Steel.Semantics.Hoare.MST.l_pre next_pre -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
[]
Steel.Semantics.Hoare.MST.weaker_lpre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> next_lpre: Steel.Semantics.Hoare.MST.l_pre next_pre -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
{ "end_col": 46, "end_line": 603, "start_col": 2, "start_line": 603 }
Prims.Tot
val step_req: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> Type0
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)
val step_req: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> Type0 let step_req (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost) : st.mem -> Type0 =
false
null
false
fun m0 -> st.interp ((pre `st.star` frame) `st.star` (st.locks_invariant m0)) m0 /\ lpre (st.core m0)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_req: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> Type0
[]
Steel.Semantics.Hoare.MST.step_req
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost -> _: Mkst0?.mem st -> Type0
{ "end_col": 21, "end_line": 593, "start_col": 4, "start_line": 591 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_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_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st
let st_laws (st: st0) =
false
null
false
symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ affine st /\ disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Prims.l_and", "Steel.Semantics.Hoare.MST.symmetry", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.transitive", "Steel.Semantics.Hoare.MST.interp_extensionality", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.associative", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.commutative", "Steel.Semantics.Hoare.MST.is_unit", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__emp", "Steel.Semantics.Hoare.MST.equals_ext", "Steel.Semantics.Hoare.MST.affine", "Steel.Semantics.Hoare.MST.disjoint_sym", "Steel.Semantics.Hoare.MST.disjoint_join", "Steel.Semantics.Hoare.MST.join_commutative", "Steel.Semantics.Hoare.MST.join_associative", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) =
false
true
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val st_laws : st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
[]
Steel.Semantics.Hoare.MST.st_laws
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
{ "end_col": 21, "end_line": 199, "start_col": 2, "start_line": 185 }
Steel.Semantics.Hoare.MST.MstTot
val get: #st: st -> Prims.unit -> MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get ()
val get: #st: st -> Prims.unit -> MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) let get (#st: st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) =
true
null
false
get ()
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Prims.unit", "FStar.NMSTTotal.get", "Steel.Semantics.Hoare.MST.full_mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_True", "Prims.l_and", "Prims.eq2" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get: #st: st -> Prims.unit -> MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
[]
Steel.Semantics.Hoare.MST.get
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
_: Prims.unit -> Steel.Semantics.Hoare.MST.MstTot (Steel.Semantics.Hoare.MST.full_mem st)
{ "end_col": 10, "end_line": 296, "start_col": 4, "start_line": 296 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0
let join_commutative (st: st0{disjoint_sym st}) =
false
null
false
forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.disjoint_sym", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.l_imp", "Prims.eq2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val join_commutative : st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_sym st} -> Prims.logical
[]
Steel.Semantics.Hoare.MST.join_commutative
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_sym st} -> Prims.logical
{ "end_col": 34, "end_line": 150, "start_col": 2, "start_line": 148 }
Prims.Tot
val frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h
val frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame) let frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame) =
false
null
false
fun h -> lpre h /\ f_frame h
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.fp_prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame)
[]
Steel.Semantics.Hoare.MST.frame_lpre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> f_frame: Steel.Semantics.Hoare.MST.fp_prop frame -> Steel.Semantics.Hoare.MST.l_pre (Mkst0?.star st pre frame)
{ "end_col": 30, "end_line": 359, "start_col": 2, "start_line": 359 }
Prims.Tot
val frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1
val frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame) let frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame) =
false
null
false
fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.fp_prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame)
[]
Steel.Semantics.Hoare.MST.frame_lpost
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> f_frame: Steel.Semantics.Hoare.MST.fp_prop frame -> Steel.Semantics.Hoare.MST.l_post (Mkst0?.star st pre frame) (fun x -> Mkst0?.star st (post x) frame)
{ "end_col": 55, "end_line": 372, "start_col": 2, "start_line": 372 }
Prims.Tot
val par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h
val par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR) let par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR) =
false
null
false
fun h -> lpreL h /\ lpreR h
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR)
[]
Steel.Semantics.Hoare.MST.par_lpre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> Steel.Semantics.Hoare.MST.l_pre (Mkst0?.star st preL preR)
{ "end_col": 29, "end_line": 412, "start_col": 2, "start_line": 412 }
Prims.Tot
val bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_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_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2)
val bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b let bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b =
false
null
false
fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.l_Exists", "Prims.prop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b
[]
Steel.Semantics.Hoare.MST.bind_lpost
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpre_a: Steel.Semantics.Hoare.MST.l_pre pre -> lpost_a: Steel.Semantics.Hoare.MST.l_post pre post_a -> lpost_b: (x: a -> Steel.Semantics.Hoare.MST.l_post (post_a x) post_b) -> Steel.Semantics.Hoare.MST.l_post pre post_b
{ "end_col": 83, "end_line": 400, "start_col": 2, "start_line": 400 }
FStar.Pervasives.Lemma
val commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q)))
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); }
val commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) let commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) =
false
null
true
calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); }
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.squash", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q)))
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q)))
[]
Steel.Semantics.Hoare.MST.commute_star_right
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> FStar.Pervasives.Lemma (ensures Mkst0?.equals st (Mkst0?.star st p (Mkst0?.star st q r)) (Mkst0?.star st p (Mkst0?.star st r q)))
{ "end_col": 3, "end_line": 696, "start_col": 2, "start_line": 692 }
FStar.Pervasives.Lemma
val assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s))))
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); }
val assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) let assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) =
false
null
true
calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); }
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.squash", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s))))
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s))))
[]
Steel.Semantics.Hoare.MST.assoc_star_right
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> FStar.Pervasives.Lemma (ensures Mkst0?.equals st (Mkst0?.star st p (Mkst0?.star st (Mkst0?.star st q r) s)) (Mkst0?.star st p (Mkst0?.star st q (Mkst0?.star st r s))))
{ "end_col": 3, "end_line": 708, "start_col": 2, "start_line": 703 }
FStar.Pervasives.Lemma
val commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s))))
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); }
val commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) let commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) =
false
null
true
calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); }
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.squash", "Steel.Semantics.Hoare.MST.assoc_star_right", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s))))
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s))))
[]
Steel.Semantics.Hoare.MST.commute_assoc_star_right
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> FStar.Pervasives.Lemma (ensures Mkst0?.equals st (Mkst0?.star st p (Mkst0?.star st (Mkst0?.star st q r) s)) (Mkst0?.star st p (Mkst0?.star st r (Mkst0?.star st q s))))
{ "end_col": 3, "end_line": 723, "start_col": 2, "start_line": 715 }
FStar.Pervasives.Lemma
val depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
val depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) let depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) =
false
null
true
assert (forall (h0: fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims._assert", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_heap_0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__emp", "Prims.unit", "Prims.l_and", "Steel.Semantics.Hoare.MST.depends_only_on", "Steel.Semantics.Hoare.MST.weaker_pre", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next)
[]
Steel.Semantics.Hoare.MST.depends_only_on_commutes_with_weaker
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
q: (_: Mkst0?.mem st -> Prims.prop) -> fp: Mkst0?.hprop st -> fp_next: Mkst0?.hprop st -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.depends_only_on q fp /\ Steel.Semantics.Hoare.MST.weaker_pre fp_next fp) (ensures Steel.Semantics.Hoare.MST.depends_only_on q fp_next)
{ "end_col": 91, "end_line": 774, "start_col": 2, "start_line": 774 }
FStar.Pervasives.Lemma
val depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
val depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) let depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) =
false
null
true
assert (forall (h0: fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims._assert", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_heap_0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__emp", "Prims.unit", "Prims.l_and", "Steel.Semantics.Hoare.MST.depends_only_on2", "Steel.Semantics.Hoare.MST.weaker_pre", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post)
[]
Steel.Semantics.Hoare.MST.depends_only_on2_commutes_with_weaker
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
q: (_: Mkst0?.mem st -> _: a -> _: Mkst0?.mem st -> Prims.prop) -> fp: Mkst0?.hprop st -> fp_next: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.depends_only_on2 q fp fp_post /\ Steel.Semantics.Hoare.MST.weaker_pre fp_next fp) (ensures Steel.Semantics.Hoare.MST.depends_only_on2 q fp_next fp_post)
{ "end_col": 91, "end_line": 787, "start_col": 2, "start_line": 787 }
FStar.Pervasives.Lemma
val commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s))
val commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0) let commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0) =
false
null
true
assert ((((p `st.star` q) `st.star` r) `st.star` s) `st.equals` ((p `st.star` (q `st.star` r)) `st.star` s))
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims._assert", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==>
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0)
[]
Steel.Semantics.Hoare.MST.commute_star_par_l
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> m0: Mkst0?.mem st -> FStar.Pervasives.Lemma (ensures Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st p q) r) s) m0 <==> Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st p (Mkst0?.star st q r)) s) m0)
{ "end_col": 54, "end_line": 730, "start_col": 4, "start_line": 729 }
FStar.Pervasives.Lemma
val equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r))
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; }
val equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) let equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) =
false
null
true
calc (st.equals) { p `st.star` q; (st.equals) { () } q `st.star` p; (st.equals) { () } r `st.star` p; (st.equals) { () } p `st.star` r; }
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r))
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r))
[]
Steel.Semantics.Hoare.MST.equals_ext_right
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> FStar.Pervasives.Lemma (requires Mkst0?.equals st q r) (ensures Mkst0?.equals st (Mkst0?.star st p q) (Mkst0?.star st p r))
{ "end_col": 3, "end_line": 685, "start_col": 2, "start_line": 677 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1
let disjoint_join (st: st0) =
false
null
false
forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.l_and", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0
false
true
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_join : st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
[]
Steel.Semantics.Hoare.MST.disjoint_join
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
{ "end_col": 34, "end_line": 145, "start_col": 2, "start_line": 139 }
Prims.Tot
val inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state
val inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre let inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre =
false
null
false
fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_Forall", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.prop", "Steel.Semantics.Hoare.MST.fp_prop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre
[]
Steel.Semantics.Hoare.MST.inst_heap_prop_for_par
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpost: Steel.Semantics.Hoare.MST.l_post pre post -> state: Mkst0?.mem st -> Steel.Semantics.Hoare.MST.fp_prop pre
{ "end_col": 41, "end_line": 819, "start_col": 2, "start_line": 816 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2
let join_associative (st: st0{disjoint_join st}) =
false
null
false
forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.disjoint_join", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.l_imp", "Prims.eq2", "Prims.logical" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val join_associative : st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_join st} -> Prims.logical
[]
Steel.Semantics.Hoare.MST.join_associative
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_join st} -> Prims.logical
{ "end_col": 60, "end_line": 156, "start_col": 2, "start_line": 153 }
FStar.Pervasives.Lemma
val frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state))
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f
val frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) let frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) =
false
null
true
frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.frame_post_for_par_aux", "Prims.unit", "Steel.Semantics.Hoare.MST.frame_post_for_par_tautology", "Prims.l_and", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.squash", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.l_Forall", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state))
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state))
[]
Steel.Semantics.Hoare.MST.frame_post_for_par
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
pre_s: Mkst0?.hprop st -> post_s: Mkst0?.hprop st -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> lpre_f: Steel.Semantics.Hoare.MST.l_pre pre_f -> lpost_f: Steel.Semantics.Hoare.MST.l_post pre_f post_f -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.post_preserves_frame post_s pre_f m0 m1 /\ Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st pre_s pre_f) (Mkst0?.locks_invariant st m0)) m0) (ensures (lpre_f (Mkst0?.core st m0) <==> lpre_f (Mkst0?.core st m1)) /\ (forall (x: a) (final_state: Mkst0?.mem st). lpost_f (Mkst0?.core st m0) x final_state <==> lpost_f (Mkst0?.core st m1) x final_state ))
{ "end_col": 51, "end_line": 866, "start_col": 2, "start_line": 865 }
FStar.Pervasives.Lemma
val commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; }
val commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0) let commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0) =
false
null
true
calc (st.equals) { ((p `st.star` q) `st.star` r) `st.star` s; (st.equals) { () } ((q `st.star` p) `st.star` r) `st.star` s; (st.equals) { () } (q `st.star` (p `st.star` r)) `st.star` s; }
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Prims.l_True", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==>
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0)
[]
Steel.Semantics.Hoare.MST.commute_star_par_r
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> m0: Mkst0?.mem st -> FStar.Pervasives.Lemma (ensures Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st p q) r) s) m0 <==> Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st q (Mkst0?.star st p r)) s) m0)
{ "end_col": 5, "end_line": 742, "start_col": 4, "start_line": 736 }
Steel.Semantics.Hoare.MST.Mst
val step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n)
val step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) let step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) =
true
null
false
NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Bind", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Bind__item__a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__pre", "Steel.Semantics.Hoare.MST.__proj__Bind__item__post_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpre_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpost_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__f", "FStar.Pervasives.Native.tuple2", "FStar.NMST.tape", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.step_bind_ret_aux", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
[]
Steel.Semantics.Hoare.MST.step_bind_ret
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)} -> Steel.Semantics.Hoare.MST.Mst (Steel.Semantics.Hoare.MST.step_result st a)
{ "end_col": 63, "end_line": 1086, "start_col": 2, "start_line": 1086 }
Prims.Tot
val return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h
val return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x) let return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x) =
false
null
false
fun h -> lpost h x h
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.l_pre" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x)
[]
Steel.Semantics.Hoare.MST.return_lpre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
x: a -> lpost: Steel.Semantics.Hoare.MST.l_post (post x) post -> Steel.Semantics.Hoare.MST.l_pre (post x)
{ "end_col": 22, "end_line": 354, "start_col": 2, "start_line": 354 }
FStar.MST.MSTATE
val step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0)
val step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) let step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) =
true
null
false
M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Bind", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Bind__item__a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__pre", "Steel.Semantics.Hoare.MST.__proj__Bind__item__post_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpre_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpost_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__f", "Steel.Semantics.Hoare.MST.full_mem", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.Step", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
[]
Steel.Semantics.Hoare.MST.step_bind_ret_aux
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)} -> FStar.MST.MSTATE (Steel.Semantics.Hoare.MST.step_result st a)
{ "end_col": 57, "end_line": 1073, "start_col": 2, "start_line": 1070 }
Prims.Tot
val bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_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_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1)
val bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre let bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre =
false
null
false
fun h -> lpre_a h /\ (forall (x: a) h1. lpost_a h x h1 ==> lpre_b x h1)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "Prims.prop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre
[]
Steel.Semantics.Hoare.MST.bind_lpre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpre_a: Steel.Semantics.Hoare.MST.l_pre pre -> lpost_a: Steel.Semantics.Hoare.MST.l_post pre post_a -> lpre_b: (x: a -> Steel.Semantics.Hoare.MST.l_pre (post_a x)) -> Steel.Semantics.Hoare.MST.l_pre pre
{ "end_col": 72, "end_line": 386, "start_col": 2, "start_line": 386 }
Prims.Tot
val par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR))
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1
val par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR)) let par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR)) =
false
null
false
fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR))
[]
Steel.Semantics.Hoare.MST.par_lpost
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpostL: Steel.Semantics.Hoare.MST.l_post preL postL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> lpostR: Steel.Semantics.Hoare.MST.l_post preR postR -> Steel.Semantics.Hoare.MST.l_post (Mkst0?.star st preL preR) (fun _ -> (let FStar.Pervasives.Native.Mktuple2 #_ #_ xL xR = _ in Mkst0?.star st (postL xL) (postR xR)) <: Mkst0?.hprop st)
{ "end_col": 82, "end_line": 428, "start_col": 2, "start_line": 428 }
Steel.Semantics.Hoare.MST.Mst
val step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_par_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_par_ret_aux frame f, n)
val step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) let step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) =
true
null
false
NMSTATE?.reflect (fun (_, n) -> step_par_ret_aux frame f, n)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Par", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Par__item__aL", "Steel.Semantics.Hoare.MST.__proj__Par__item__preL", "Steel.Semantics.Hoare.MST.__proj__Par__item__postL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostL", "Steel.Semantics.Hoare.MST.__proj__Par__item__mL", "Steel.Semantics.Hoare.MST.__proj__Par__item__aR", "Steel.Semantics.Hoare.MST.__proj__Par__item__preR", "Steel.Semantics.Hoare.MST.__proj__Par__item__postR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostR", "Steel.Semantics.Hoare.MST.__proj__Par__item__mR", "FStar.Pervasives.Native.tuple2", "FStar.NMST.tape", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.step_par_ret_aux", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0) let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n) let step_frame (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Frame (Ret _ _ _) _ _ -> step_frame_ret frame f | Frame #_ #_ #f_pre #_ #_ #_ f frame' f_frame' -> let m0 = get () in //To go from: // f_pre * frame' * frame * st.locks_invariant m0 to // f_pre * (frame' * frame) * st.locks_invariant m0 commute_star_par_l f_pre frame' frame (st.locks_invariant m0) m0; let Step next_fpre next_fpost next_flpre next_flpost f = step (frame' `st.star` frame) f in let m1 = get () in //To go in the other direction on the output memory m1 commute_star_par_l next_fpre frame' frame (st.locks_invariant m1) m1; Step (next_fpre `st.star` frame') (fun x -> next_fpost x `st.star` frame') (frame_lpre next_flpre f_frame') (frame_lpost next_flpre next_flpost f_frame') (Frame f frame' f_frame') let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Par #_ #aL #_ #_ #_ #_ (Ret pL xL lpL) #aR #_ #_ #_ #_ (Ret pR xR lpR) -> let lpost : l_post #st #(aL & aR) (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) = fun h0 (xL, xR) h1 -> lpL h0 xL h1 /\ lpR h0 xR h1 in Step (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) (fun h -> lpL h xL h /\ lpR h xR h) lpost (Ret (fun (xL, xR) -> pL xL `st.star` pR xR) (xL, xR) lpost), m0) let step_par_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
[]
Steel.Semantics.Hoare.MST.step_par_ret
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)} -> Steel.Semantics.Hoare.MST.Mst (Steel.Semantics.Hoare.MST.step_result st a)
{ "end_col": 62, "end_line": 1239, "start_col": 2, "start_line": 1239 }
FStar.MST.MSTATE
val step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0)
val step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) let step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) =
true
null
false
M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step ((p x) `st.star` frame') (fun x -> (p x) `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> (p x) `st.star` frame') x lpost), m0)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Frame", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Frame__item__a", "Steel.Semantics.Hoare.MST.__proj__Frame__item__pre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__post", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpost", "Steel.Semantics.Hoare.MST.__proj__Frame__item__f", "Steel.Semantics.Hoare.MST.full_mem", "Steel.Semantics.Hoare.MST.fp_prop", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.Step", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.Ret", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
[]
Steel.Semantics.Hoare.MST.step_frame_ret_aux
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)} -> FStar.MST.MSTATE (Steel.Semantics.Hoare.MST.step_result st a)
{ "end_col": 58, "end_line": 1151, "start_col": 2, "start_line": 1145 }
FStar.MST.MSTATE
val step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Par #_ #aL #_ #_ #_ #_ (Ret pL xL lpL) #aR #_ #_ #_ #_ (Ret pR xR lpR) -> let lpost : l_post #st #(aL & aR) (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) = fun h0 (xL, xR) h1 -> lpL h0 xL h1 /\ lpR h0 xR h1 in Step (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) (fun h -> lpL h xL h /\ lpR h xR h) lpost (Ret (fun (xL, xR) -> pL xL `st.star` pR xR) (xL, xR) lpost), m0)
val step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) let step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) =
true
null
false
M.MSTATE?.reflect (fun m0 -> match f with | Par #_ #aL #_ #_ #_ #_ (Ret pL xL lpL) #aR #_ #_ #_ #_ (Ret pR xR lpR) -> let lpost:l_post #st #(aL & aR) ((pL xL) `st.star` (pR xR)) (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) = fun h0 (xL, xR) h1 -> lpL h0 xL h1 /\ lpR h0 xR h1 in Step ((pL xL) `st.star` (pR xR)) (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) (fun h -> lpL h xL h /\ lpR h xR h) lpost (Ret (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) (xL, xR) lpost), m0)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Par", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Par__item__aL", "Steel.Semantics.Hoare.MST.__proj__Par__item__preL", "Steel.Semantics.Hoare.MST.__proj__Par__item__postL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostL", "Steel.Semantics.Hoare.MST.__proj__Par__item__mL", "Steel.Semantics.Hoare.MST.__proj__Par__item__aR", "Steel.Semantics.Hoare.MST.__proj__Par__item__preR", "Steel.Semantics.Hoare.MST.__proj__Par__item__postR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostR", "Steel.Semantics.Hoare.MST.__proj__Par__item__mR", "Steel.Semantics.Hoare.MST.full_mem", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.Step", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.Ret", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0) let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n) let step_frame (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Frame (Ret _ _ _) _ _ -> step_frame_ret frame f | Frame #_ #_ #f_pre #_ #_ #_ f frame' f_frame' -> let m0 = get () in //To go from: // f_pre * frame' * frame * st.locks_invariant m0 to // f_pre * (frame' * frame) * st.locks_invariant m0 commute_star_par_l f_pre frame' frame (st.locks_invariant m0) m0; let Step next_fpre next_fpost next_flpre next_flpost f = step (frame' `st.star` frame) f in let m1 = get () in //To go in the other direction on the output memory m1 commute_star_par_l next_fpre frame' frame (st.locks_invariant m1) m1; Step (next_fpre `st.star` frame') (fun x -> next_fpost x `st.star` frame') (frame_lpre next_flpre f_frame') (frame_lpost next_flpre next_flpost f_frame') (Frame f frame' f_frame') let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
[]
Steel.Semantics.Hoare.MST.step_par_ret_aux
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)} -> FStar.MST.MSTATE (Steel.Semantics.Hoare.MST.step_result st a)
{ "end_col": 73, "end_line": 1226, "start_col": 2, "start_line": 1213 }
Prims.Tot
val lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1
val lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post let lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post =
false
null
false
fun _ x h1 -> lpost (st.core state) x h1
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "total" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.prop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post
[]
Steel.Semantics.Hoare.MST.lpost_ret_act
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpost: Steel.Semantics.Hoare.MST.l_post pre post -> x: a -> state: Mkst0?.mem st -> Steel.Semantics.Hoare.MST.l_post (post x) post
{ "end_col": 42, "end_line": 1034, "start_col": 2, "start_line": 1034 }
FStar.Pervasives.Lemma
val stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in ()
val stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h) let stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h) =
false
null
true
let aux xL xR frame h : Lemma (requires st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h) (ensures st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { ((postL xL) `st.star` (next_postR xR)) `st.star` frame; (st.equals) { () } ((next_postR xR) `st.star` (postL xL)) `st.star` frame; (st.equals) { () } (next_postR xR) `st.star` ((postL xL) `st.star` frame); }; assert (st.interp ((next_postR xR) `st.star` ((postL xL) `st.star` frame)) h); assert (st.interp ((postR xR) `st.star` ((postL xL) `st.star` frame)) h); calc (st.equals) { (postR xR) `st.star` ((postL xL) `st.star` frame); (st.equals) { () } ((postR xR) `st.star` (postL xL)) `st.star` frame; (st.equals) { () } ((postL xL) `st.star` (postR xR)) `st.star` frame; } in ()
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.unit", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims._assert", "Steel.Semantics.Hoare.MST.stronger_post", "Prims.l_Forall", "Prims.l_imp" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==>
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h)
[]
Steel.Semantics.Hoare.MST.stronger_post_par_r
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
postL: Steel.Semantics.Hoare.MST.post_t st aL -> postR: Steel.Semantics.Hoare.MST.post_t st aR -> next_postR: Steel.Semantics.Hoare.MST.post_t st aR -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.stronger_post postR next_postR) (ensures forall (xL: aL) (xR: aR) (frame: Mkst0?.hprop st) (h: Mkst0?.mem st). Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (postL xL) (next_postR xR)) frame) h ==> Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (postL xL) (postR xR)) frame) h)
{ "end_col": 4, "end_line": 1003, "start_col": 5, "start_line": 979 }
Steel.Semantics.Hoare.MST.Mst
val step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n)
val step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) let step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) =
true
null
false
NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n)
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Frame", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Frame__item__a", "Steel.Semantics.Hoare.MST.__proj__Frame__item__pre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__post", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpost", "Steel.Semantics.Hoare.MST.__proj__Frame__item__f", "FStar.Pervasives.Native.tuple2", "FStar.NMST.tape", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.step_frame_ret_aux", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0) let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
[]
Steel.Semantics.Hoare.MST.step_frame_ret
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)} -> Steel.Semantics.Hoare.MST.Mst (Steel.Semantics.Hoare.MST.step_result st a)
{ "end_col": 64, "end_line": 1164, "start_col": 2, "start_line": 1164 }
FStar.Pervasives.Lemma
val par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ])
val par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) let par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) =
false
null
true
frame_post_for_par preL next_preL state next_state lpreR lpostR; FStar.Tactics.Effect.assert_by_tactic (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) (fun _ -> (); (norm [delta_only [`%weaker_lpre; `%par_lpre]]))
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "FStar.Tactics.Effect.assert_by_tactic", "Steel.Semantics.Hoare.MST.weaker_lpre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.par_lpre", "Prims.unit", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Steel.Semantics.Hoare.MST.frame_post_for_par", "Prims.l_and", "Steel.Semantics.Hoare.MST.stronger_lpost", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.squash", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.par_lpost", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
[]
Steel.Semantics.Hoare.MST.par_weaker_lpre_and_stronger_lpost_l
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpostL: Steel.Semantics.Hoare.MST.l_post preL postL -> next_lpreL: Steel.Semantics.Hoare.MST.l_pre next_preL -> next_lpostL: Steel.Semantics.Hoare.MST.l_post next_preL next_postL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> lpostR: Steel.Semantics.Hoare.MST.l_post preR postR -> state: Mkst0?.mem st -> next_state: Mkst0?.mem st -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.weaker_lpre lpreL next_lpreL state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost lpostL next_lpostL state next_state /\ Steel.Semantics.Hoare.MST.post_preserves_frame next_preL preR state next_state /\ lpreL (Mkst0?.core st state) /\ lpreR (Mkst0?.core st state) /\ Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st preL preR) (Mkst0?.locks_invariant st state)) state) (ensures Steel.Semantics.Hoare.MST.weaker_lpre (Steel.Semantics.Hoare.MST.par_lpre lpreL lpreR) (Steel.Semantics.Hoare.MST.par_lpre next_lpreL lpreR) state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost (Steel.Semantics.Hoare.MST.par_lpost lpreL lpostL lpreR lpostR) (Steel.Semantics.Hoare.MST.par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
{ "end_col": 52, "end_line": 908, "start_col": 2, "start_line": 906 }
FStar.Pervasives.Lemma
val par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state
val par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) let par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) =
false
null
true
calc (st.equals) { ((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state); (st.equals) { () } ((preR `st.star` preL) `st.star` frame) `st.star` (st.locks_invariant state); (st.equals) { () } (preR `st.star` preL) `st.star` (frame `st.star` (st.locks_invariant state)); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` (st.locks_invariant state)) ((st.locks_invariant state) `st.star` frame) } (preR `st.star` preL) `st.star` ((st.locks_invariant state) `st.star` frame); (st.equals) { () } ((preR `st.star` preL) `st.star` (st.locks_invariant state)) `st.star` frame; }; assert (st.interp ((preR `st.star` preL) `st.star` (st.locks_invariant state)) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; FStar.Tactics.Effect.assert_by_tactic (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) (fun _ -> (); (norm [delta_only [`%weaker_lpre; `%par_lpre]])); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state
{ "checked_file": "Steel.Semantics.Hoare.MST.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ "lemma" ]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.commute_star_par_r", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Steel.Semantics.Hoare.MST.weaker_lpre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.par_lpre", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Steel.Semantics.Hoare.MST.frame_post_for_par", "Prims._assert", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.l_and", "Steel.Semantics.Hoare.MST.stronger_lpost", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.par_lpost", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
false
false
Steel.Semantics.Hoare.MST.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
[]
Steel.Semantics.Hoare.MST.par_weaker_lpre_and_stronger_lpost_r
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpostL: Steel.Semantics.Hoare.MST.l_post preL postL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> lpostR: Steel.Semantics.Hoare.MST.l_post preR postR -> next_lpreR: Steel.Semantics.Hoare.MST.l_pre next_preR -> next_lpostR: Steel.Semantics.Hoare.MST.l_post next_preR next_postR -> frame: Mkst0?.hprop st -> state: Mkst0?.mem st -> next_state: Mkst0?.mem st -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.weaker_lpre lpreR next_lpreR state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost lpostR next_lpostR state next_state /\ Steel.Semantics.Hoare.MST.post_preserves_frame next_preR (Mkst0?.star st preL frame) state next_state /\ lpreR (Mkst0?.core st state) /\ lpreL (Mkst0?.core st state) /\ Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st preL preR) frame) (Mkst0?.locks_invariant st state)) state) (ensures Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st preL next_preR) frame) (Mkst0?.locks_invariant st next_state)) next_state /\ Steel.Semantics.Hoare.MST.weaker_lpre (Steel.Semantics.Hoare.MST.par_lpre lpreL lpreR) (Steel.Semantics.Hoare.MST.par_lpre lpreL next_lpreR) state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost (Steel.Semantics.Hoare.MST.par_lpost lpreL lpostL lpreR lpostR) (Steel.Semantics.Hoare.MST.par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
{ "end_col": 84, "end_line": 964, "start_col": 2, "start_line": 947 }
FStar.Pervasives.Lemma
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let expand_key_128_reveal = opaque_revealer (`%expand_key_128) expand_key_128 expand_key_128_def
let expand_key_128_reveal =
false
null
true
opaque_revealer (`%expand_key_128) expand_key_128 expand_key_128_def
{ "checked_file": "Vale.AES.AES_helpers.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ "lemma" ]
[ "Vale.Def.Opaque_s.opaque_revealer", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Prims.nat", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.AES_common_s.AES_128", "Prims.l_True", "Vale.AES.AES_helpers.expand_key_128", "Vale.AES.AES_helpers.expand_key_128_def" ]
[]
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1)) let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3] else round_key_128 (expand_key_128_def key (round - 1)) round
false
false
Vale.AES.AES_helpers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val expand_key_128_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.AES_helpers.expand_key_128 == Vale.AES.AES_helpers.expand_key_128_def)
[]
Vale.AES.AES_helpers.expand_key_128_reveal
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.AES_helpers.expand_key_128 == Vale.AES.AES_helpers.expand_key_128_def)
{ "end_col": 108, "end_line": 43, "start_col": 40, "start_line": 43 }
Prims.Pure
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let expand_key_128 = opaque_make expand_key_128_def
let expand_key_128 =
false
null
false
opaque_make expand_key_128_def
{ "checked_file": "Vale.AES.AES_helpers.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[]
[ "Vale.Def.Opaque_s.opaque_make", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Prims.nat", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.AES_common_s.AES_128", "Prims.l_True", "Vale.AES.AES_helpers.expand_key_128_def" ]
[]
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1)) let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3]
false
false
Vale.AES.AES_helpers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val expand_key_128 : key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> round: Prims.nat -> Prims.Pure Vale.Def.Types_s.quad32
[]
Vale.AES.AES_helpers.expand_key_128
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> round: Prims.nat -> Prims.Pure Vale.Def.Types_s.quad32
{ "end_col": 70, "end_line": 42, "start_col": 40, "start_line": 42 }
Prims.Tot
val round_key_128 (prev: quad32) (round: nat) : quad32
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1))
val round_key_128 (prev: quad32) (round: nat) : quad32 let round_key_128 (prev: quad32) (round: nat) : quad32 =
false
null
false
round_key_128_rcon prev (aes_rcon (round - 1))
{ "checked_file": "Vale.AES.AES_helpers.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.AES.AES_helpers.round_key_128_rcon", "Vale.AES.AES_common_s.aes_rcon", "Prims.op_Subtraction" ]
[]
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3
false
true
Vale.AES.AES_helpers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val round_key_128 (prev: quad32) (round: nat) : quad32
[]
Vale.AES.AES_helpers.round_key_128
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
prev: Vale.Def.Types_s.quad32 -> round: Prims.nat -> Vale.Def.Types_s.quad32
{ "end_col": 48, "end_line": 34, "start_col": 2, "start_line": 34 }
Prims.Tot
val simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let simd_round_key_128 (prev:quad32) (rcon:nat32) : quad32 = let r = rot_word_LE (sub_word prev.hi3) *^ rcon in let q = prev in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in q *^^ Mkfour r r r r
val simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32 let simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32 =
false
null
false
let r = rot_word_LE (sub_word prev.hi3) *^ rcon in let q = prev in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in q *^^ Mkfour r r r r
{ "checked_file": "Vale.AES.AES_helpers.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.AES.AES_helpers.op_Star_Hat_Hat", "Vale.Def.Words_s.Mkfour", "Vale.AES.AES_helpers.quad32_shl32", "Vale.Def.Words_s.nat32", "Vale.AES.AES_helpers.op_Star_Hat", "Vale.AES.AES_s.rot_word_LE", "Vale.AES.AES_common_s.sub_word", "Vale.Def.Words_s.__proj__Mkfour__item__hi3" ]
[]
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1)) let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3] else round_key_128 (expand_key_128_def key (round - 1)) round [@"opaque_to_smt"] let expand_key_128 = opaque_make expand_key_128_def irreducible let expand_key_128_reveal = opaque_revealer (`%expand_key_128) expand_key_128 expand_key_128_def val lemma_expand_key_128_0 (key:aes_key_LE AES_128) : Lemma (equal key (expand_key AES_128 key 4)) val lemma_expand_key_128_i (key:aes_key_LE AES_128) (i:nat) : Lemma (requires 0 < i /\ i < 11 ) (ensures ( let m = 4 * (i - 1) in let n = 4 * i in let v = expand_key AES_128 key n in let w = expand_key AES_128 key (n + 4) in let prev = Mkfour v.[m + 0] v.[m + 1] v.[m + 2] v.[m + 3] in round_key_128 prev i == Mkfour w.[n + 0] w.[n + 1] w.[n + 2] w.[n + 3] )) // expand_key for large 'size' argument agrees with expand_key for smaller 'size' argument val lemma_expand_append (key:aes_key_LE AES_128) (size1:nat) (size2:nat) : Lemma (requires size1 <= size2 /\ size2 <= 44) (ensures equal (expand_key AES_128 key size1) (slice (expand_key AES_128 key size2) 0 size1)) (decreases size2) // quad32 key expansion is equivalent to nat32 key expansion val lemma_expand_key_128 (key:seq nat32) (size:nat) : Lemma (requires size <= 11 /\ is_aes_key_LE AES_128 key) (ensures ( let s = key_schedule_to_round_keys size (expand_key AES_128 key 44) in (forall (i:nat).{:pattern (expand_key_128 key i) \/ (expand_key_128_def key i)} i < size ==> expand_key_128 key i == s.[i]) ))
false
true
Vale.AES.AES_helpers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32
[]
Vale.AES.AES_helpers.simd_round_key_128
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
prev: Vale.Def.Types_s.quad32 -> rcon: Vale.Def.Types_s.nat32 -> Vale.Def.Types_s.quad32
{ "end_col": 22, "end_line": 83, "start_col": 60, "start_line": 77 }
Prims.Tot
val round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3
val round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32 let round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32 =
false
null
false
let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3
{ "checked_file": "Vale.AES.AES_helpers.fsti.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Words_s.nat32", "Vale.AES.AES_helpers.op_Star_Hat", "Vale.AES.AES_common_s.sub_word", "Vale.AES.AES_s.rot_word_LE" ]
[]
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent.
false
true
Vale.AES.AES_helpers.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32
[]
Vale.AES.AES_helpers.round_key_128_rcon
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
prev: Vale.Def.Types_s.quad32 -> rcon: Vale.Def.Types_s.nat32 -> Vale.Def.Types_s.quad32
{ "end_col": 20, "end_line": 31, "start_col": 60, "start_line": 25 }