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, ...@@ -48,7 +48,7 @@ Notation ProtoUnfold p1 p2 := (∀ d pas q,
ProtoNormalize d p2 pas q ProtoNormalize d p1 pas q). ProtoNormalize d p2 pas q ProtoNormalize d p1 pas q).
Section classes. Section classes.
Context `{!proto_chanG Σ, !heapG Σ} (N : namespace). Context `{!proto_chanG Σ, !heapG Σ}.
Implicit Types p : iProto Σ. Implicit Types p : iProto Σ.
Implicit Types TT : tele. Implicit Types TT : tele.
...@@ -139,14 +139,14 @@ Section classes. ...@@ -139,14 +139,14 @@ Section classes.
(** Automatically perform normalization of protocols in the proof mode *) (** Automatically perform normalization of protocols in the proof mode *)
Global Instance mapsto_proto_from_assumption q c p1 p2 : Global Instance mapsto_proto_from_assumption q c p1 p2 :
ProtoNormalize false p1 [] p2 ProtoNormalize false p1 [] p2
FromAssumption q (c p1 @ N) (c p2 @ N). FromAssumption q (c p1) (c p2).
Proof. Proof.
rewrite /FromAssumption /ProtoNormalize=> ->. rewrite /FromAssumption /ProtoNormalize=> ->.
by rewrite /= right_id bi.intuitionistically_if_elim. by rewrite /= right_id bi.intuitionistically_if_elim.
Qed. Qed.
Global Instance mapsto_proto_from_frame q c p1 p2 : Global Instance mapsto_proto_from_frame q c p1 p2 :
ProtoNormalize false p1 [] p2 ProtoNormalize false p1 [] p2
Frame q (c p1 @ N) (c p2 @ N) True. Frame q (c p1) (c p2) True.
Proof. Proof.
rewrite /Frame /ProtoNormalize=> ->. rewrite /Frame /ProtoNormalize=> ->.
by rewrite /= !right_id bi.intuitionistically_if_elim. by rewrite /= !right_id bi.intuitionistically_if_elim.
...@@ -155,14 +155,14 @@ End classes. ...@@ -155,14 +155,14 @@ End classes.
(** Symbolic execution tactics *) (** Symbolic execution tactics *)
(* TODO: strip laters *) (* 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 Σ) Φ : 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) ProtoNormalize false p [] (iProto_message Receive pc)
let Δ' := envs_delete false i false Δ in let Δ' := envs_delete false i false Δ in
(.. x : TT, (.. x : TT,
match envs_app false 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) {{ Φ }}) | Some Δ'' => envs_entails Δ'' (WP fill K (of_val (pc x).1.1) {{ Φ }})
| None => False | None => False
end) end)
...@@ -179,7 +179,7 @@ Qed. ...@@ -179,7 +179,7 @@ Qed.
Tactic Notation "wp_recv_core" tactic3(tac_intros) "as" tactic3(tac) := Tactic Notation "wp_recv_core" tactic3(tac_intros) "as" tactic3(tac) :=
let solve_mapsto _ := 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 iAssumptionCore || fail "wp_recv: cannot find" c "↣ ? @ ?" in
wp_pures; wp_pures;
let Hnew := iFresh in let Hnew := iFresh in
...@@ -233,15 +233,15 @@ Tactic Notation "wp_recv" "(" intropattern_list(xs) ")" "as" "(" simple_intropat ...@@ -233,15 +233,15 @@ Tactic Notation "wp_recv" "(" intropattern_list(xs) ")" "as" "(" simple_intropat
simple_intropattern(x8) ")" constr(pat) := 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). 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 Σ) Φ : 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) ProtoNormalize false p [] (iProto_message Send pc)
let Δ' := envs_delete false i false Δ in let Δ' := envs_delete false i false Δ in
(.. x : TT, (.. x : TT,
match envs_split (if neg is true then Right else Left) js Δ' with match envs_split (if neg is true then Right else Left) js Δ' with
| Some (Δ1,Δ2) => | 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' => | Some Δ2' =>
v = (pc x).1.1 v = (pc x).1.1
envs_entails Δ1 (pc x).1.2 envs_entails Δ1 (pc x).1.2
...@@ -265,7 +265,7 @@ Qed. ...@@ -265,7 +265,7 @@ Qed.
Tactic Notation "wp_send_core" tactic3(tac_exist) "with" constr(pat) := Tactic Notation "wp_send_core" tactic3(tac_exist) "with" constr(pat) :=
let solve_mapsto _ := 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 iAssumptionCore || fail "wp_send: cannot find" c "↣ ? @ ?" in
let solve_done d := let solve_done d :=
lazymatch d with lazymatch d with
...@@ -327,14 +327,14 @@ Tactic Notation "wp_send" "(" uconstr(x1) uconstr(x2) uconstr(x3) uconstr(x4) ") ...@@ -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; wp_send_core (eexists x1; eexists x2; eexists x3; eexists x4; eexists x5;
eexists x6; eexists x7; eexists x8) with pat. 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 Σ) Φ : 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) ProtoNormalize false p [] (p1 <{P1}&{P2}> p2)
let Δ' := envs_delete false i false Δ in let Δ' := envs_delete false i false Δ in
( b : bool, ( b : bool,
match envs_app false 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) {{ Φ }}) | Some Δ'' => envs_entails Δ'' (WP fill K (of_val #b) {{ Φ }})
| None => False | None => False
end) end)
...@@ -350,7 +350,7 @@ Qed. ...@@ -350,7 +350,7 @@ Qed.
Tactic Notation "wp_branch_core" "as" tactic3(tac1) tactic3(tac2) := Tactic Notation "wp_branch_core" "as" tactic3(tac1) tactic3(tac2) :=
let solve_mapsto _ := 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 iAssumptionCore || fail "wp_branch: cannot find" c "↣ ? @ ?" in
wp_pures; wp_pures;
let Hnew := iFresh in let Hnew := iFresh in
...@@ -375,14 +375,14 @@ Tactic Notation "wp_branch" "as" "%" intropattern(pat1) "|" "%" intropattern(pat ...@@ -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). wp_branch_core as (fun H => iPure H as pat1) (fun H => iPure H as pat2).
Tactic Notation "wp_branch" := wp_branch as %_ | %_. 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 Σ) Φ : 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) ProtoNormalize false p [] (p1 <{P1}+{P2}> p2)
let Δ' := envs_delete false i false Δ in let Δ' := envs_delete false i false Δ in
match envs_split (if neg is true then Right else Left) js Δ' with match envs_split (if neg is true then Right else Left) js Δ' with
| Some (Δ1,Δ2) => | 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' => | Some Δ2' =>
envs_entails Δ1 (if b then P1 else P2) envs_entails Δ1 (if b then P1 else P2)
envs_entails Δ2' (WP fill K (of_val #()) {{ Φ }}) envs_entails Δ2' (WP fill K (of_val #()) {{ Φ }})
...@@ -404,7 +404,7 @@ Qed. ...@@ -404,7 +404,7 @@ Qed.
Tactic Notation "wp_select" "with" constr(pat) := Tactic Notation "wp_select" "with" constr(pat) :=
let solve_mapsto _ := 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 iAssumptionCore || fail "wp_select: cannot find" c "↣ ? @ ?" in
let solve_done d := let solve_done d :=
lazymatch d with lazymatch d with
......
This diff is collapsed.
...@@ -47,7 +47,7 @@ Definition prot2 : iProto Σ := ...@@ -47,7 +47,7 @@ Definition prot2 : iProto Σ :=
(<?> l : loc, MSG #l {{ l #42 }}; END)%proto. (<?> l : loc, MSG #l {{ l #42 }}; END)%proto.
Definition prot3 : iProto Σ := Definition prot3 : iProto Σ :=
(<?> c : val, MSG c {{ c prot1 @ nroot }}; END)%proto. (<?> c : val, MSG c {{ c prot1 }}; END)%proto.
Definition prot4 : iProto Σ := Definition prot4 : iProto Σ :=
(<!> x : Z, MSG #x; <?> MSG #(x + 2); END)%proto. (<!> x : Z, MSG #x; <?> MSG #(x + 2); END)%proto.
...@@ -68,7 +68,7 @@ Fixpoint prot_lock (n : nat) : iProto Σ := ...@@ -68,7 +68,7 @@ Fixpoint prot_lock (n : nat) : iProto Σ :=
Lemma prog1_spec : {{{ True }}} prog1 #() {{{ RET #42; True }}}. Lemma prog1_spec : {{{ True }}} prog1 #() {{{ RET #42; True }}}.
Proof. Proof.
iIntros (Φ) "_ HΦ". wp_lam. 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 "[]". - by wp_send with "[]".
- wp_recv as "_". by iApply "HΦ". - wp_recv as "_". by iApply "HΦ".
Qed. Qed.
...@@ -76,7 +76,7 @@ Qed. ...@@ -76,7 +76,7 @@ Qed.
Lemma prog2_spec : {{{ True }}} prog2 #() {{{ RET #42; True }}}. Lemma prog2_spec : {{{ True }}} prog2 #() {{{ RET #42; True }}}.
Proof. Proof.
iIntros (Φ) "_ HΦ". wp_lam. 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_alloc l as "Hl". by wp_send with "[$Hl]".
- wp_recv (l) as "Hl". wp_load. by iApply "HΦ". - wp_recv (l) as "Hl". wp_load. by iApply "HΦ".
Qed. Qed.
...@@ -84,8 +84,8 @@ Qed. ...@@ -84,8 +84,8 @@ Qed.
Lemma prog3_spec : {{{ True }}} prog3 #() {{{ RET #42; True }}}. Lemma prog3_spec : {{{ True }}} prog3 #() {{{ RET #42; True }}}.
Proof. Proof.
iIntros (Φ) "_ HΦ". wp_lam. iIntros (Φ) "_ HΦ". wp_lam.
wp_apply (start_chan_proto_spec nroot prot3); iIntros (c) "Hc". wp_apply (start_chan_proto_spec prot3); iIntros (c) "Hc".
- wp_apply (new_chan_proto_spec nroot with "[//]"). - wp_apply (new_chan_proto_spec with "[//]").
iIntros (c2 c2') "Hcc2". iMod ("Hcc2" $! prot1) as "[Hc2 Hc2']". iIntros (c2 c2') "Hcc2". iMod ("Hcc2" $! prot1) as "[Hc2 Hc2']".
wp_send with "[$Hc2]". by wp_send with "[]". wp_send with "[$Hc2]". by wp_send with "[]".
- wp_recv (c2) as "Hc2". wp_recv as "_". by iApply "HΦ". - wp_recv (c2) as "Hc2". wp_recv as "_". by iApply "HΦ".
...@@ -94,7 +94,7 @@ Qed. ...@@ -94,7 +94,7 @@ Qed.
Lemma prog4_spec : {{{ True }}} prog4 #() {{{ RET #42; True }}}. Lemma prog4_spec : {{{ True }}} prog4 #() {{{ RET #42; True }}}.
Proof. Proof.
iIntros (Φ) "_ HΦ". wp_lam. 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_recv (x) as "_". by wp_send with "[]".
- wp_send with "[//]". wp_recv as "_". by iApply "HΦ". - wp_send with "[//]". wp_recv as "_". by iApply "HΦ".
Qed. Qed.
...@@ -102,7 +102,7 @@ Qed. ...@@ -102,7 +102,7 @@ Qed.
Lemma prog5_spec : {{{ True }}} prog5 #() {{{ RET #42; True }}}. Lemma prog5_spec : {{{ True }}} prog5 #() {{{ RET #42; True }}}.
Proof. Proof.
iIntros (Φ) "_ HΦ". wp_lam. 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. - wp_recv (P Ψ vf) as "#Hf". wp_send with "[]"; last done.
iIntros "!>" (Ψ') "HP HΨ'". wp_apply ("Hf" with "HP"); iIntros (x) "HΨ". iIntros "!>" (Ψ') "HP HΨ'". wp_apply ("Hf" with "HP"); iIntros (x) "HΨ".
wp_pures. by iApply "HΨ'". wp_pures. by iApply "HΨ'".
...@@ -117,12 +117,12 @@ Lemma prog_lock_spec `{!lockG Σ, contributionG Σ unitUR} : ...@@ -117,12 +117,12 @@ Lemma prog_lock_spec `{!lockG Σ, contributionG Σ unitUR} :
{{{ True }}} prog_lock #() {{{ RET #42; True }}}. {{{ True }}} prog_lock #() {{{ RET #42; True }}}.
Proof. Proof.
iIntros (Φ) "_ HΦ". wp_lam. 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 (contribution_init) as (γ) "Hs".
iMod (alloc_client with "Hs") as "[Hs Hcl1]". iMod (alloc_client with "Hs") as "[Hs Hcl1]".
iMod (alloc_client with "Hs") as "[Hs Hcl2]". iMod (alloc_client with "Hs") as "[Hs Hcl2]".
wp_apply (newlock_spec nroot ( n, server γ n ε 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. with "[Hc Hs]"); first by eauto with iFrame.
iIntros (lk γlk) "#Hlk". iIntros (lk γlk) "#Hlk".
iAssert ( (client γ ε - iAssert ( (client γ ε -
......
...@@ -26,7 +26,7 @@ Definition sort_service_br_del : val := ...@@ -26,7 +26,7 @@ Definition sort_service_br_del : val :=
else #(). else #().
Section sort_service_br_del. 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}. Context {A} (I : A val iProp Σ) (R : A A Prop) `{!RelDecision R, !Total R}.
Definition sort_protocol_br_aux (rec : iProto Σ) : iProto Σ := Definition sort_protocol_br_aux (rec : iProto Σ) : iProto Σ :=
...@@ -40,9 +40,9 @@ Section sort_service_br_del. ...@@ -40,9 +40,9 @@ Section sort_service_br_del.
Lemma sort_service_br_spec cmp c : Lemma sort_service_br_spec cmp c :
cmp_spec I R cmp - cmp_spec I R cmp -
{{{ c iProto_dual sort_protocol_br @ N }}} {{{ c iProto_dual sort_protocol_br }}}
sort_service_br cmp c sort_service_br cmp c
{{{ RET #(); c END @ N }}}. {{{ RET #(); c END }}}.
Proof. Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ). iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ).
wp_rec. wp_branch; wp_pures. wp_rec. wp_branch; wp_pures.
...@@ -52,7 +52,7 @@ Section sort_service_br_del. ...@@ -52,7 +52,7 @@ Section sort_service_br_del.
Qed. Qed.
Definition sort_protocol_del_aux (rec : iProto Σ) : iProto Σ := 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. Instance sort_protocol_del_aux_contractive : Contractive sort_protocol_del_aux.
Proof. solve_proto_contractive. Qed. Proof. solve_proto_contractive. Qed.
Definition sort_protocol_del : iProto Σ := fixpoint sort_protocol_del_aux. Definition sort_protocol_del : iProto Σ := fixpoint sort_protocol_del_aux.
...@@ -62,13 +62,13 @@ Section sort_service_br_del. ...@@ -62,13 +62,13 @@ Section sort_service_br_del.
Lemma sort_protocol_del_spec cmp c : Lemma sort_protocol_del_spec cmp c :
cmp_spec I R cmp - cmp_spec I R cmp -
{{{ c iProto_dual sort_protocol_del @ N }}} {{{ c iProto_dual sort_protocol_del }}}
sort_service_del cmp c sort_service_del cmp c
{{{ RET #(); c END @ N }}}. {{{ RET #(); c END }}}.
Proof. Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (Ψ). iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (Ψ).
wp_rec. wp_branch; wp_pures. 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'". iIntros (c') "Hc'".
{ wp_pures. wp_apply (sort_service_spec with "Hcmp Hc'"); auto. } { wp_pures. wp_apply (sort_service_spec with "Hcmp Hc'"); auto. }
wp_send with "[$Hc']". by wp_apply ("IH" with "Hc"). } wp_send with "[$Hc']". by wp_apply ("IH" with "Hc"). }
...@@ -76,7 +76,7 @@ Section sort_service_br_del. ...@@ -76,7 +76,7 @@ Section sort_service_br_del.
Qed. Qed.
Definition sort_protocol_br_del_aux (rec : iProto Σ) : iProto Σ := 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. Instance sort_protocol_br_del_aux_contractive : Contractive sort_protocol_br_del_aux.
Proof. solve_proto_contractive. Qed. Proof. solve_proto_contractive. Qed.
Definition sort_protocol_br_del : iProto Σ := fixpoint sort_protocol_br_del_aux. Definition sort_protocol_br_del : iProto Σ := fixpoint sort_protocol_br_del_aux.
...@@ -86,16 +86,16 @@ Section sort_service_br_del. ...@@ -86,16 +86,16 @@ Section sort_service_br_del.
Lemma sort_service_br_del_spec cmp c : Lemma sort_service_br_del_spec cmp c :
cmp_spec I R cmp - 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 sort_service_br_del cmp c
{{{ RET #(); c END @ N }}}. {{{ RET #(); c END }}}.
Proof. Proof.
iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ). iIntros "#Hcmp !>" (Ψ) "Hc HΨ". iLöb as "IH" forall (c Ψ).
wp_rec. wp_branch; wp_pures. wp_rec. wp_branch; wp_pures.
{ wp_apply (sort_service_spec with "Hcmp Hc"); iIntros "Hc". { wp_apply (sort_service_spec with "Hcmp Hc"); iIntros "Hc".
by wp_apply ("IH" with "Hc"). } by wp_apply ("IH" with "Hc"). }
wp_branch; wp_pures. 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_apply ("IH" with "Hc'"); auto. }
wp_send with "[$Hc']". wp_send with "[$Hc']".
by wp_apply ("IH" with "Hc"). } by wp_apply ("IH" with "Hc"). }
......
...@@ -56,7 +56,7 @@ Class mapG Σ A `{Countable A} := { ...@@ -56,7 +56,7 @@ Class mapG Σ A `{Countable A} := {
Section map. Section map.
Context `{Countable A} {B : Type}. 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). Context (IA : A val iProp Σ) (IB : B val iProp Σ) (map : A list B).
Local Open Scope nat_scope. Local Open Scope nat_scope.
Implicit Types n : nat. Implicit Types n : nat.
...@@ -82,11 +82,11 @@ Section map. ...@@ -82,11 +82,11 @@ Section map.
Proof. apply proto_unfold_eq, (fixpoint_unfold par_map_protocol_aux). Qed. Proof. apply proto_unfold_eq, (fixpoint_unfold par_map_protocol_aux). Qed.
Definition map_worker_lock_inv (γ : gname) (c : val) : iProp Σ := 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 : Lemma par_map_worker_spec γl γ vmap lk c :
map_spec vmap - 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 par_map_worker vmap lk c
{{{ RET #(); True }}}. {{{ RET #(); True }}}.
Proof. Proof.
...@@ -126,7 +126,7 @@ Section map. ...@@ -126,7 +126,7 @@ Section map.
Lemma par_map_workers_spec γl γ n vmap lk c : Lemma par_map_workers_spec γl γ n vmap lk c :
map_spec vmap - 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)) }}} [] replicate n (client γ (:gmultiset A)) }}}
par_map_workers #n vmap lk c par_map_workers #n vmap lk c
{{{ RET #(); True }}}. {{{ RET #(); True }}}.
...@@ -143,13 +143,13 @@ Section map. ...@@ -143,13 +143,13 @@ Section map.
Lemma par_map_service_spec n vmap c : Lemma par_map_service_spec n vmap c :
map_spec vmap - map_spec vmap -
{{{ c iProto_dual (par_map_protocol n ) @ N }}} {{{ c iProto_dual (par_map_protocol n ) }}}
par_map_service #n vmap c par_map_service #n vmap c
{{{ RET #(); True }}}. {{{ RET #(); True }}}.
Proof. Proof.
iIntros "#Hf !>"; iIntros (Φ) "Hc HΦ". wp_lam; wp_pures. iIntros "#Hf !>"; iIntros (Φ) "Hc HΦ". wp_lam; wp_pures.
iMod (contribution_init_pow (A:=gmultisetUR A) n) as (γ) "[Hs Hγs]". 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. } { iExists n, . iFrame. }
iIntros (lk γl) "#Hlk". iIntros (lk γl) "#Hlk".
wp_apply (par_map_workers_spec with "Hf [$Hlk $Hγs]"); auto. wp_apply (par_map_workers_spec with "Hf [$Hlk $Hγs]"); auto.
...@@ -157,7 +157,7 @@ Section map. ...@@ -157,7 +157,7 @@ Section map.
Lemma par_map_client_loop_spec n c l k xs X ys : Lemma par_map_client_loop_spec n c l k xs X ys :
(n = 0 X = xs = []) (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 par_map_client_loop #n c #l #k
{{{ ys', RET #(); {{{ ys', RET #();
ys' (xs ++ elements X) = map llist IA l [] llist IB k (ys' ++ ys) ys' (xs ++ elements X) = map llist IA l [] llist IB k (ys' ++ ys)
...@@ -198,7 +198,7 @@ Section map. ...@@ -198,7 +198,7 @@ Section map.
{{{ ys, RET #(); ys xs = map llist IB l ys }}}. {{{ ys, RET #(); ys xs = map llist IB l ys }}}.
Proof. Proof.
iIntros (?) "#Hmap !>"; iIntros (Φ) "Hl HΦ". wp_lam; wp_pures. 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_apply (par_map_service_spec with "Hmap Hc"); auto. }
wp_pures. wp_apply (lnil_spec with "[//]"); iIntros (k) "Hk". wp_pures. wp_apply (lnil_spec with "[//]"); iIntros (k) "Hk".
wp_apply (par_map_client_loop_spec with "[$Hl $Hk $Hc //]"); first lia. 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} := { ...@@ -95,7 +95,7 @@ Class map_reduceG Σ A B `{Countable A, Countable B} := {
Section mapper. Section mapper.
Context `{Countable A, Countable B} {C : Type}. 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 (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 (map : A list (Z * B)) (red : Z list B list C).
Context `{! j, Proper (() ==> ()) (red j)}. Context `{! j, Proper (() ==> ()) (red j)}.
...@@ -127,13 +127,13 @@ Section mapper. ...@@ -127,13 +127,13 @@ Section mapper.
(n = 0 X = xs = []) (n = 0 X = xs = [])
{{{ {{{
llist IA l xs llist IA l xs
cmap par_map_protocol IA IZB map n (X : gmultiset A) @ N cmap par_map_protocol IA IZB map n (X : gmultiset A)
csort sort_fg_head_protocol IZB RZB ys @ N csort sort_fg_head_protocol IZB RZB ys
}}} }}}
par_map_reduce_map #n cmap csort #l par_map_reduce_map #n cmap csort #l
{{{ ys', RET #(); {{{ ys', RET #();
ys' (xs ++ elements X) = map 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. Proof.
iIntros (Hn Φ) "(Hl & Hcmap & Hcsort) HΦ". iIntros (Hn Φ) "(Hl & Hcmap & Hcsort) HΦ".
...@@ -172,7 +172,7 @@ Section mapper. ...@@ -172,7 +172,7 @@ Section mapper.
i iys_sorted.*1 i iys_sorted.*1
{{{ {{{
llist (IB i) l (reverse ys) 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 par_map_reduce_collect csort #i #l
{{{ ys' miy, RET accv miy; {{{ ys' miy, RET accv miy;
...@@ -181,7 +181,7 @@ Section mapper. ...@@ -181,7 +181,7 @@ Section mapper.
(iys_sorted ++ ((i,) <$> ys ++ ys') iys) miy (iys_sorted ++ ((i,) <$> ys ++ ys') iys) miy
llist (IB i) l (reverse (ys ++ ys')) llist (IB i) l (reverse (ys ++ ys'))
csort from_option (λ _, sort_fg_tail_protocol IZB RZB iys