Skip to content
Snippets Groups Projects
Commit 405f577c authored by Jonas Kastberg Hinrichsen's avatar Jonas Kastberg Hinrichsen
Browse files

Update to semantic let's

parent 36124591
No related branches found
No related tags found
No related merge requests found
...@@ -33,20 +33,20 @@ Definition get_side c s := ...@@ -33,20 +33,20 @@ Definition get_side c s :=
Definition send : val := Definition send : val :=
λ: "c" "s" "v", λ: "c" "s" "v",
let lk := get_lock "c" in let: "lk" := get_lock "c" in
acquire lk;; acquire "lk";;
let l := get_side "c" "s" in let: "l" := get_side "c" "s" in
l <- lsnoc !l "v";; "l" <- lsnoc !"l" "v";;
release lk. release "lk".
Definition try_recv : val := Definition try_recv : val :=
λ: "c" "s", λ: "c" "s",
let lk := get_lock "c" in let: "lk" := get_lock "c" in
acquire lk;; acquire "lk";;
let l := (get_side "c" (dual_side "s")) in let: "l" := (get_side "c" (dual_side "s")) in
match: !l with match: !"l" with
SOME "p" => l <- Snd "p";; release lk;; SOME (Fst "p") SOME "p" => "l" <- Snd "p";; release "lk";; SOME (Fst "p")
| NONE => release lk;; NONE | NONE => release "lk";; NONE
end. end.
Definition recv : val := Definition recv : val :=
...@@ -142,7 +142,7 @@ Section channel. ...@@ -142,7 +142,7 @@ Section channel.
destruct Hside as [-> | ->]. destruct Hside as [-> | ->].
- wp_pures. iDestruct "Hl" as (ll lhd ->) "(Hl & Hll)". - wp_pures. iDestruct "Hl" as (ll lhd ->) "(Hl & Hll)".
wp_load. wp_apply (lsnoc_spec with "Hll"). wp_load. wp_apply (lsnoc_spec with "Hll").
iIntros (hd') "Hll". wp_pures. iIntros (hd' Hll). wp_pures.
wp_bind (_ <- _)%E. iMod "HΦ" as (ls' rs') "[Hchan HΦ]". wp_bind (_ <- _)%E. iMod "HΦ" as (ls' rs') "[Hchan HΦ]".
wp_store. wp_store.
iDestruct "Hchan" as (l' r' lk' [= <- <- <-]) "[Hls' Hrs']". iDestruct "Hchan" as (l' r' lk' [= <- <- <-]) "[Hls' Hrs']".
...@@ -151,12 +151,11 @@ Section channel. ...@@ -151,12 +151,11 @@ Section channel.
iMod ("HΦ" with "[Hls' Hrs']") as "HΦ". iMod ("HΦ" with "[Hls' Hrs']") as "HΦ".
{ rewrite /= /chan_frag. eauto with iFrame. } { rewrite /= /chan_frag. eauto with iFrame. }
iModIntro. iModIntro.
wp_apply (release_spec with "[-HΦ $Hlock $Hlocked]"). wp_apply (release_spec with "[-HΦ $Hlock $Hlocked]"); last eauto.
{ rewrite /is_list_ref. eauto 10 with iFrame. } { rewrite /is_list_ref. eauto 10 with iFrame. }
iIntros "_ //".
- wp_pures. iDestruct "Hr" as (lr rhd ->) "(Hr & Hlr)". - wp_pures. iDestruct "Hr" as (lr rhd ->) "(Hr & Hlr)".
wp_load. wp_apply (lsnoc_spec with "Hlr"). wp_load. wp_apply (lsnoc_spec with "Hlr").
iIntros (hd') "Hlr". wp_pures. iIntros (hd' Hlr). wp_pures.
wp_bind (_ <- _)%E. iMod "HΦ" as (ls' rs') "[Hchan HΦ]". wp_bind (_ <- _)%E. iMod "HΦ" as (ls' rs') "[Hchan HΦ]".
wp_store. wp_store.
iDestruct "Hchan" as (l' r' lk' [= <- <- <-]) "[Hls' Hrs']". iDestruct "Hchan" as (l' r' lk' [= <- <- <-]) "[Hls' Hrs']".
...@@ -165,41 +164,37 @@ Section channel. ...@@ -165,41 +164,37 @@ Section channel.
iMod ("HΦ" with "[Hls' Hrs']") as "HΦ". iMod ("HΦ" with "[Hls' Hrs']") as "HΦ".
{ rewrite /= /chan_frag. eauto with iFrame. } { rewrite /= /chan_frag. eauto with iFrame. }
iModIntro. iModIntro.
wp_apply (release_spec with "[-HΦ $Hlock $Hlocked]"). wp_apply (release_spec with "[-HΦ $Hlock $Hlocked]"); last eauto.
{ rewrite /is_list_ref. eauto 10 with iFrame. } { rewrite /is_list_ref. eauto 10 with iFrame. }
iIntros "_ //".
Qed. Qed.
Definition try_recv_upd_fail γ c ls rs s : iProp Σ := Definition try_recv_fail γ c ls rs s : iProp Σ :=
match s with match s with
| left => (chan_frag γ c ls rs rs = [])%I | left => (chan_frag γ c ls rs rs = [])%I
| right => (chan_frag γ c ls rs ls = [])%I | right => (chan_frag γ c ls rs ls = [])%I
| _ => False⌝%I | _ => False⌝%I
end. end.
Definition try_recv_upd_succ γ c ls rs s v : iProp Σ := Definition try_recv_succ γ c ls rs s v : iProp Σ :=
match s with match s with
| left => ( rs', chan_frag γ c ls rs' rs = v::rs')%I | left => ( rs', chan_frag γ c ls rs' rs = v::rs')%I
| right => ( ls', chan_frag γ c ls' rs ls = v::ls')%I | right => ( ls', chan_frag γ c ls' rs ls = v::ls')%I
| _ => False⌝%I | _ => False⌝%I
end. end.
Definition try_recv_upd γ c ls rs s v : iProp Σ := Definition try_recv_get γ c ls rs s v : iProp Σ :=
match v with match v with
| NONEV => try_recv_upd_fail γ c ls rs s | NONEV => try_recv_fail γ c ls rs s
| SOMEV w => try_recv_upd_succ γ c ls rs s w | SOMEV w => try_recv_succ γ c ls rs s w
| _ => False⌝%I | _ => False⌝%I
end. end.
Definition try_recv_vs E γ c s Φ :=
(|={,E}=> ls rs,
chan_frag γ c ls rs
( v, try_recv_upd γ c ls rs s v ={E,}=∗ Φ v))%I.
Lemma try_recv_spec Φ E γ (c s : val) : Lemma try_recv_spec Φ E γ (c s : val) :
is_side s is_side s
chan_ctx γ c -∗ chan_ctx γ c -∗
try_recv_vs E γ c s Φ -∗ (|={,E}=> ls rs,
chan_frag γ c ls rs
( v, try_recv_get γ c ls rs s v ={E,}=∗ Φ v)) -∗
WP try_recv c s {{ Φ }}. WP try_recv c s {{ Φ }}.
Proof. Proof.
iIntros (Hside) "Hc HΦ". wp_lam; wp_pures. iIntros (Hside) "Hc HΦ". wp_lam; wp_pures.
...@@ -219,7 +214,7 @@ Section channel. ...@@ -219,7 +214,7 @@ Section channel.
iDestruct (excl_eq with "Hrsa Hrsf") as %->. iDestruct (excl_eq with "Hrsa Hrsf") as %->.
iSpecialize ("HΦ" $!(InjLV #())). iSpecialize ("HΦ" $!(InjLV #())).
iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ". iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ".
{ rewrite /try_recv_upd /try_recv_upd_fail /chan_frag. { rewrite /try_recv_get /try_recv_fail /chan_frag.
eauto 10 with iFrame. } eauto 10 with iFrame. }
iModIntro. iModIntro.
wp_apply (release_spec with "[-HΦ $Hlocked $Hlock]"). wp_apply (release_spec with "[-HΦ $Hlocked $Hlock]").
...@@ -237,7 +232,7 @@ Section channel. ...@@ -237,7 +232,7 @@ Section channel.
iDestruct (excl_update _ _ _ (rs) with "Hrsa Hrsf") as ">[Hrsa Hrsf]". iDestruct (excl_update _ _ _ (rs) with "Hrsa Hrsf") as ">[Hrsa Hrsf]".
iSpecialize ("HΦ" $!(InjRV (v))). iSpecialize ("HΦ" $!(InjRV (v))).
iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ". iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ".
{ rewrite /try_recv_upd /try_recv_upd_succ /chan_frag. { rewrite /try_recv_get /try_recv_succ /chan_frag.
eauto 10 with iFrame. } eauto 10 with iFrame. }
iModIntro. iModIntro.
wp_store. wp_store.
...@@ -258,7 +253,7 @@ Section channel. ...@@ -258,7 +253,7 @@ Section channel.
iDestruct (excl_eq with "Hrsa Hrsf") as %->. iDestruct (excl_eq with "Hrsa Hrsf") as %->.
iSpecialize ("HΦ" $!(InjLV #())). iSpecialize ("HΦ" $!(InjLV #())).
iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ". iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ".
{ rewrite /try_recv_upd /try_recv_upd_fail /chan_frag. { rewrite /try_recv_get /try_recv_fail /chan_frag.
eauto 10 with iFrame. } eauto 10 with iFrame. }
iModIntro. iModIntro.
wp_apply (release_spec with "[-HΦ $Hlocked $Hlock]"). wp_apply (release_spec with "[-HΦ $Hlocked $Hlock]").
...@@ -276,7 +271,7 @@ Section channel. ...@@ -276,7 +271,7 @@ Section channel.
iDestruct (excl_update _ _ _ (ls) with "Hlsa Hlsf") as ">[Hlsa Hlsf]". iDestruct (excl_update _ _ _ (ls) with "Hlsa Hlsf") as ">[Hlsa Hlsf]".
iSpecialize ("HΦ" $!(InjRV (v))). iSpecialize ("HΦ" $!(InjRV (v))).
iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ". iMod ("HΦ" with "[Hlsf Hrsf]") as "HΦ".
{ rewrite /try_recv_upd /try_recv_upd_succ /chan_frag. { rewrite /try_recv_get /try_recv_succ /chan_frag.
eauto 10 with iFrame. } eauto 10 with iFrame. }
iModIntro. iModIntro.
wp_store. wp_store.
...@@ -287,16 +282,13 @@ Section channel. ...@@ -287,16 +282,13 @@ Section channel.
by iApply "HΦ". by iApply "HΦ".
Qed. Qed.
Definition recv_vs E γ c s Φ :=
( (|={,E}=> ls rs,
chan_frag γ c ls rs
((try_recv_upd_fail γ c ls rs s ={E,}=∗ True)
( v, try_recv_upd_succ γ c ls rs s v ={E,}=∗ Φ v))))%I.
Lemma recv_spec Φ E γ c s : Lemma recv_spec Φ E γ c s :
is_side s is_side s
chan_ctx γ c -∗ chan_ctx γ c -∗
recv_vs E γ c s Φ -∗ ( (|={,E}=> ls rs,
chan_frag γ c ls rs
((try_recv_fail γ c ls rs s ={E,}=∗ True)
( v, try_recv_succ γ c ls rs s v ={E,}=∗ Φ v)))) -∗
WP recv c s {{ Φ }}. WP recv c s {{ Φ }}.
Proof. Proof.
iIntros (Hside) "#Hc #HΦ". iIntros (Hside) "#Hc #HΦ".
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment