Skip to content
Snippets Groups Projects
Commit 0f4e744e authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Tactics `wp_send` and `wp_recv`.

parent 2c2ed933
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ theories/utils/compare.v ...@@ -7,6 +7,7 @@ theories/utils/compare.v
theories/channel/channel.v theories/channel/channel.v
theories/channel/proto_model.v theories/channel/proto_model.v
theories/channel/proto_channel.v theories/channel/proto_channel.v
theories/channel/proofmode.v
theories/examples/list_sort.v theories/examples/list_sort.v
theories/examples/list_sort_instances.v theories/examples/list_sort_instances.v
theories/examples/list_sort_elem.v theories/examples/list_sort_elem.v
......
From stdpp Require Import sorting. From stdpp Require Import sorting.
From osiris.channel Require Import proto_channel. From osiris.channel Require Import proto_channel proofmode.
From iris.heap_lang Require Import proofmode notation. From iris.heap_lang Require Import proofmode notation.
From osiris.utils Require Import list compare. From osiris.utils Require Import list compare.
...@@ -89,17 +89,14 @@ Section list_sort. ...@@ -89,17 +89,14 @@ Section list_sort.
Proof. Proof.
iIntros (Ψ) "Hc HΨ". iLöb as "IH" forall (p c Ψ). iIntros (Ψ) "Hc HΨ". iLöb as "IH" forall (p c Ψ).
wp_lam. wp_lam.
wp_apply (recv_proto_spec with "Hc"); simpl. wp_recv (A I R ?? cmp) with "#Hcmp".
iIntros (A I R ?? cmp) "/= Hc #Hcmp". wp_recv (xs l vs) with "[Hl HI]".
wp_apply (recv_proto_spec with "Hc"); simpl.
iIntros (xs l vs) "/= Hc [Hl HI]".
wp_load. wp_apply (llength_spec (A:=val) with "[//]"); iIntros (_). wp_load. wp_apply (llength_spec (A:=val) with "[//]"); iIntros (_).
iDestruct (big_sepL2_length with "HI") as %<-. iDestruct (big_sepL2_length with "HI") as %<-.
wp_op; case_bool_decide as Hlen; wp_if. wp_op; case_bool_decide as Hlen; wp_if.
{ assert (Sorted R xs). { assert (Sorted R xs).
{ destruct xs as [|x1 [|x2 xs]]; simpl in *; eauto with lia. } { destruct xs as [|x1 [|x2 xs]]; simpl in *; eauto with lia. }
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$Hl $HI]"; first by auto. by iApply "HΨ". }
iExists xs, vs; iSplit; first done. eauto 10 with iFrame. }
wp_load. wp_apply (lsplit_spec (A:=val) with "[//]"); iIntros (vs1 vs2 <-). wp_load. wp_apply (lsplit_spec (A:=val) with "[//]"); iIntros (vs1 vs2 <-).
wp_alloc l1 as "Hl1"; wp_alloc l2 as "Hl2". wp_alloc l1 as "Hl1"; wp_alloc l2 as "Hl2".
iDestruct (big_sepL2_app_inv_r with "HI") as (xs1 xs2 ->) "[HI1 HI2]". iDestruct (big_sepL2_app_inv_r with "HI") as (xs1 xs2 ->) "[HI1 HI2]".
...@@ -109,26 +106,20 @@ Section list_sort. ...@@ -109,26 +106,20 @@ Section list_sort.
wp_apply (start_chan_proto_spec N sort_protocol); iIntros (cz) "Hcz". wp_apply (start_chan_proto_spec N sort_protocol); iIntros (cz) "Hcz".
{ rewrite -{2}(right_id END%proto _ (iProto_dual _)). { rewrite -{2}(right_id END%proto _ (iProto_dual _)).
wp_apply ("IH" with "Hcz"); auto. } wp_apply ("IH" with "Hcz"); auto. }
wp_apply (send_proto_spec with "Hcy"); simpl. wp_send with "[$Hcmp]".
iExists _, I, R, _, _, cmp. iSplit; first done. iIntros "{$Hcmp} !> Hcy". wp_send with "[$Hl1 $HI1]".
wp_apply (send_proto_spec with "Hcy"); simpl. wp_send with "[$Hcmp]".
iExists xs1, l1, vs1. iSplit; first done. iIntros "{$Hl1 $HI1} !> Hcy". wp_send with "[$Hl2 $HI2]".
wp_apply (send_proto_spec with "Hcz"); simpl. wp_recv (ys1 ws1) with (??) "[Hl1 HI1]".
iExists _, I, R, _, _, cmp. iSplit; first done. iIntros "{$Hcmp} !> Hcz". wp_recv (ys2 ws2) with (??) "[Hl2 HI2]".
wp_apply (send_proto_spec with "Hcz"); simpl.
iExists xs2, l2, vs2. iSplit; first done. iIntros "{$Hl2 $HI2} !> Hcz".
wp_apply (recv_proto_spec with "Hcy"); simpl.
iIntros (ys1 ws1) "_". iDestruct 1 as (??) "[Hl1 HI1]".
wp_apply (recv_proto_spec with "Hcz"); simpl.
iIntros (ys2 ws2) "_". iDestruct 1 as (??) "[Hl2 HI2]".
do 2 wp_load. do 2 wp_load.
wp_apply (lmerge_spec with "Hcmp [$HI1 $HI2]"). iIntros (ws) "HI". wp_apply (lmerge_spec with "Hcmp [$HI1 $HI2]"). iIntros (ws) "HI".
wp_store. wp_store.
wp_apply (send_proto_spec with "Hc"); simpl. wp_send ((list_merge R ys1 ys2) ws) with "[$Hl $HI]".
iExists (list_merge R ys1 ys2), ws. - iSplit; iPureIntro.
iSplit; first done. iFrame. iSplit; iPureIntro. + by apply (Sorted_list_merge _).
- by apply (Sorted_list_merge _). + rewrite (merge_Permutation R). by f_equiv.
- rewrite (merge_Permutation R). by f_equiv. - by iApply "HΨ".
Qed. Qed.
Lemma list_sort_client_spec {A} (I : A val iProp Σ) R Lemma list_sort_client_spec {A} (I : A val iProp Σ) R
...@@ -143,17 +134,9 @@ Section list_sort. ...@@ -143,17 +134,9 @@ Section list_sort.
wp_apply (start_chan_proto_spec N sort_protocol); iIntros (c) "Hc". wp_apply (start_chan_proto_spec N sort_protocol); iIntros (c) "Hc".
{ rewrite -(right_id END%proto _ (iProto_dual _)). { rewrite -(right_id END%proto _ (iProto_dual _)).
wp_apply (list_sort_service_spec with "Hc"); auto. } wp_apply (list_sort_service_spec with "Hc"); auto. }
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$Hcmp]".
iExists _, I, R, _, _, cmp. wp_send with "[$Hl]".
iSplitR=> //. wp_recv (ys ws) with "(Hsorted & Hperm & Hl & HI)".
iSplitR=> //. wp_pures. iApply "HΦ"; iFrame.
iIntros "!> Hc".
wp_apply (send_proto_spec with "Hc"); simpl.
iExists xs, l, vs.
iSplitR=> //.
iIntros "{$Hl} !> Hc".
wp_apply (recv_proto_spec with "Hc"); simpl.
iIntros (ys ws) "Hc (Hsorted & Hperm & Hl & HI)".
wp_pures. iApply "HΦ". iFrame.
Qed. Qed.
End list_sort. End list_sort.
From stdpp Require Import sorting. From stdpp Require Import sorting.
From osiris.channel Require Import proto_channel. From osiris.channel Require Import proto_channel proofmode.
From iris.heap_lang Require Import proofmode notation. From iris.heap_lang Require Import proofmode notation.
From iris.heap_lang Require Import assert. From iris.heap_lang Require Import assert.
From osiris.utils Require Import list compare. From osiris.utils Require Import list compare.
...@@ -93,10 +93,9 @@ Section list_sort_elem. ...@@ -93,10 +93,9 @@ Section list_sort_elem.
Proof. Proof.
iIntros (Ψ) "(Hc & Hc1 & Hc2) HΨ". iLöb as "IH" forall (c c1 c2 xs xs1 xs2 Ψ). iIntros (Ψ) "(Hc & Hc1 & Hc2) HΨ". iLöb as "IH" forall (c c1 c2 xs xs1 xs2 Ψ).
wp_rec. wp_apply (branch_spec with "Hc"); iIntros ([]) "[Hc _]"; wp_pures. wp_rec. wp_apply (branch_spec with "Hc"); iIntros ([]) "[Hc _]"; wp_pures.
- wp_apply (recv_proto_spec with "Hc"); iIntros (x v) "/= Hc HI". - wp_recv (x v) with "HI".
wp_apply (select_spec with "[$Hc1]")=> //=; iIntros "Hc1". wp_apply (select_spec with "[$Hc1]")=> //=; iIntros "Hc1".
wp_apply (send_proto_spec with "Hc1"); simpl. wp_send with "[$HI]".
iExists x, v. iSplit; [done|]. iIntros "{$HI} !> Hc1".
wp_apply ("IH" with "Hc Hc2 Hc1"). wp_apply ("IH" with "Hc Hc2 Hc1").
iIntros (xs' xs1' xs2'); iDestruct 1 as (Hxs') "(Hc & Hc2 & Hc1)". iIntros (xs' xs1' xs2'); iDestruct 1 as (Hxs') "(Hc & Hc2 & Hc1)".
rewrite -!(assoc_L (++)). rewrite -!(assoc_L (++)).
...@@ -121,12 +120,9 @@ Section list_sort_elem. ...@@ -121,12 +120,9 @@ Section list_sort_elem.
iIntros (Hxs Hys Hsorted Hrel Ψ) "[Hc Hcin] HΨ". iIntros (Hxs Hys Hsorted Hrel Ψ) "[Hc Hcin] HΨ".
iLöb as "IH" forall (c cin xs ys xs' ys' Hxs Hys Hsorted Hrel). iLöb as "IH" forall (c cin xs ys xs' ys' Hxs Hys Hsorted Hrel).
wp_rec. wp_apply (branch_spec with "Hcin"); iIntros ([]) "[Hcin Hys']". wp_rec. wp_apply (branch_spec with "Hcin"); iIntros ([]) "[Hcin Hys']".
- iClear "Hys'". - iClear "Hys'". wp_recv (x v) with (Htl) "HI".
wp_apply (recv_proto_spec with "Hcin"); iIntros (x v) "/= Hcin".
iDestruct 1 as (Hx) "HI".
wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc". wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc".
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$HI]"; first by auto.
iExists x, v. iFrame "HI". do 2 (iSplit; [by auto|]); iIntros "!> Hc".
wp_apply ("IH" with "[%] [%] [%] [%] Hc Hcin HΨ"). wp_apply ("IH" with "[%] [%] [%] [%] Hc Hcin HΨ").
{ done. } { done. }
{ by rewrite Hys -!assoc_L (comm _ zs). } { by rewrite Hys -!assoc_L (comm _ zs). }
...@@ -158,13 +154,11 @@ Section list_sort_elem. ...@@ -158,13 +154,11 @@ Section list_sort_elem.
iLöb as "IH" forall (c1 c2 xs1 xs2 ys y1 w1 ys1 ys2 Hxs Hys Hsort Htl Htl_le). iLöb as "IH" forall (c1 c2 xs1 xs2 ys y1 w1 ys1 ys2 Hxs Hys Hsort Htl Htl_le).
wp_rec. wp_apply (branch_spec with "[$Hc2]"); iIntros ([]) "[Hc2 Hys2]". wp_rec. wp_apply (branch_spec with "[$Hc2]"); iIntros ([]) "[Hc2 Hys2]".
- iClear "Hys2". - iClear "Hys2".
wp_apply (recv_proto_spec with "Hc2"); iIntros (x v) "/= Hc2". wp_recv (x v) with (Htl2) "HIx".
iDestruct 1 as (Htl2) "HIx".
wp_pures. wp_apply ("Hcmp" with "[$HIy1 $HIx]"); iIntros "[HIy1 HIx]". wp_pures. wp_apply ("Hcmp" with "[$HIy1 $HIx]"); iIntros "[HIy1 HIx]".
case_bool_decide. case_bool_decide.
+ wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc". + wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc".
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$HIy1 //]".
iExists y1, w1. iFrame "HIy1". do 2 (iSplit; [done|]); iIntros "!> Hc".
wp_apply ("IH" with "[%] [%] [%] [%] [%] Hc Hc2 Hc1 HIx"). wp_apply ("IH" with "[%] [%] [%] [%] [%] Hc Hc2 Hc1 HIx").
{ by rewrite comm. } { by rewrite comm. }
{ by rewrite assoc (comm _ ys2) Hys. } { by rewrite assoc (comm _ ys2) Hys. }
...@@ -174,10 +168,8 @@ Section list_sort_elem. ...@@ -174,10 +168,8 @@ Section list_sort_elem.
inversion 1; discriminate_list || simplify_list_eq. by constructor. } inversion 1; discriminate_list || simplify_list_eq. by constructor. }
iIntros "(?&?&?)". iApply "HΨ"; iFrame. iIntros "(?&?&?)". iApply "HΨ"; iFrame.
+ wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc". + wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc".
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$HIx]".
iExists x, v. iFrame "HIx". iSplit; [done|]; iSplit.
{ iPureIntro. by apply Htl_le, total_not. } { iPureIntro. by apply Htl_le, total_not. }
iIntros "!> Hc".
wp_apply ("IH" with "[% //] [%] [%] [%] [%] Hc Hc1 Hc2 HIy1 HΨ"). wp_apply ("IH" with "[% //] [%] [%] [%] [%] Hc Hc1 Hc2 HIy1 HΨ").
{ by rewrite Hys assoc. } { by rewrite Hys assoc. }
{ rewrite fmap_app. by apply Sorted_snoc, Htl_le, total_not. } { rewrite fmap_app. by apply Sorted_snoc, Htl_le, total_not. }
...@@ -186,8 +178,7 @@ Section list_sort_elem. ...@@ -186,8 +178,7 @@ Section list_sort_elem.
inversion 1; discriminate_list || simplify_list_eq. by constructor. } inversion 1; discriminate_list || simplify_list_eq. by constructor. }
- iDestruct "Hys2" as %Hys2. - iDestruct "Hys2" as %Hys2.
wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc". wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc".
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$HIy1 //]".
iExists y1, w1. iFrame "HIy1". do 2 (iSplit; [done|]); iIntros "!> Hc".
wp_apply (list_sort_elem_service_move_spec with "[$Hc $Hc1]"). wp_apply (list_sort_elem_service_move_spec with "[$Hc $Hc1]").
{ done. } { done. }
{ by rewrite Hys Hys2 -!assoc_L (comm _ xs2). } { by rewrite Hys Hys2 -!assoc_L (comm _ xs2). }
...@@ -206,9 +197,9 @@ Section list_sort_elem. ...@@ -206,9 +197,9 @@ Section list_sort_elem.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ). iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ).
wp_rec; wp_pures. wp_rec; wp_pures.
wp_apply (branch_spec with "Hc"); iIntros ([]) "[Hc _]"; wp_pures. wp_apply (branch_spec with "Hc"); iIntros ([]) "[Hc _]"; wp_pures.
- wp_apply (recv_proto_spec with "Hc"); iIntros (x1 v1) "/= Hc HIx1". - wp_recv (x1 v1) with "HIx1".
wp_apply (branch_spec with "Hc"); iIntros ([]) "[Hc _]"; wp_pures. wp_apply (branch_spec with "Hc"); iIntros ([]) "[Hc _]"; wp_pures.
+ wp_apply (recv_proto_spec with "Hc"); iIntros (x2 v2) "/= Hc HIx2". + wp_recv (x2 v2) with "HIx2".
wp_apply (start_chan_proto_spec N list_sort_elem_protocol). wp_apply (start_chan_proto_spec N list_sort_elem_protocol).
{ iIntros (cy) "Hcy". wp_apply ("IH" with "Hcy"); auto. } { iIntros (cy) "Hcy". wp_apply ("IH" with "Hcy"); auto. }
iIntros (cy) "Hcy". iIntros (cy) "Hcy".
...@@ -216,26 +207,23 @@ Section list_sort_elem. ...@@ -216,26 +207,23 @@ Section list_sort_elem.
{ iIntros (cz) "Hcz". wp_apply ("IH" with "Hcz"); auto. } { iIntros (cz) "Hcz". wp_apply ("IH" with "Hcz"); auto. }
iIntros (cz) "Hcz". iIntros (cz) "Hcz".
wp_apply (select_spec with "[$Hcy]")=> //; iIntros "Hcy". wp_apply (select_spec with "[$Hcy]")=> //; iIntros "Hcy".
wp_apply (send_proto_spec with "Hcy")=> //=. wp_send with "[$HIx1]".
iExists x1, v1. iFrame "HIx1". iSplit; [done|]; iIntros "!> Hcy".
wp_apply (select_spec with "[$Hcz]")=> //; iIntros "Hcz". wp_apply (select_spec with "[$Hcz]")=> //; iIntros "Hcz".
wp_apply (send_proto_spec with "Hcz")=> //=. wp_send with "[$HIx2]".
iExists x2, v2. iFrame "HIx2". iSplit; [done|]; iIntros "!> Hcz".
wp_apply (list_sort_elem_service_split_spec with "[$Hc $Hcy $Hcz]"). wp_apply (list_sort_elem_service_split_spec with "[$Hc $Hcy $Hcz]").
iIntros (xs' xs1' xs2'); iDestruct 1 as (Hxs') "(Hc & Hcy & Hcz) /=". iIntros (xs' xs1' xs2'); iDestruct 1 as (Hxs') "(Hc & Hcy & Hcz) /=".
wp_apply (branch_spec with "Hcy"); iIntros (b) "[Hcy Hnil]". wp_apply (branch_spec with "Hcy"); iIntros (b) "[Hcy Hnil]".
destruct b; last first. destruct b; last first.
{ by iDestruct "Hnil" as %?%Permutation_nil_cons. } { by iDestruct "Hnil" as %?%Permutation_nil_cons. }
iClear "Hnil". iClear "Hnil".
wp_apply (recv_proto_spec with "Hcy"); iIntros (x v) "/= Hcy [_ HIx]". wp_recv (x v) with "[_ HIx]".
wp_apply (list_sort_elem_service_merge_spec _ _ _ _ _ [] _ _ _ _ [] [] wp_apply (list_sort_elem_service_merge_spec _ _ _ _ _ [] _ _ _ _ [] []
with "Hcmp [$Hc $Hcy $Hcz $HIx]"); simpl; auto using TlRel_nil, Sorted_nil. with "Hcmp [$Hc $Hcy $Hcz $HIx]"); simpl; auto using TlRel_nil, Sorted_nil.
{ by rewrite Hxs' Permutation_middle. } { by rewrite Hxs' Permutation_middle. }
iIntros "(Hc & Hcy & Hcz)". by iApply "HΨ". iIntros "(Hc & Hcy & Hcz)". by iApply "HΨ".
+ wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc". + wp_apply (select_spec with "[$Hc]")=> //=; iIntros "Hc".
wp_apply (send_proto_spec with "Hc"); simpl. wp_send with "[$HIx1]"; first by auto using TlRel_nil.
iExists x1, v1. iFrame "HIx1". do 2 (iSplit; [by auto using TlRel_nil|]). by wp_apply (select_spec with "[$Hc]").
iIntros "!> Hc". by wp_apply (select_spec with "[$Hc]").
- by wp_apply (select_spec with "[$Hc]"). - by wp_apply (select_spec with "[$Hc]").
Qed. Qed.
End list_sort_elem. End list_sort_elem.
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