Commit 16e1b090 authored by Robbert Krebbers's avatar Robbert Krebbers

Fix namespace for proto.

parent fbdbf1e6
......@@ -48,7 +48,7 @@ Notation ProtoUnfold p1 p2 := (∀ d pas q,
ProtoNormalize d p2 pas q ProtoNormalize d p1 pas q).
Section classes.
Context `{!proto_chanG Σ, !heapG Σ} (N : namespace).
Context `{!proto_chanG Σ, !heapG Σ}.
Implicit Types p : iProto Σ.
Implicit Types TT : tele.
......@@ -139,14 +139,14 @@ Section classes.
(** Automatically perform normalization of protocols in the proof mode *)
Global Instance mapsto_proto_from_assumption q c p1 p2 :
ProtoNormalize false p1 [] p2
FromAssumption q (c p1 @ N) (c p2 @ N).
FromAssumption q (c p1) (c p2).
Proof.
rewrite /FromAssumption /ProtoNormalize=> ->.
by rewrite /= right_id bi.intuitionistically_if_elim.
Qed.
Global Instance mapsto_proto_from_frame q c p1 p2 :
ProtoNormalize false p1 [] p2
Frame q (c p1 @ N) (c p2 @ N) True.
Frame q (c p1) (c p2) True.
Proof.
rewrite /Frame /ProtoNormalize=> ->.
by rewrite /= !right_id bi.intuitionistically_if_elim.
......@@ -155,14 +155,14 @@ End classes.
(** Symbolic execution tactics *)
(* TODO: strip laters *)
Lemma tac_wp_recv `{!proto_chanG Σ, !heapG Σ} {TT : tele} Δ i j K N
Lemma tac_wp_recv `{!proto_chanG Σ, !heapG Σ} {TT : tele} Δ i j K
c p (pc : TT val * iProp Σ * iProto Σ) Φ :
envs_lookup i Δ = Some (false, c p @ N)%I
envs_lookup i Δ = Some (false, c p)%I
ProtoNormalize false p [] (iProto_message Receive pc)
let Δ' := envs_delete false i false Δ in
(.. x : TT,
match envs_app false
(Esnoc (Esnoc Enil j ((pc x).1.2)) i (c (pc x).2 @ N)) Δ' with
(Esnoc (Esnoc Enil j ((pc x).1.2)) i (c (pc x).2)) Δ' with
| Some Δ'' => envs_entails Δ'' (WP fill K (of_val (pc x).1.1) {{ Φ }})
| None => False
end)
......@@ -179,7 +179,7 @@ Qed.
Tactic Notation "wp_recv_core" tactic3(tac_intros) "as" tactic3(tac) :=
let solve_mapsto _ :=
let c := match goal with |- _ = Some (_, (?c _ @ _)%I) => c end in
let c := match goal with |- _ = Some (_, (?c _)%I) => c end in
iAssumptionCore || fail "wp_recv: cannot find" c "↣ ? @ ?" in
wp_pures;
let Hnew := iFresh in
......@@ -233,15 +233,15 @@ Tactic Notation "wp_recv" "(" intropattern_list(xs) ")" "as" "(" simple_intropat
simple_intropattern(x8) ")" constr(pat) :=
wp_recv_core (intros xs) as (fun H => iDestructHyp H as ( x1 x2 x3 x4 x5 x6 x7 x8 ) pat).
Lemma tac_wp_send `{!proto_chanG Σ, !heapG Σ} {TT : tele} Δ neg i js K N
Lemma tac_wp_send `{!proto_chanG Σ, !heapG Σ} {TT : tele} Δ neg i js K
c v p (pc : TT val * iProp Σ * iProto Σ) Φ :
envs_lookup i Δ = Some (false, c p @ N)%I
envs_lookup i Δ = Some (false, c p)%I
ProtoNormalize false p [] (iProto_message Send pc)
let Δ' := envs_delete false i false Δ in
(.. x : TT,
match envs_split (if neg is true then Right else Left) js Δ' with
| Some (Δ1,Δ2) =>
match envs_app false (Esnoc Enil i (c (pc x).2 @ N)) Δ2 with
match envs_app false (Esnoc Enil i (c (pc x).2)) Δ2 with
| Some Δ2' =>
v = (pc x).1.1
envs_entails Δ1 (pc x).1.2
......@@ -265,7 +265,7 @@ Qed.
Tactic Notation "wp_send_core" tactic3(tac_exist) "with" constr(pat) :=
let solve_mapsto _ :=
let c := match goal with |- _ = Some (_, (?c _ @ _)%I) => c end in
let c := match goal with |- _ = Some (_, (?c _)%I) => c end in
iAssumptionCore || fail "wp_send: cannot find" c "↣ ? @ ?" in
let solve_done d :=
lazymatch d with
......@@ -327,14 +327,14 @@ Tactic Notation "wp_send" "(" uconstr(x1) uconstr(x2) uconstr(x3) uconstr(x4) ")
wp_send_core (eexists x1; eexists x2; eexists x3; eexists x4; eexists x5;
eexists x6; eexists x7; eexists x8) with pat.
Lemma tac_wp_branch `{!proto_chanG Σ, !heapG Σ} Δ i j K N
Lemma tac_wp_branch `{!proto_chanG Σ, !heapG Σ} Δ i j K
c p P1 P2 (p1 p2 : iProto Σ) Φ :
envs_lookup i Δ = Some (false, c p @ N)%I
envs_lookup i Δ = Some (false, c p)%I
ProtoNormalize false p [] (p1 <{P1}&{P2}> p2)
let Δ' := envs_delete false i false Δ in
( b : bool,
match envs_app false
(Esnoc (Esnoc Enil j (if b then P1 else P2)) i (c (if b then p1 else p2) @ N)) Δ' with
(Esnoc (Esnoc Enil j (if b then P1 else P2)) i (c (if b then p1 else p2))) Δ' with
| Some Δ'' => envs_entails Δ'' (WP fill K (of_val #b) {{ Φ }})
| None => False
end)
......@@ -350,7 +350,7 @@ Qed.
Tactic Notation "wp_branch_core" "as" tactic3(tac1) tactic3(tac2) :=
let solve_mapsto _ :=
let c := match goal with |- _ = Some (_, (?c _ @ _)%I) => c end in
let c := match goal with |- _ = Some (_, (?c _)%I) => c end in
iAssumptionCore || fail "wp_branch: cannot find" c "↣ ? @ ?" in
wp_pures;
let Hnew := iFresh in
......@@ -375,14 +375,14 @@ Tactic Notation "wp_branch" "as" "%" intropattern(pat1) "|" "%" intropattern(pat
wp_branch_core as (fun H => iPure H as pat1) (fun H => iPure H as pat2).
Tactic Notation "wp_branch" := wp_branch as %_ | %_.
Lemma tac_wp_select `{!proto_chanG Σ, !heapG Σ} Δ neg i js K N
Lemma tac_wp_select `{!proto_chanG Σ, !heapG Σ} Δ neg i js K
c (b : bool) p P1 P2 (p1 p2 : iProto Σ) Φ :
envs_lookup i Δ = Some (false, c p @ N)%I
envs_lookup i Δ = Some (false, c p)%I
ProtoNormalize false p [] (p1 <{P1}+{P2}> p2)
let Δ' := envs_delete false i false Δ in
match envs_split (if neg is true then Right else Left) js Δ' with
| Some (Δ1,Δ2) =>
match envs_app false (Esnoc Enil i (c if b then p1 else p2 @ N)) Δ2 with
match envs_app false (Esnoc Enil i (c if b then p1 else p2)) Δ2 with
| Some Δ2' =>
envs_entails Δ1 (if b then P1 else P2)
envs_entails Δ2' (WP fill K (of_val #()) {{ Φ }})
......@@ -404,7 +404,7 @@ Qed.
Tactic Notation "wp_select" "with" constr(pat) :=
let solve_mapsto _ :=
let c := match goal with |- _ = Some (_, (?c _ @ _)%I) => c end in
let c := match goal with |- _ = Some (_, (?c _)%I) => c end in
iAssumptionCore || fail "wp_select: cannot find" c "↣ ? @ ?" in
let solve_done d :=
lazymatch d with
......
This diff is collapsed.
......@@ -47,7 +47,7 @@ Definition prot2 : iProto Σ :=
(<?> l : loc, MSG #l {{ l #42 }}; END)%proto.
Definition prot3 : iProto Σ :=
(<?> c : val, MSG c {{ c prot1 @ nroot }}; END)%proto.
(<?> c : val, MSG c {{ c prot1 }}; END)%proto.
Definition prot4 : iProto Σ :=
(<!> x : Z, MSG #x; <?> MSG #(x + 2); END)%proto.
......@@ -68,7 +68,7 @@ Fixpoint prot_lock (n : nat) : iProto Σ :=
Lemma prog1_spec : {{{ True }}} prog1 #() {{{ RET #42; True }}}.
Proof.
iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot prot1); iIntros (c) "Hc".
wp_apply (start_chan_proto_spec prot1); iIntros (c) "Hc".
- by wp_send with "[]".
- wp_recv as "_". by iApply "HΦ".
Qed.
......@@ -76,7 +76,7 @@ Qed.
Lemma prog2_spec : {{{ True }}} prog2 #() {{{ RET #42; True }}}.
Proof.
iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot prot2); iIntros (c) "Hc".
wp_apply (start_chan_proto_spec prot2); iIntros (c) "Hc".
- wp_alloc l as "Hl". by wp_send with "[$Hl]".
- wp_recv (l) as "Hl". wp_load. by iApply "HΦ".
Qed.
......@@ -84,8 +84,8 @@ Qed.
Lemma prog3_spec : {{{ True }}} prog3 #() {{{ RET #42; True }}}.
Proof.
iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot prot3); iIntros (c) "Hc".
- wp_apply (new_chan_proto_spec nroot with "[//]").
wp_apply (start_chan_proto_spec prot3); iIntros (c) "Hc".
- wp_apply (new_chan_proto_spec with "[//]").
iIntros (c2 c2') "Hcc2". iMod ("Hcc2" $! prot1) as "[Hc2 Hc2']".
wp_send with "[$Hc2]". by wp_send with "[]".
- wp_recv (c2) as "Hc2". wp_recv as "_". by iApply "HΦ".
......@@ -94,7 +94,7 @@ Qed.
Lemma prog4_spec : {{{ True }}} prog4 #() {{{ RET #42; True }}}.
Proof.
iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot prot4); iIntros (c) "Hc".
wp_apply (start_chan_proto_spec prot4); iIntros (c) "Hc".
- wp_recv (x) as "_". by wp_send with "[]".
- wp_send with "[//]". wp_recv as "_". by iApply "HΦ".
Qed.
......@@ -102,7 +102,7 @@ Qed.
Lemma prog5_spec : {{{ True }}} prog5 #() {{{ RET #42; True }}}.
Proof.
iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot prot5); iIntros (c) "Hc".
wp_apply (start_chan_proto_spec prot5); iIntros (c) "Hc".
- wp_recv (P Ψ vf) as "#Hf". wp_send with "[]"; last done.
iIntros "!>" (Ψ') "HP HΨ'". wp_apply ("Hf" with "HP"); iIntros (x) "HΨ".
wp_pures. by iApply "HΨ'".
......@@ -117,12 +117,12 @@ Lemma prog_lock_spec `{!lockG Σ, contributionG Σ unitUR} :
{{{ True }}} prog_lock #() {{{ RET #42; True }}}.
Proof.
iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot (prot_lock 2)); iIntros (c) "Hc".
wp_apply (start_chan_proto_spec (prot_lock 2)); iIntros (c) "Hc".
- iMod (contribution_init) as (γ) "Hs".
iMod (alloc_client with "Hs") as "[Hs Hcl1]".
iMod (alloc_client with "Hs") as "[Hs Hcl2]".
wp_apply (newlock_spec nroot ( n, server γ n ε
c iProto_dual (prot_lock n) @ nroot)%I
c iProto_dual (prot_lock n))%I
with "[Hc Hs]"); first by eauto with iFrame.
iIntros (lk γlk) "#Hlk".
iAssert ( (client γ ε -
......
......@@ -26,7 +26,7 @@ Definition sort_service_br_del : val :=
else #().
Section sort_service_br_del.
Context `{!heapG Σ, !proto_chanG Σ} (N : namespace).
Context `{!heapG Σ, !proto_chanG Σ}.
Context {A} (I : A val iProp Σ) (R : A A Prop) `{!RelDecision R, !Total R}.
Definition sort_protocol_br_aux (rec : iProto Σ) : iProto Σ :=
......@@ -40,9 +40,9 @@ Section sort_service_br_del.
Lemma sort_service_br_spec cmp c :
cmp_spec I R cmp -
{{{ c iProto_dual sort_protocol_br @ N }}}
{{{ c iProto_dual sort_protocol_br }}}
sort_service_br cmp c
{{{ RET #(); c END @ N }}}.
{{{ RET #(); c END }}}.
Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ).
wp_rec. wp_branch; wp_pures.
......@@ -52,7 +52,7 @@ Section sort_service_br_del.
Qed.
Definition sort_protocol_del_aux (rec : iProto Σ) : iProto Σ :=
((<?> c, MSG c {{ c sort_protocol I R @ N }}; rec) <+> END)%proto.
((<?> c, MSG c {{ c sort_protocol I R }}; rec) <+> END)%proto.
Instance sort_protocol_del_aux_contractive : Contractive sort_protocol_del_aux.
Proof. solve_proto_contractive. Qed.
Definition sort_protocol_del : iProto Σ := fixpoint sort_protocol_del_aux.
......@@ -62,13 +62,13 @@ Section sort_service_br_del.
Lemma sort_protocol_del_spec cmp c :
cmp_spec I R cmp -
{{{ c iProto_dual sort_protocol_del @ N }}}
{{{ c iProto_dual sort_protocol_del }}}
sort_service_del cmp c
{{{ RET #(); c END @ N }}}.
{{{ RET #(); c END }}}.
Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (Ψ).
wp_rec. wp_branch; wp_pures.
{ wp_apply (start_chan_proto_spec _ (sort_protocol I R <++> END)%proto);
{ wp_apply (start_chan_proto_spec (sort_protocol I R <++> END)%proto);
iIntros (c') "Hc'".
{ wp_pures. wp_apply (sort_service_spec with "Hcmp Hc'"); auto. }
wp_send with "[$Hc']". by wp_apply ("IH" with "Hc"). }
......@@ -76,7 +76,7 @@ Section sort_service_br_del.
Qed.
Definition sort_protocol_br_del_aux (rec : iProto Σ) : iProto Σ :=
((sort_protocol I R <++> rec) <+> ((<?> c, MSG c {{ c rec @ N }}; rec) <+> END))%proto.
((sort_protocol I R <++> rec) <+> ((<?> c, MSG c {{ c rec }}; rec) <+> END))%proto.
Instance sort_protocol_br_del_aux_contractive : Contractive sort_protocol_br_del_aux.
Proof. solve_proto_contractive. Qed.
Definition sort_protocol_br_del : iProto Σ := fixpoint sort_protocol_br_del_aux.
......@@ -86,16 +86,16 @@ Section sort_service_br_del.
Lemma sort_service_br_del_spec cmp c :
cmp_spec I R cmp -
{{{ c iProto_dual sort_protocol_br_del @ N }}}
{{{ c iProto_dual sort_protocol_br_del }}}
sort_service_br_del cmp c
{{{ RET #(); c END @ N }}}.
{{{ RET #(); c END }}}.
Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ).
wp_rec. wp_branch; wp_pures.
{ wp_apply (sort_service_spec with "Hcmp Hc"); iIntros "Hc".
by wp_apply ("IH" with "Hc"). }
wp_branch; wp_pures.
{ wp_apply (start_chan_proto_spec N sort_protocol_br_del); iIntros (c') "Hc'".
{ wp_apply (start_chan_proto_spec sort_protocol_br_del); iIntros (c') "Hc'".
{ wp_apply ("IH" with "Hc'"); auto. }
wp_send with "[$Hc']".
by wp_apply ("IH" with "Hc"). }
......
......@@ -56,7 +56,7 @@ Class mapG Σ A `{Countable A} := {
Section map.
Context `{Countable A} {B : Type}.
Context `{!heapG Σ, !proto_chanG Σ, !mapG Σ A} (N : namespace).
Context `{!heapG Σ, !proto_chanG Σ, !mapG Σ A}.
Context (IA : A val iProp Σ) (IB : B val iProp Σ) (map : A list B).
Local Open Scope nat_scope.
Implicit Types n : nat.
......@@ -82,11 +82,11 @@ Section map.
Proof. apply proto_unfold_eq, (fixpoint_unfold par_map_protocol_aux). Qed.
Definition map_worker_lock_inv (γ : gname) (c : val) : iProp Σ :=
( i X, server γ i X c iProto_dual (par_map_protocol i X) @ N)%I.
( i X, server γ i X c iProto_dual (par_map_protocol i X))%I.
Lemma par_map_worker_spec γl γ vmap lk c :
map_spec vmap -
{{{ is_lock N γl lk (map_worker_lock_inv γ c) client γ ( : gmultiset A) }}}
{{{ is_lock nroot γl lk (map_worker_lock_inv γ c) client γ ( : gmultiset A) }}}
par_map_worker vmap lk c
{{{ RET #(); True }}}.
Proof.
......@@ -126,7 +126,7 @@ Section map.
Lemma par_map_workers_spec γl γ n vmap lk c :
map_spec vmap -
{{{ is_lock N γl lk (map_worker_lock_inv γ c)
{{{ is_lock nroot γl lk (map_worker_lock_inv γ c)
[] replicate n (client γ (:gmultiset A)) }}}
par_map_workers #n vmap lk c
{{{ RET #(); True }}}.
......@@ -143,13 +143,13 @@ Section map.
Lemma par_map_service_spec n vmap c :
map_spec vmap -
{{{ c iProto_dual (par_map_protocol n ) @ N }}}
{{{ c iProto_dual (par_map_protocol n ) }}}
par_map_service #n vmap c
{{{ RET #(); True }}}.
Proof.
iIntros "#Hf !>"; iIntros (Φ) "Hc HΦ". wp_lam; wp_pures.
iMod (contribution_init_pow (A:=gmultisetUR A) n) as (γ) "[Hs Hγs]".
wp_apply (newlock_spec N (map_worker_lock_inv γ c) with "[Hc Hs]").
wp_apply (newlock_spec nroot (map_worker_lock_inv γ c) with "[Hc Hs]").
{ iExists n, . iFrame. }
iIntros (lk γl) "#Hlk".
wp_apply (par_map_workers_spec with "Hf [$Hlk $Hγs]"); auto.
......@@ -157,7 +157,7 @@ Section map.
Lemma par_map_client_loop_spec n c l k xs X ys :
(n = 0 X = xs = [])
{{{ llist IA l xs llist IB k ys c par_map_protocol n X @ N }}}
{{{ llist IA l xs llist IB k ys c par_map_protocol n X }}}
par_map_client_loop #n c #l #k
{{{ ys', RET #();
ys' ≡ₚ (xs ++ elements X) = map llist IA l [] llist IB k (ys' ++ ys)
......@@ -198,7 +198,7 @@ Section map.
{{{ ys, RET #(); ys ≡ₚ xs = map llist IB l ys }}}.
Proof.
iIntros (?) "#Hmap !>"; iIntros (Φ) "Hl HΦ". wp_lam; wp_pures.
wp_apply (start_chan_proto_spec N (par_map_protocol n )); iIntros (c) "// Hc".
wp_apply (start_chan_proto_spec (par_map_protocol n )); iIntros (c) "// Hc".
{ wp_apply (par_map_service_spec with "Hmap Hc"); auto. }
wp_pures. wp_apply (lnil_spec with "[//]"); iIntros (k) "Hk".
wp_apply (par_map_client_loop_spec with "[$Hl $Hk $Hc //]"); first lia.
......
......@@ -95,7 +95,7 @@ Class map_reduceG Σ A B `{Countable A, Countable B} := {
Section mapper.
Context `{Countable A, Countable B} {C : Type}.
Context `{!heapG Σ, !proto_chanG Σ, !map_reduceG Σ A B} (N : namespace).
Context `{!heapG Σ, !proto_chanG Σ, !map_reduceG Σ A B}.
Context (IA : A val iProp Σ) (IB : Z B val iProp Σ) (IC : C val iProp Σ).
Context (map : A list (Z * B)) (red : Z list B list C).
Context `{! j, Proper ((≡ₚ) ==> (≡ₚ)) (red j)}.
......@@ -127,13 +127,13 @@ Section mapper.
(n = 0 X = xs = [])
{{{
llist IA l xs
cmap par_map_protocol IA IZB map n (X : gmultiset A) @ N
csort sort_fg_head_protocol IZB RZB ys @ N
cmap par_map_protocol IA IZB map n (X : gmultiset A)
csort sort_fg_head_protocol IZB RZB ys
}}}
par_map_reduce_map #n cmap csort #l
{{{ ys', RET #();
ys' ≡ₚ (xs ++ elements X) = map
llist IA l [] csort sort_fg_head_protocol IZB RZB (ys ++ ys') @ N
llist IA l [] csort sort_fg_head_protocol IZB RZB (ys ++ ys')
}}}.
Proof.
iIntros (Hn Φ) "(Hl & Hcmap & Hcsort) HΦ".
......@@ -172,7 +172,7 @@ Section mapper.
i iys_sorted.*1
{{{
llist (IB i) l (reverse ys)
csort sort_fg_tail_protocol IZB RZB iys (iys_sorted ++ ((i,) <$> ys)) @ N
csort sort_fg_tail_protocol IZB RZB iys (iys_sorted ++ ((i,) <$> ys))
}}}
par_map_reduce_collect csort #i #l
{{{ ys' miy, RET accv miy;
......@@ -181,7 +181,7 @@ Section mapper.
(iys_sorted ++ ((i,) <$> ys ++ ys') ≡ₚ iys) miy
llist (IB i) l (reverse (ys ++ ys'))
csort from_option (λ _, sort_fg_tail_protocol IZB RZB iys
((iys_sorted ++ ((i,) <$> ys ++ ys')) ++ acc miy)) END%proto miy @ N
((iys_sorted ++ ((i,) <$> ys ++ ys')) ++ acc miy)) END%proto miy
from_option (λ '(i,y,w), IB i y w) True miy
}}}.
Proof.
......@@ -222,8 +222,8 @@ Section mapper.
{{{
llist IC l zs
csort from_option (λ _, sort_fg_tail_protocol IZB RZB iys
(iys_sorted ++ acc miy)) END%proto miy @ N
cred par_map_protocol IZBs IC (curry red) n (Y : gmultiset (Z * list B)) @ N
(iys_sorted ++ acc miy)) END%proto miy
cred par_map_protocol IZBs IC (curry red) n (Y : gmultiset (Z * list B))
from_option (λ '(i,y,w), IB i y w) True miy
}}}
par_map_reduce_reduce #n csort cred (accv miy) #l
......@@ -280,18 +280,18 @@ Section mapper.
{{{ zs, RET #(); zs ≡ₚ map_reduce map red xs llist IC l zs }}}.
Proof.
iIntros (?) "#Hmap #Hred !>"; iIntros (Φ) "Hl HΦ". wp_lam; wp_pures.
wp_apply (start_chan_proto_spec N (par_map_protocol IA IZB map n ));
wp_apply (start_chan_proto_spec (par_map_protocol IA IZB map n ));
iIntros (cmap) "// Hcmap".
{ wp_pures. wp_apply (par_map_service_spec with "Hmap Hcmap"); auto. }
wp_apply (start_chan_proto_spec N (sort_fg_protocol IZB RZB <++> END)%proto);
wp_apply (start_chan_proto_spec (sort_fg_protocol IZB RZB <++> END)%proto);
iIntros (csort) "Hcsort".
{ wp_apply (sort_service_fg_spec N with "[] Hcsort"); last by auto.
{ wp_apply (sort_service_fg_spec with "[] Hcsort"); last by auto.
iApply RZB_cmp_spec. }
rewrite right_id.
wp_apply (par_map_reduce_map_spec with "[$Hl $Hcmap $Hcsort]"); first lia.
iIntros (iys). rewrite gmultiset_elements_empty right_id_L.
iDestruct 1 as (Hiys) "[Hl Hcsort] /=". wp_select; wp_pures; simpl.
wp_apply (start_chan_proto_spec N (par_map_protocol IZBs IC (curry red) n ));
wp_apply (start_chan_proto_spec (par_map_protocol IZBs IC (curry red) n ));
iIntros (cred) "// Hcred".
{ wp_pures. wp_apply (par_map_service_spec with "Hred Hcred"); auto. }
wp_branch as %_|%Hnil; last first.
......
......@@ -36,7 +36,7 @@ Definition sort_client_func : val := λ: "cmp" "xs",
recv "c".
Section sort.
Context `{!heapG Σ, !proto_chanG Σ} (N : namespace).
Context `{!heapG Σ, !proto_chanG Σ}.
Definition sort_protocol {A} (I : A val iProp Σ) (R : A A Prop)
`{!RelDecision R, !Total R} : iProto Σ :=
......@@ -87,9 +87,9 @@ Section sort.
Lemma sort_service_spec {A} (I : A val iProp Σ) (R : A A Prop)
`{!RelDecision R, !Total R} (cmp : val) p c :
cmp_spec I R cmp -
{{{ c iProto_dual (sort_protocol I R) <++> p @ N }}}
{{{ c (iProto_dual (sort_protocol I R) <++> p) }}}
sort_service cmp c
{{{ RET #(); c p @ N }}}.
{{{ RET #(); c p }}}.
Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (p c Ψ). wp_lam.
wp_recv (xs l) as "Hl".
......@@ -100,10 +100,10 @@ Section sort.
wp_send with "[$Hl]"; first by auto. by iApply "HΨ". }
wp_apply (lsplit_spec with "Hl"); iIntros (l2 vs1 vs2);
iDestruct 1 as (->) "[Hl1 Hl2]".
wp_apply (start_chan_proto_spec N (sort_protocol I R)); iIntros (cy) "Hcy".
wp_apply (start_chan_proto_spec (sort_protocol I R)); iIntros (cy) "Hcy".
{ rewrite -{2}(right_id END%proto _ (iProto_dual _)).
wp_apply ("IH" with "Hcy"); auto. }
wp_apply (start_chan_proto_spec N (sort_protocol I R)); iIntros (cz) "Hcz".
wp_apply (start_chan_proto_spec (sort_protocol I R)); iIntros (cz) "Hcz".
{ rewrite -{2}(right_id END%proto _ (iProto_dual _)).
wp_apply ("IH" with "Hcz"); auto. }
wp_send with "[$Hl1]".
......@@ -119,9 +119,9 @@ Section sort.
Qed.
Lemma sort_service_func_spec p c :
{{{ c iProto_dual sort_protocol_func <++> p @ N }}}
{{{ c (iProto_dual sort_protocol_func <++> p) }}}
sort_service_func c
{{{ RET #(); c p @ N }}}.
{{{ RET #(); c p }}}.
Proof.
iIntros (Ψ) "Hc HΨ". wp_lam.
wp_recv (A I R ?? cmp) as "#Hcmp".
......@@ -136,7 +136,7 @@ Section sort.
{{{ ys, RET #(); Sorted R ys ys ≡ₚ xs llist I l ys }}}.
Proof.
iIntros "#Hcmp !>" (Φ) "Hl HΦ". wp_lam.
wp_apply (start_chan_proto_spec N sort_protocol_func); iIntros (c) "Hc".
wp_apply (start_chan_proto_spec sort_protocol_func); iIntros (c) "Hc".
{ rewrite -(right_id END%proto _ (iProto_dual _)).
wp_apply (sort_service_func_spec with "Hc"); auto. }
wp_send with "[$Hcmp]".
......
......@@ -52,7 +52,7 @@ Definition sort_service_fg_func : val := λ: "c",
sort_service_fg "cmp" "c".
Section sort_fg.
Context `{!heapG Σ, !proto_chanG Σ} (N : namespace).
Context `{!heapG Σ, !proto_chanG Σ}.
Section sort_fg_inner.
Context {A} (I : A val iProp Σ) (R : relation A) `{!RelDecision R, !Total R}.
......@@ -92,15 +92,15 @@ Section sort_fg.
Lemma sort_service_fg_split_spec c p c1 c2 xs xs1 xs2 :
{{{
c iProto_dual (sort_fg_head_protocol xs) <++> p @ N
c1 sort_fg_head_protocol xs1 @ N c2 sort_fg_head_protocol xs2 @ N
c (iProto_dual (sort_fg_head_protocol xs) <++> p)
c1 sort_fg_head_protocol xs1 c2 sort_fg_head_protocol xs2
}}}
sort_service_fg_split c c1 c2
{{{ xs' xs1' xs2', RET #();
xs' ≡ₚ xs1' ++ xs2'
c iProto_dual (sort_fg_tail_protocol (xs ++ xs') []) <++> p @ N
c1 sort_fg_tail_protocol (xs1 ++ xs1') [] @ N
c2 sort_fg_tail_protocol (xs2 ++ xs2') [] @ N
c (iProto_dual (sort_fg_tail_protocol (xs ++ xs') []) <++> p)
c1 sort_fg_tail_protocol (xs1 ++ xs1') []
c2 sort_fg_tail_protocol (xs2 ++ xs2') []
}}}.
Proof.
iIntros (Ψ) "(Hc & Hc1 & Hc2) HΨ". iLöb as "IH" forall (c c1 c2 xs xs1 xs2 Ψ).
......@@ -120,11 +120,11 @@ Section sort_fg.
Sorted R ys
( x, TlRel R x ys' TlRel R x ys)
{{{
c iProto_dual (sort_fg_tail_protocol xs ys) <++> p @ N
cin sort_fg_tail_protocol xs' ys' @ N
c (iProto_dual (sort_fg_tail_protocol xs ys) <++> p)
cin sort_fg_tail_protocol xs' ys'
}}}
sort_service_fg_forward c cin
{{{ RET #(); c p @ N cin END @ N }}}.
{{{ RET #(); c p cin END }}}.
Proof.
iIntros (Hxs Hys Hsorted Hrel Ψ) "[Hc Hcin] HΨ".
iLöb as "IH" forall (c cin xs ys xs' ys' Hxs Hys Hsorted Hrel).
......@@ -150,13 +150,13 @@ Section sort_fg.
( x, TlRel R x ys2 R x y1 TlRel R x ys)
cmp_spec I R cmp -
{{{
c iProto_dual (sort_fg_tail_protocol xs ys) <++> p @ N
c1 sort_fg_tail_protocol xs1 (ys1 ++ [y1]) @ N
c2 sort_fg_tail_protocol xs2 ys2 @ N
c (iProto_dual (sort_fg_tail_protocol xs ys) <++> p)
c1 sort_fg_tail_protocol xs1 (ys1 ++ [y1])
c2 sort_fg_tail_protocol xs2 ys2
I y1 w1
}}}
sort_service_fg_merge cmp c w1 c1 c2
{{{ RET #(); c p @ N }}}.
{{{ RET #(); c p }}}.
Proof.
iIntros (Hxs Hys Hsort Htl Htl_le) "#Hcmp !>".
iIntros (Ψ) "(Hc & Hc1 & Hc2 & HIy1) HΨ".
......@@ -193,18 +193,18 @@ Section sort_fg.
Lemma sort_service_fg_spec cmp c p :
cmp_spec I R cmp -
{{{ c iProto_dual sort_fg_protocol <++> p @ N }}}
{{{ c (iProto_dual sort_fg_protocol <++> p) }}}
sort_service_fg cmp c
{{{ RET #(); c p @ N }}}.
{{{ RET #(); c p }}}.
Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c p Ψ).
wp_rec; wp_pures. wp_branch; wp_pures.
- wp_recv (x1 v1) as "HIx1". wp_branch; wp_pures.
+ wp_recv (x2 v2) as "HIx2".
wp_apply (start_chan_proto_spec N (sort_fg_protocol <++> END)%proto).
wp_apply (start_chan_proto_spec (sort_fg_protocol <++> END)%proto).
{ iIntros (cy) "Hcy". wp_apply ("IH" with "Hcy"). auto. }
iIntros (cy) "Hcy".
wp_apply (start_chan_proto_spec N (sort_fg_protocol <++> END)%proto).
wp_apply (start_chan_proto_spec (sort_fg_protocol <++> END)%proto).
{ iIntros (cz) "Hcz". wp_apply ("IH" with "Hcz"); auto. }
iIntros (cz) "Hcz". rewrite !right_id.
wp_select. wp_send with "[$HIx1]".
......@@ -229,9 +229,9 @@ Section sort_fg.
sort_fg_head_protocol I R [])%proto.
Lemma sort_service_fg_func_spec c p :
{{{ c iProto_dual sort_fg_func_protocol <++> p @ N }}}
{{{ c (iProto_dual sort_fg_func_protocol <++> p) }}}
sort_service_fg_func c
{{{ RET #(); c p @ N }}}.
{{{ RET #(); c p }}}.
Proof.
iIntros (Ψ) "Hc HΨ". wp_lam.
wp_recv (A I R ? ? cmp) as "#Hcmp".
......
......@@ -23,13 +23,13 @@ Definition sort_client_fg : val := λ: "cmp" "xs",
recv_all "c" "xs".
Section sort_fg_client.
Context `{!heapG Σ, !proto_chanG Σ} (N : namespace).
Context `{!heapG Σ, !proto_chanG Σ}.
Context {A} (I : A val iProp Σ) (R : relation A) `{!RelDecision R, !Total R}.
Lemma send_all_spec c p xs' l xs :
{{{ llist I l xs c sort_fg_head_protocol I R xs' <++> p @ N }}}
{{{ llist I l xs c (sort_fg_head_protocol I R xs' <++> p) }}}
send_all c #l
{{{ RET #(); llist I l [] c sort_fg_head_protocol I R (xs' ++ xs) <++> p @ N }}}.
{{{ RET #(); llist I l [] c (sort_fg_head_protocol I R (xs' ++ xs) <++> p) }}}.
Proof.
iIntros (Φ) "[Hl Hc] HΦ".
iInduction xs as [|x xs] "IH" forall (xs').
......@@ -42,10 +42,10 @@ Section sort_fg_client.
Lemma recv_all_spec c p l xs ys' :
Sorted R ys'
{{{ llist I l [] c sort_fg_tail_protocol I R xs ys' <++> p @ N }}}
{{{ llist I l [] c (sort_fg_tail_protocol I R xs ys' <++> p) }}}
recv_all c #l
{{{ ys, RET #();
Sorted R (ys' ++ ys) ys' ++ ys ≡ₚ xs llist I l ys c p @ N
Sorted R (ys' ++ ys) ys' ++ ys ≡ₚ xs llist I l ys c p
}}}.
Proof.
iIntros (Hsort Φ) "[Hl Hc] HΦ".
......@@ -66,9 +66,9 @@ Section sort_fg_client.
{{{ ys, RET #(); Sorted R ys ys ≡ₚ xs llist I l ys }}}.
Proof.
iIntros "#Hcmp !>" (Φ) "Hl HΦ". wp_lam.
wp_apply (start_chan_proto_spec N (sort_fg_protocol I R <++> END)%proto);
wp_apply (start_chan_proto_spec (sort_fg_protocol I R <++> END)%proto);
iIntros (c) "Hc".
{ wp_apply (sort_service_fg_spec N with "Hcmp Hc"); auto. }
{ wp_apply (sort_service_fg_spec with "Hcmp Hc"); auto. }
wp_apply (send_all_spec with "[$Hl $Hc]"); iIntros "[Hl Hc]".