Skip to content
Snippets Groups Projects
Commit d344c353 authored by Zhen Zhang's avatar Zhen Zhang
Browse files

srv ... token exchange is too complex

parent b2ba5bcb
Branches
Tags
No related merge requests found
...@@ -16,7 +16,7 @@ Definition srv : val := ...@@ -16,7 +16,7 @@ Definition srv : val :=
Definition wait: val := Definition wait: val :=
rec: "wait" "p" := rec: "wait" "p" :=
match: !"p" with match: !"p" with
InjR "r" => "p" <- InjR #0 ;; "r" InjR "r" => "r"
| InjL "_" => "wait" "p" | InjL "_" => "wait" "p"
end. end.
...@@ -60,38 +60,53 @@ Section proof. ...@@ -60,38 +60,53 @@ Section proof.
Context `{!heapG Σ, !lockG Σ, !srvG Σ} (N : namespace). Context `{!heapG Σ, !lockG Σ, !srvG Σ} (N : namespace).
Definition srv_inv Definition srv_inv
(γx γ1 γ2 γ3: gname) (p: loc) (γx γ1 γ2 γ3 γ4 γ5: gname) (p: loc)
(Q: val val Prop): iProp Σ := (Q: val val Prop): iProp Σ :=
(( (x: val), p InjRV x own γ1 (Excl ())) (( (x: val), p InjRV x own γ1 (Excl ()) own γ3 (Excl ()))
( (x: val), p InjLV x own γx ((1/2)%Qp, DecAgree x) own γ2 (Excl ())) ( (x y: val), p InjRV y own γx ((1/2)%Qp, DecAgree x) Q x y own γ2 (Excl ()) own γ3 (Excl ()))
( (x y: val), p InjRV y own γx ((1/2)%Qp, DecAgree x) Q x y own γ3 (Excl ())))%I. ( (x: val), p InjLV x own γx ((1/2)%Qp, DecAgree x) own γ5 (Excl ()) own γ3 (Excl ()))
( (x: val), p InjLV x own γx ((1/2)%Qp, DecAgree x) own γ5 (Excl ()) own γ4 (Excl ())))%I.
Lemma srv_inv_timeless γx γ1 γ2 γ3 p Q: TimelessP (srv_inv γx γ1 γ2 γ3 p Q). Lemma srv_inv_timeless γx γ1 γ2 γ3 γ4 γ5 p Q: TimelessP (srv_inv γx γ1 γ2 γ3 γ4 γ5 p Q).
Proof. apply _. Qed. Proof. apply _. Qed.
Lemma wait_spec (Φ: val iProp Σ) (Q: val val Prop) x γx γ1 γ2 γ3 p: Lemma wait_spec (Φ: val iProp Σ) (Q: val val Prop) x γx γ1 γ2 γ3 γ4 γ5 p:
heapN N heapN N
heap_ctx inv N (srv_inv γx γ1 γ2 γ3 p Q) heap_ctx inv N (srv_inv γx γ1 γ2 γ3 γ4 γ5 p Q)
own γx ((1/2)%Qp, DecAgree x) own γ1 (Excl ()) own γ3 (Excl ()) own γx ((1/2)%Qp, DecAgree x) own γ1 (Excl ()) own γ5 (Excl ())
( y, own γ1 (Excl ()) own γ2 (Excl ()) - own γx (1%Qp, DecAgree x) - Q x y- Φ y) ( y, own γ2 (Excl ()) - own γx (1%Qp, DecAgree x) - Q x y- Φ y)
WP wait #p {{ Φ }}. WP wait #p {{ Φ }}.
Proof. Proof.
iIntros (HN) "(#Hh & #Hsrv & Hx & Hempty & Hfinished & HΦ)". iIntros (HN) "(#Hh & #Hsrv & Hx & Hempty & Hfinished & HΦ)".
iLöb as "IH". iLöb as "IH".
wp_rec. wp_bind (! #p)%E. wp_rec. wp_bind (! #p)%E.
iInv N as ">[Hinv|[Hinv|Hinv]]" "Hclose". iInv N as ">[Hinv|[Hinv|[Hinv|Hinv]]]" "Hclose".
+ iExFalso. iDestruct "Hinv" as (?) "[_ Ho1]". - iExFalso. iDestruct "Hinv" as (?) "[_ [Ho1 _]]".
iCombine "Hempty" "Ho1" as "Hempty". iCombine "Hempty" "Ho1" as "Hempty".
by iDestruct (own_valid with "Hempty") as "%". by iDestruct (own_valid with "Hempty") as "%".
+ iDestruct "Hinv" as (x') "(Hp & Hx' & Hissued)". - iDestruct "Hinv" as (x' y') "(Hp & Hx' & % & Ho2 & Ho3)".
wp_load. destruct (decide (x = x')) as [->|Hneq].
iVs ("Hclose" with "[Hp Hx' Hissued]"). + wp_load. iVs ("Hclose" with "[Hp Hx' Ho2 Ho3]").
{ iNext. iRight. iLeft. iExists x'. by iFrame. } { iNext. rewrite /srv_inv. iRight. iLeft. iExists x', y'.
iVsIntro. wp_match. by iApply ("IH" with "Hx Hempty Hfinished"). by iFrame. }
+ iDestruct "Hinv" as (x' y') "(Hp & Hx' & % & Ho3)". iVsIntro. wp_match.
iCombine "Hfinished" "Ho3" as "Hfinished". iInv N as ">[Hinv|[Hinv|[Hinv|Hinv]]]" "Hclose".
by iDestruct (own_valid with "Hfinished") as "%". * admit.
Qed. * iDestruct "Hinv" as (x'' y'') "(Hp & Hx'' & % & Ho2 & Ho3)".
iVs ("Hclose" with "[Hp Hempty Ho3]").
{ iNext. rewrite /srv_inv. iLeft.
iExists y''. by iFrame. }
destruct (decide (x' = x'')) as [->|Hneq].
{ iCombine "Hx" "Hx''" as "Hx".
iDestruct (own_update with "Hx") as "==>Hx"; first by apply pair_l_frac_op.
by iApply ("HΦ" with "Ho2 Hx"). }
{ admit. }
* admit.
* admit.
+ admit.
- admit.
- admit.
Admitted.
Lemma mk_srv_spec (f: val) Q: Lemma mk_srv_spec (f: val) Q:
heapN N heapN N
...@@ -102,57 +117,85 @@ Section proof. ...@@ -102,57 +117,85 @@ Section proof.
wp_let. wp_alloc p as "Hp". wp_let. wp_alloc p as "Hp".
iVs (own_alloc (Excl ())) as (γ1) "Hempty"; first done. iVs (own_alloc (Excl ())) as (γ1) "Hempty"; first done.
iVs (own_alloc (Excl ())) as (γ2) "Hissued"; first done. iVs (own_alloc (Excl ())) as (γ2) "Hissued"; first done.
iVs (own_alloc (Excl ())) as (γ3) "Hfinished"; first done. iVs (own_alloc (Excl ())) as (γ3) "Hblack"; first done.
iVs (own_alloc (Excl ())) as (γ4) "Hwhite"; first done.
iVs (own_alloc (Excl ())) as (γ5) "Hfinished"; first done.
iVs (own_alloc (1%Qp, DecAgree #0)) as (γx) "Hx"; first done. iVs (own_alloc (1%Qp, DecAgree #0)) as (γx) "Hx"; first done.
iVs (inv_alloc N _ (srv_inv γx γ1 γ2 γ3 p Q) with "[Hp Hempty]") as "#?". iVs (inv_alloc N _ (srv_inv γx γ1 γ2 γ3 γ4 γ5 p Q) with "[Hp Hempty Hblack]") as "#?".
{ iNext. rewrite /srv_inv. iLeft. iExists #0. by iFrame. } { iNext. rewrite /srv_inv. iLeft. iExists #0. by iFrame. }
(* iVs (inv_alloc N _ (own γ3 (Excl ()) own γ4 (Excl ()))%I with "[Hwhite]") as "#Hsinv". *)
(* { iNext. by iRight. } *)
wp_let. wp_bind (newlock _). wp_let. wp_bind (newlock _).
iApply newlock_spec=>//. iFrame "Hh". iApply newlock_spec=>//. iFrame "Hh".
iAssert ( x, own γx (1%Qp, DecAgree x) own γ2 (Excl ()) own γ3 (Excl ()))%I with "[Hissued Hfinished Hx]" as "Hinv". iAssert ( x, own γx (1%Qp, DecAgree x) own γ2 (Excl ()) own γ5 (Excl ()))%I with "[Hissued Hfinished Hx]" as "Hinv".
{ iExists #0. by iFrame. } { iExists #0. by iFrame. }
iFrame "Hinv". iIntros (lk γlk) "#Hlk". iFrame "Hinv". iIntros (lk γlk) "#Hlk".
wp_let. wp_apply wp_fork. wp_let. wp_apply wp_fork.
iSplitL. iSplitR "Hwhite".
- (* client closure *) - (* (* client closure *) *)
iVsIntro. wp_seq. iVsIntro. (* iVsIntro. wp_seq. iVsIntro. *)
iAlways. iIntros (x). (* iAlways. iIntros (x). *)
wp_let. wp_bind (acquire _). iApply acquire_spec. (* wp_let. wp_bind (acquire _). iApply acquire_spec. *)
iFrame "Hlk". iIntros "Hlked Ho". (* iFrame "Hlk". iIntros "Hlked Ho". *)
iDestruct "Ho" as (x') "[Hx [Hissued Hfinished]]". (* iDestruct "Ho" as (x') "[Hx [Hissued Hfinished]]". *)
wp_seq. wp_bind (_ <- _)%E. (* wp_seq. wp_bind (_ <- _)%E. *)
iInv N as ">Hinv" "Hclose". (* iInv N as ">Hinv" "Hclose". *)
rewrite /srv_inv. (* rewrite /srv_inv. *)
iDestruct "Hinv" as "[Hinv|[Hinv|Hinv]]". (* iDestruct "Hinv" as "[Hinv|[Hinv|Hinv]]". *)
+ iDestruct "Hinv" as (x'') "[Hp Hempty]". (* + iDestruct "Hinv" as (x'') "[Hp Hempty]". *)
wp_store. (* wp_store. *)
iAssert (|=r=> own γx (1%Qp, DecAgree x))%I with "[Hx]" as "Ho". (* iAssert (|=r=> own γx (1%Qp, DecAgree x))%I with "[Hx]" as "Ho". *)
{ iDestruct (own_update with "Hx") as "Hx"; last by iAssumption. (* { iDestruct (own_update with "Hx") as "Hx"; last by iAssumption. *)
apply cmra_update_exclusive. done. } (* apply cmra_update_exclusive. done. } *)
iVs "Ho". iDestruct (own_update with "Ho") as "==>[Ho1 Ho2]"; first by apply pair_l_frac_op'. (* iVs "Ho". iDestruct (own_update with "Ho") as "==>[Ho1 Ho2]"; first by apply pair_l_frac_op'. *)
iVs ("Hclose" with "[Hp Hissued Ho1]"). (* iVs ("Hclose" with "[Hp Hissued Ho1]"). *)
{ rewrite /locked. iNext. iRight. iLeft. (* { rewrite /locked. iNext. iRight. iLeft. *)
iExists x. by iFrame. } (* iExists x. by iFrame. } *)
iVsIntro. wp_seq. (* iVsIntro. wp_seq. *)
wp_bind (wait _). (* wp_bind (wait _). *)
iApply (wait_spec with "[Hempty Hfinished Ho2 Hlked]"); first by done. (* iApply (wait_spec with "[Hempty Hfinished Ho2 Hlked]"); first by done. *)
{ iFrame "Hh". iFrame "#". iFrame. (* { iFrame "Hh". iFrame "#". iFrame. *)
iIntros (y3) "[Hempty Hissued] Hx %". (* iIntros (y3) "[Hempty Hissued] Hx %". *)
wp_let. wp_bind (release _). (* wp_let. wp_bind (release _). *)
iApply pvs_wp. (* iApply pvs_wp. *)
iInv N as ">[Hinv|[Hinv|Hinv]]" "Hclose". (* iInv N as ">[Hinv|[Hinv|Hinv]]" "Hclose". *)
- admit. (* - admit. *)
- admit. (* - admit. *)
- iDestruct "Hinv" as (x4 y4) "(Hp & _ & _ & Hfinished)". (* - iDestruct "Hinv" as (x4 y4) "(Hp & _ & _ & Hfinished)". *)
iVs ("Hclose" with "[Hp Hempty]"). (* iVs ("Hclose" with "[Hp Hempty]"). *)
{ iNext. iLeft. iExists y4. by iFrame. } (* { iNext. iLeft. iExists y4. by iFrame. } *)
iApply release_spec. (* iApply release_spec. *)
iFrame "Hlk Hlked". (* iFrame "Hlk Hlked". *)
iSplitL "Hissued Hfinished Hx". (* iSplitL "Hissued Hfinished Hx". *)
{ iExists x. by iFrame. } (* { iExists x. by iFrame. } *)
by wp_seq. (* by wp_seq. *)
} (* } *)
+ admit. (* + admit. *)
+ admit. (* + admit. *) admit.
- (* server side *) - (* server side *)
iLöb as "IH".
wp_rec. wp_let. wp_bind (! _)%E.
iInv N as ">[Hinv|[Hinv|[Hinv|Hinv]]]" "Hclose".
+ iDestruct "Hinv" as (x) "[Hp Hrest]".
wp_load. iVs ("Hclose" with "[Hp Hrest]").
{ iNext. rewrite /srv_inv. iLeft. iExists x. by iFrame. }
iVsIntro. wp_match. by iApply "IH".
+ iDestruct "Hinv" as (x y) "[Hp Hrest]".
wp_load. iVs ("Hclose" with "[Hp Hrest]").
{ iNext. rewrite /srv_inv. iRight. iLeft. iExists x, y. by iFrame. }
iVsIntro. wp_match. by iApply "IH".
+ iDestruct "Hinv" as (x) "(Hp & Hx & Hfinished & Hblack)".
wp_load. iVs ("Hclose" with "[Hp Hx Hfinished Hwhite]").
{ iNext. rewrite /srv_inv. iRight. iRight. iRight. iExists x. by iFrame. }
iVsIntro. wp_match.
wp_bind (_ <- _)%E.
iApply pvs_wp.
iInv N as ">[Hinv|[Hinv|[Hinv|Hinv]]]" "Hclose".
* admit.
* admit.
* admit.
* iDestruct "Hinv" as (x') "(Hp & Hx & Hfinished & Hwhite)".
iVs ("Hclose" with "[Hp Hx Hfinished Hblack]").
Admitted. Admitted.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment