(*Require Import VST.concurrency.cl_step_lemmas. Require Import VST.concurrency.resource_decay_lemmas. Require Import VST.concurrency.resource_decay_join.*)
Local Arguments getThreadR {_} {_} {_} _ _ _.
Local Arguments getThreadC {_} {_} {_} _ _ _.
Local Arguments personal_mem : clear implicits.
Local Arguments updThread {_} {_} {_} _ _ _ _ _.
Local Arguments updThreadR {_} {_} {_} _ _ _ _.
Local Arguments updThreadC {_} {_} {_} _ _ _ _.
Local Arguments juicyRestrict : clear implicits.
Set Bullet Behavior "Strict Subproofs".
Open Scope string_scope.
(* to make the proof faster, we avoid unfolding of those definitions *)
Definition Jspec'_juicy_mem_equiv_def CS ext_link :=
ext_spec_stable juicy_mem_equiv (JE_spec _ ( @OK_spec (Concurrent_Espec unit CS ext_link))).
Definition Jspec'_hered_def CS ext_link :=
ext_spec_stable age (JE_spec _ ( @OK_spec (Concurrent_Espec unit CS ext_link))).

(* Specifications: *)
(* Weaker statement than preservation for makelock, enough to prove safety *)
Lemma safety_induction_makelock ge Gamma n state
(CS : compspecs)
(ext_link : string -> ident)
(ext_link_inj : forall s1 s2, ext_link s1 = ext_link s2 -> s1 = s2)
(Jspec' := @OK_spec (Concurrent_Espec unit CS ext_link))
(Jspec'_juicy_mem_equiv : Jspec'_juicy_mem_equiv_def CS ext_link)
(Jspec'_hered : Jspec'_hered_def CS ext_link)
(personal_mem_equiv_spec :
forall (m m' : Mem.mem') (phi : rmap) (pr : mem_cohere' m phi) (pr' : mem_cohere' m' phi),
Mem.nextblock m = Mem.nextblock m' ->
(forall loc : address, max_access_at m loc = max_access_at m' loc) ->
(forall loc : AV.address, isVAL (phi @ loc) -> contents_at m loc = contents_at m' loc) ->
mem_equiv (m_dry (personal_mem m phi pr)) (m_dry (personal_mem m' phi pr'))) :
blocked_at_external state MKLOCK ->
state_invariant Jspec' Gamma (S n) state ->
exists state',
state_step(ge := ge) state state' /\
(state_invariant Jspec' Gamma n state' \/
state_invariant Jspec' Gamma (S n) state').
Lemma safety_induction_release ge Gamma n state
(CS : compspecs)
(ext_link : string -> ident)
(ext_link_inj : forall s1 s2, ext_link s1 = ext_link s2 -> s1 = s2)
(Jspec' := @OK_spec (Concurrent_Espec unit CS ext_link))
(Jspec'_juicy_mem_equiv : Jspec'_juicy_mem_equiv_def CS ext_link)
(Jspec'_hered : Jspec'_hered_def CS ext_link)
(personal_mem_equiv_spec :
forall (m m' : Mem.mem') (phi : rmap) (pr : mem_cohere' m phi) (pr' : mem_cohere' m' phi),
Mem.nextblock m = Mem.nextblock m' ->
(forall loc : address, max_access_at m loc = max_access_at m' loc) ->
(forall loc : AV.address, isVAL (phi @ loc) -> contents_at m loc = contents_at m' loc) ->
mem_equiv (m_dry (personal_mem m phi pr)) (m_dry (personal_mem m' phi pr'))) :
blocked_at_external state UNLOCK ->
state_invariant Jspec' Gamma (S n) state ->
exists state',
state_step(ge := ge) state state' /\
(state_invariant Jspec' Gamma n state' \/
state_invariant Jspec' Gamma (S n) state').
Lemma shape_of_args2 (F V : Type) (args : list val) v (ge : Genv.t F V) :
Val.has_type_list args (sig_args (ef_sig CREATE)) ->
v <> Vundef ->
v =
eval_id _args (make_ext_args (filter_genv (symb2genv (genv_symb_injective ge))) (_f :: _args :: nil) args) ->
exists arg1, args = arg1 :: v :: nil.
Lemma shape_of_args3 (F V : Type) (args : list val) v (ge : Genv.t F V) :
Val.has_type_list args (sig_args (ef_sig CREATE)) ->
v <> Vundef ->
v =
eval_id _f (make_ext_args (filter_genv (symb2genv (genv_symb_injective ge))) (_f :: _args :: nil) args) ->
exists arg2, args = v :: arg2 :: nil.
Lemma lock_coherence_age_to ge n m (tp : jstate ge) Phi :
lock_coherence (lset tp) Phi m ->
lock_coherence (AMap.map (option_map (age_to n)) (lset tp)) (age_to n Phi) m.
Lemma func_at_func_at'' fs loc phi :
seplog.func_at fs loc phi =
match fs with mk_funspec fsig cc A P Q _ _ => func_at'' fsig cc A P Q loc phi end.
Lemma cond_approx_eq_app n A P1 P2 phi :
cond_approx_eq n A P1 P2 ->
(level phi < n)%nat ->
forall ts y z,
app_pred (P1 ts (fmap (rmaps.dependent_type_functor_rec ts A) (approx n) (approx n) y) z) phi ->
app_pred (P2 ts (fmap (rmaps.dependent_type_functor_rec ts A) (approx n) (approx n) y) z) phi.
Lemma prop_app_pred {A} `{_ : ageable A} (P : Prop) (phi : A) : P -> app_pred (!! P) phi.
Lemma safety_induction_spawn ge Gamma n state
(CS : compspecs)
(ext_link : string -> ident)
(ext_link_inj : forall s1 s2, ext_link s1 = ext_link s2 -> s1 = s2)
(Jspec' := @OK_spec (Concurrent_Espec unit CS ext_link))
(Jspec'_juicy_mem_equiv : Jspec'_juicy_mem_equiv_def CS ext_link)
(Jspec'_hered : Jspec'_hered_def CS ext_link)
(personal_mem_equiv_spec :
forall (m m' : Mem.mem') (phi : rmap) (pr : mem_cohere' m phi) (pr' : mem_cohere' m' phi),
Mem.nextblock m = Mem.nextblock m' ->
(forall loc : address, max_access_at m loc = max_access_at m' loc) ->
(forall loc : AV.address, isVAL (phi @ loc) -> contents_at m loc = contents_at m' loc) ->
mem_equiv (m_dry (personal_mem m phi pr)) (m_dry (personal_mem m' phi pr'))) :
blocked_at_external state CREATE ->
state_invariant Jspec' Gamma (S n) state ->
exists state',
state_step(ge := ge) state state' /\
(state_invariant Jspec' Gamma n state' \/
state_invariant Jspec' Gamma (S n) state').