Section InternalSteps.
Context {Sem : Semantics}
{SemAx : SemAxioms}
{SemD : SemDet}.
Notation schedule := (seq nat).
Existing Instance OrdinalPool.OrdinalThreadPool.
Existing Instance dryResources.
Existing Instance DryHybridMachineSig.
(** Internal steps are just thread coresteps or resume steps or start steps, they mimic fine-grained internal steps *)
Definition internal_step {tid} {tp} m (cnt: containsThread tp tid)
(Hcomp: mem_compatible tp m) tp' m' :=
(exists ev, threadStep cnt Hcomp tp' m' ev) \/
(resume_thread m cnt tp' /\ m = m') \/
(start_thread m cnt tp' m').
(* For now we don't emit events from internal_execution*)
(*NOTE: we will probably never need to do so*)
Inductive internal_execution : schedule -> t -> mem ->
t -> mem -> Prop :=
| refl_exec : forall tp m,
internal_execution [::] tp m tp m
| step_trans : forall tid U U' tp m tp' m' tp'' m''
(cnt: containsThread tp tid)
(HschedN: schedPeek U = Some tid)
(HschedS: schedSkip U = U')
(Hcomp: mem_compatible tp m)
(Hstep: internal_step cnt Hcomp tp' m')
(Htrans: internal_execution U' tp' m' tp'' m''),
internal_execution U tp m tp'' m''.
(** ** Lemmas about internal steps and internal executions *)
Ltac exec_induction base_case :=
intros;
match goal with
| [xs : list _, i : nat, Hexec: internal_execution _ ?Tp ?M _ _ |- _] =>
generalize dependent Tp; generalize dependent M;
induction xs as [| x xs' IHxs]; intros;
[ match goal with
| [Hexec: internal_execution _ _ _ _ _ |- _] =>
try (inversion Hexec; subst;
by Tactics.pf_cleanup)
end
| match goal with
| [Hexec: internal_execution _ _ _ _ _ |- _] =>
simpl in Hexec;
destruct (x == i) eqn:Heq;
move/eqP:Heq=>Heq;
try eauto;
subst;
try (inversion Hexec as [|? ? ? ? ? ? ? ? ? ?
HschedN HschedS Hcomp ? Htrans]; subst;
simpl in Htrans;
simpl in HschedN; inversion HschedN; subst;
Tactics.pf_cleanup;
specialize (IHxs _ _  Htrans);
rewrite <- IHxs;
erewrite base_case; eauto)
end
]
end.

Lemma internal_exec_disjoint_val_lockPool:
forall (tp tp' : t) (m m' : mem) (i : nat) xs bl ofsl pmap
(Hcomp : mem_compatible tp m)
(Hexec: internal_execution [seq x <- xs | x == i] tp m tp' m')
(Hl: lockRes tp (bl,ofsl) = Some pmap)
b ofs
(Hreadable: Mem.perm (restrPermMap ((compat_lp _ _ Hcomp) _ _ Hl).1)
b ofs Cur Readable \/
Mem.perm (restrPermMap ((compat_lp _ _ Hcomp) _ _ Hl).2)
b ofs Cur Readable),
Maps.ZMap.get ofs (Mem.mem_contents m) # b =
Maps.ZMap.get ofs (Mem.mem_contents m') # b.