Require Import Footprint InteractionSemantics GAST GMemory
GlobDefs ETrace GlobSemantics GlobSemantics_Lemmas NPSemantics TypedSemantics .
Require Import DRF USimDRF NPDRF FPLemmas.
Require Import Classical Wf Arith.
This file contains auxiliary definitions used in the proof of equivalence of NPDRF and DRF
Local Notation "'<<'
i ','
c ','
sg ','
F '>>'" := {|
Core.i :=
i;
Core.c :=
c;
Core.sg :=
sg;
Core.F :=
F|} (
at level 60,
right associativity).
Local Definition pc_valid_tid {
ge}:= @
GSimDefs.pc_valid_tid ge.
Local Notation "{
A ,
B ,
C ,
D }" := {|
thread_pool:=
A;
cur_tid:=
B;
gm:=
C;
atom_bit:=
D|}(
at level 70,
right associativity).
Local Notation "{-|
PC ,
T }" := ({|
thread_pool :=
thread_pool PC;
cur_tid :=
T;
gm :=
gm PC;
atom_bit :=
atom_bit PC |}) (
at level 70,
right associativity).
Section PRace.
Lemma tau_star_np_step_star_glob_step:
forall ge pc pc'
fp',
tau_star (@
np_step ge)
pc fp'
pc' ->
tau_star glob_step pc fp'
pc'.
Proof.
Inductive glob_predict{
GE:
GlobEnv.t}:@
ProgConfig GE ->
tid ->
Bit ->
FP.t ->
Prop :=
|
predict0:
forall pc pc'
fp t,
@
type_glob_step GE core ({-|
pc,
t})
tau fp pc' ->
atom_bit pc =
O ->
glob_predict pc t O fp
|
predictI:
forall pc pc'
pc''
fp t,
@
type_glob_step GE entat ({-|
pc,
t})
tau FP.emp pc' ->
tau_star (
type_glob_step core)
pc'
fp pc'' ->
glob_predict pc t I fp.
Lemma predict_equiv:
forall ge pc t b fp,
@
predict ge pc t b fp <->
glob_predict pc t b fp.
Proof.
split;
intro.
{
inversion H;
subst.
pose proof H_core_step as Tmp1.
eapply local_core_step in Tmp1 as (
c'&?&
thdp'&?) ;
eauto.
econstructor;
econstructor;
eauto.
assert(
exists c',
Core.update c cc'
c').
eexists;
econstructor;
eauto.
destruct H0 as (
c'&
H_core_upd).
pose proof H_tp_core as backup1.
unfold ThreadPool.get_top in H_tp_core.
destruct (
ThreadPool.get_cs thdp t)
eqn:
eq;[|
inversion H_tp_core].
unfold CallStack.top in H_tp_core.
destruct t1 eqn:
eq2;
inversion H_tp_core;
subst;
clear H_tp_core.
rename backup1 into H_tp_core.
assert(
exists thdp',
ThreadPool.update thdp t c'
thdp').
eexists.
econstructor;
eauto.
econstructor;
eauto.
destruct H0 as (
t'&
H_tp_upd).
assert(
entat_step:
type_glob_step entat ({
thdp,
t,
gm,
O})
tau FP.emp ({
t',
t,
gm,
I})).
econstructor;
eauto.
unfold ThreadPool.get_top in H_tp_core.
destruct (
ThreadPool.get_cs thdp t)
eqn:
eq2;[|
inversion H_tp_core].
assert(
ThreadPool.get_cs t'
t =
Some(
c'::
t3)%
list).
unfold ThreadPool.get_cs.
inversion H_tp_upd;
subst.
simpl.
rewrite Maps.PMap.gsspec.
destruct Coqlib.peq;[|
contradiction].
inversion H1;
subst.
rewrite H0 in eq2.
inversion eq2;
inversion eq;
subst.
inversion H5;
subst.
auto.
assert(
ThreadPool.get_top t'
t =
Some c').
unfold ThreadPool.get_top.
rewrite H0;
auto.
inversion H_core_upd;
subst.
eapply star_local_core_step with(
d:=
I)
in H_core_step as [];
eauto.
econstructor 2;
eauto.
}
{
inversion H;
subst.
inversion H0;
subst.
destruct pc as (
thdp,
t',
gm,
b).
compute in H1;
subst.
simpl in *.
econstructor ;
eauto.
inversion H0;
subst.
destruct pc as (
thdp,
t',
gm,
b).
compute in H6;
subst.
simpl in *.
destruct pc''.
pose proof H1 as Tmp1.
apply star_core_step_equiv in Tmp1.
apply tau_star_type_step in Tmp1.
assert(
cur_tid =
t).
apply GlobSim.GlobSim.tau_star_tid_preservation in Tmp1;
auto.
subst.
assert(
atom_bit =
I).
apply tau_star_tau_N_equiv in Tmp1 as [].
apply GlobSim.GlobSim.tau_N_bit_I_preservation in H2;
auto.
subst.
clear Tmp1.
destruct c.
destruct c'.
inversion H_core_update;
subst.
simpl in H2.
assert(
ThreadPool.get_top thdp'
t =
Some (<<
i,
cc',
sg,
F>>)).
unfold ThreadPool.get_top.
inversion H_tp_upd;
subst.
unfold ThreadPool.get_cs.
simpl.
rewrite Maps.PMap.gsspec.
destruct Coqlib.peq;[|
contradiction].
inversion H4;
subst;
auto.
compute [
CallStack.top].
rewrite H2;
auto.
pose proof H3 as Tmp1.
eapply corestar_localstar in Tmp1 as [
cc''[]];
eauto.
econstructor 2;
eauto.
}
Qed.
Definition glob_npnsw_step {
GE}(
pc:@
ProgConfig GE)(
l:
glabel)(
fp:
FP.t)(
pc':@
ProgConfig GE):
Prop:=
@
type_glob_step GE core pc l fp pc' \/
type_glob_step call pc l fp pc' \/
type_glob_step ret pc l fp pc'.
Lemma glob_npnsw_step_bitO_preserve{
GE}:
forall pc l fp pc',
atom_bit pc =
O ->
@
glob_npnsw_step GE pc l fp pc'->
atom_bit pc' =
O.
Proof.
inversion 2 as [T|[T|T]];inversion T;subst;auto. Qed.
Lemma glob_npnsw_star_bitO_preserve{
GE}:
forall pc fp pc',
atom_bit pc =
O ->
tau_star (@
glob_npnsw_step GE)
pc fp pc'->
atom_bit pc' =
O.
Proof.
Lemma glob_npnsw_step_to_np_step{
GE}:
forall pc l fp pc',
@
glob_npnsw_step GE pc l fp pc' ->
np_step pc l fp pc'.
Proof.
Lemma glob_npnsw_star_to_np_taustar{
GE}:
forall pc fp pc',
tau_star (@
glob_npnsw_step GE)
pc fp pc'->
tau_star np_step pc fp pc'.
Proof.
Inductive glob_predict_star{
GE}:@
ProgConfig GE ->
tid ->
Bit ->
FP.t ->
Prop :=
|
star_predict0:
forall pc pc'
fp t,
tau_star glob_npnsw_step ({-|
pc,
t})
fp pc' ->
atom_bit pc =
O ->
glob_predict_star pc t O fp
|
star_predictI:
forall pc pc'
pc''
fp t,
@
type_glob_step GE entat ({-|
pc,
t})
tau FP.emp pc' ->
tau_star (
type_glob_step core)
pc'
fp pc'' ->
glob_predict_star pc t I fp.
Inductive np_predict_star{
GE}:@
ProgConfig GE->
tid->
Bit->
FP.t->
Prop:=
|
np_predict0_star:
forall pc pc'
fp t,
tau_star np_step ({-|
pc,
t})
fp pc' ->
atom_bit pc =
O ->
atom_bit pc' =
O ->
@
np_predict_star GE pc t O fp
|
np_predictI_star:
forall pc pc1 pc2 pc3 fp1 fp2 t,
tau_star np_step ({-|
pc,
t})
fp1 pc1 ->
atom_bit pc =
O ->
type_np_step entat pc1 tau FP.emp pc2 ->
tau_star np_step pc2 fp2 pc3->
@
np_predict_star GE pc t I (
FP.union fp1 fp2).
Inductive glob_predict_star_alter{
GE}:@
ProgConfig GE->
tid->
Bit->
FP.t->
Prop:=
|
glob_predict0_star_alter:
forall pc pc'
fp t,
tau_star glob_npnsw_step ({-|
pc,
t})
fp pc' ->
atom_bit pc =
O ->
atom_bit pc' =
O ->
glob_predict_star_alter pc t O fp
|
glob_predictI_star_alter:
forall pc pc1 pc2 pc3 fp1 fp2 t,
tau_star glob_npnsw_step ({-|
pc,
t})
fp1 pc1 ->
atom_bit pc =
O ->
type_glob_step entat pc1 tau FP.emp pc2 ->
tau_star (
type_glob_step core)
pc2 fp2 pc3->
glob_predict_star_alter pc t I (
FP.union fp1 fp2).
Lemma glob_predict_star_to_alter:
forall GE pc t b fp,
@
glob_predict_star GE pc t b fp ->
glob_predict_star_alter pc t b fp.
Proof.
Definition nonhalt_biteq_tau_npstep {
GE}(
pc:@
ProgConfig GE)(
l:
glabel)(
fp:
FP.t)(
pc':@
ProgConfig GE):
Prop:=
type_np_step core pc l fp pc' \/
type_np_step call pc l fp pc' \/
type_np_step ret pc l fp pc'.
Lemma npstep_nohalt{
GE}:
forall x pc fp pc'
fp'
pc'',
@
type_np_step GE x pc tau fp pc' ->
np_step pc'
tau fp'
pc'' ->
x <>
allhalt.
Proof.
intros.
inversion H;
subst;
try(
intro contra;
inversion contra;
fail).
assert(
exists c',
ThreadPool.get_top thdp'
t =
Some c').
inversion H0;
eauto.
destruct H1.
unfold ThreadPool.get_top in H1.
destruct ThreadPool.get_cs eqn:?;
inversion H1;
clear H1;
subst.
inversion H_thread_halt;
subst.
rewrite Heqo in H1;
inversion H1;
clear H1;
subst.
inversion H2;
subst.
inversion H3.
Qed.
Lemma npstep_biteq_nohalt{
GE}:
forall pc fp pc'
fp'
pc'',
@
np_step GE pc tau fp pc' ->
atom_bit pc =
atom_bit pc' ->
np_step pc'
tau fp'
pc'' ->
nonhalt_biteq_tau_npstep pc tau fp pc'.
Proof.
Lemma nptaustar_nohalt{
GE}:
forall pc fp pc'
fp'
pc'',
tau_star (@
np_step GE)
pc fp pc' ->
atom_bit pc =
atom_bit pc' ->
np_step pc'
tau fp'
pc'' ->
tau_star nonhalt_biteq_tau_npstep pc fp pc'.
Proof.
Lemma nohalt_nptaustar{
GE}:
forall pc fp pc',
tau_star nonhalt_biteq_tau_npstep pc fp pc'->
tau_star (@
np_step GE)
pc fp pc' /\
atom_bit pc =
atom_bit pc'.
Proof.
Lemma nonhalt_biteq_tau_npstep_glob_npnsw_step_equiv{
GE}:
forall pc l fp pc',
nonhalt_biteq_tau_npstep pc l fp pc' <-> @
glob_npnsw_step GE pc l fp pc'.
Proof.
Lemma nonhalt_biteq_taustar_npnsw_tau_star_equiv{
GE}:
forall pc fp pc',
tau_star nonhalt_biteq_tau_npstep pc fp pc' <->
tau_star (@
glob_npnsw_step GE)
pc fp pc'.
Proof.
Inductive race {
ge} : (@
ProgConfig ge->
tid->
Bit->
FP.t->
Prop)->@
ProgConfig ge ->
Prop :=
Race:
forall (
predict:@
ProgConfig ge->
tid->
Bit->
FP.t->
Prop)
pc t1 b1 fp1 t2 b2 fp2,
t1 <>
t2 ->
predict pc t1 b1 fp1 ->
predict pc t2 b2 fp2 ->
b1 <>
I \/
b2 <>
I ->
FP.conflict fp1 fp2 ->
race predict pc.
Lemma race_equiv:
forall ge pc,
@
race_config ge pc <->
race predict pc.
Proof.
split;intro;inversion H;subst.
econstructor;eauto.
econstructor;try apply H0;eauto.
Qed.
Lemma nprace_equiv:
forall ge pc,
@
np_race_config ge pc <->
race np_predict_star pc.
Proof.
Lemma predict_equiv_race_equiv:
forall ge predict1 predict2,
(
forall (
pc:@
ProgConfig ge)
t b fp,
predict1 pc t b fp <->
predict2 pc t b fp) ->
(
forall pc,@
race ge predict1 pc <->
race predict2 pc).
Proof.
split;intro;inversion H0;subst;apply H in H2;apply H in H3;econstructor;eauto.
Qed.
Lemma predict_race_to_star:
forall ge pc,
@
race ge glob_predict pc ->
race glob_predict_star pc.
Proof.
intros.
inversion H;
subst.
inversion H1;
inversion H2;
subst.
econstructor;
eauto.
rewrite <-
FP.fp_union_emp with(
fp:=
fp1).
econstructor;
eauto.
econstructor;
eauto;[
left;
eauto|
constructor].
rewrite <-
FP.fp_union_emp with(
fp:=
fp2).
econstructor;
eauto.
econstructor;
eauto;[
left;
eauto|
constructor].
econstructor;
eauto.
rewrite <-
FP.fp_union_emp with(
fp:=
fp1).
econstructor;
eauto.
econstructor;
eauto;[
left;
eauto|
constructor].
econstructor;
eauto.
econstructor;
eauto.
econstructor;
eauto.
rewrite <-
FP.fp_union_emp with(
fp:=
fp2).
econstructor;
eauto.
econstructor;
eauto;[
left;
eauto|
constructor].
destruct H3;
contradiction.
Qed.
Lemma predict_star_race_to_alter:
forall ge pc,
@
race ge glob_predict_star pc ->
race glob_predict_star_alter pc.
Proof.
Lemma race_np_predict_starOO_glob_predict_star_alter:
forall ge pc t1 fp1 pc1 t2 fp2 pc2,
t1 <>
t2 ->
tau_star (@
np_step ge) ({-|
pc,
t1})
fp1 pc1 ->
atom_bit pc =
O ->
atom_bit pc1 =
O ->
tau_star np_step ({-|
pc,
t2})
fp2 pc2 ->
atom_bit pc2 =
O ->
FP.conflict fp1 fp2 ->
race glob_predict_star_alter pc.
Proof.
Lemma race_np_predict_starOI_glob_predict_star_alter:
forall ge pc t1 fp1 pc1 t2 fp2 pc2 pc3 fp3 pc4,
t1 <>
t2 ->
tau_star (@
np_step ge) ({-|
pc,
t1})
fp1 pc1 ->
atom_bit pc =
O ->
atom_bit pc1 =
O ->
tau_star np_step ({-|
pc,
t2})
fp2 pc2 ->
atom_bit pc2 =
O ->
type_np_step entat pc2 tau FP.emp pc3->
tau_star np_step pc3 fp3 pc4 ->
FP.conflict fp1 (
FP.union fp2 fp3) ->
race glob_predict_star_alter pc.
Proof.
Lemma nppredictrace_globpredictstaraltrace_equiv:
forall ge pc,
@
race ge np_predict_star pc <->
race glob_predict_star_alter pc.
Proof.
Definition star_race {
ge} (
predict:@
ProgConfig ge->
tid->
Bit->
FP.t->
Prop)(
pc:
ProgConfig):
Prop:=
exists l fp pc',
ETrace.star glob_step pc l fp pc' /\
race predict pc'.
Lemma star_race_equiv:
forall ge pc,
@
star_race_config ge pc <->
star_race predict pc.
Proof.
split;
intro.
unfold star_race_config in H.
destruct H as (
l&
fp&
pc'&
star1&
race1).
exists l,
fp,
pc'.
split;
auto.
apply race_equiv;
auto.
unfold star_race in H.
destruct H as (
l&
fp&
pc'&
star1&
race1).
exists l,
fp,
pc'.
split;
auto.
apply race_equiv;
auto.
Qed.
Lemma predict_equiv_to_star_race_equiv:
forall ge predict1 predict2,
(
forall (
pc:@
ProgConfig ge)
t b fp,
predict1 pc t b fp <->
predict2 pc t b fp) ->
(
forall pc,@
star_race ge predict1 pc <->
star_race predict2 pc).
Proof.
Lemma glob_predict_to_star:
forall ge pc fp b t,
@
glob_predict ge pc b t fp ->
glob_predict_star pc b t fp.
Proof.
intros.
inversion H;
subst;
econstructor;
eauto.
rewrite<-
FP.fp_union_emp with(
fp:=
fp).
econstructor 2;
eauto.
unfold glob_npnsw_step;
left;
eauto.
constructor.
Qed.
Lemma star_race_to_star_predict_race:
forall ge pc,
@
star_race ge glob_predict pc ->
star_race glob_predict_star pc.
Proof.
intros;
unfold star_race in *.
destruct H as (
l&
fp&
pc'&
star1&
race1).
induction star1.
exists nil,
FP.emp,
s.
split;[
constructor|].
inversion race1;
subst.
apply glob_predict_to_star in H0.
apply glob_predict_to_star in H1.
econstructor;
eauto.
specialize (
IHstar1 race1)
as (
l'&
fp'&
pc'&
star'&
race').
exists (
cons e l'),(
FP.union fp1 fp'),
pc'.
split;[
econstructor 2|];
eauto.
Qed.
Definition glob_race_prog {
NL}{
L:@
langs NL}{
ge}(
predict:@
ProgConfig ge->
tid->
Bit->
FP.t->
Prop)(
p:
prog L):
Prop:=
exists gm pc t,
init_config p gm ge pc t /\
star_race predict pc.
Lemma race_prog_to_glob_race_prog_star_predictt:
forall NL L p,
@
race_prog NL L p ->
exists ge,@
glob_race_prog NL L ge glob_predict_star p.
Proof.
End PRace.