Commit 0247cec5 authored by Ralf Jung's avatar Ralf Jung

concurrent stacks: also unify concurrent bag (per-element) specs for stacks 1 and 2

parent 68473b43
Pipeline #10766 passed with stage
in 9 minutes and 5 seconds
...@@ -5,6 +5,9 @@ From iris.program_logic Require Export weakestpre hoare. ...@@ -5,6 +5,9 @@ From iris.program_logic Require Export weakestpre hoare.
From iris.heap_lang Require Export lang. From iris.heap_lang Require Export lang.
From iris.algebra Require Import agree list. From iris.algebra Require Import agree list.
From iris.heap_lang Require Import assert proofmode notation. From iris.heap_lang Require Import assert proofmode notation.
From iris_examples.concurrent_stacks Require Import spec.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(** Stack 1: No helping, bag spec. *) (** Stack 1: No helping, bag spec. *)
...@@ -14,10 +17,10 @@ Definition mk_stack : val := ...@@ -14,10 +17,10 @@ Definition mk_stack : val :=
let: "r" := ref NONEV in let: "r" := ref NONEV in
(rec: "pop" "n" := (rec: "pop" "n" :=
match: !"r" with match: !"r" with
NONE => #-1 NONE => NONE
| SOME "hd" => | SOME "hd" =>
if: CAS "r" (SOME "hd") (Snd !"hd") if: CAS "r" (SOME "hd") (Snd !"hd")
then Fst !"hd" then SOME (Fst !"hd")
else "pop" "n" else "pop" "n"
end, end,
rec: "push" "n" := rec: "push" "n" :=
...@@ -81,8 +84,8 @@ Section stacks. ...@@ -81,8 +84,8 @@ Section stacks.
(* Per-element invariant (i.e., bag spec). *) (* Per-element invariant (i.e., bag spec). *)
Theorem stack_works P Φ : Theorem stack_works P Φ :
( (f f : val), ( (f f : val),
( (v : val), WP f #() {{ v, P v v #-1 }}) ( WP f #() {{ v, ( v', v SOMEV v' P v') v NONEV }})
- ( (v : val), (P v - WP f v {{ v, True }})) - ( (v : val), (P v - WP f v {{ v, True }}))
- Φ (f, f)%V)%I - Φ (f, f)%V)%I
- WP mk_stack #() {{ Φ }}. - WP mk_stack #() {{ Φ }}.
...@@ -98,7 +101,7 @@ Section stacks. ...@@ -98,7 +101,7 @@ Section stacks.
wp_let. wp_let.
iModIntro. iModIntro.
iApply "HΦ". iApply "HΦ".
- iIntros (v) "!#". - iIntros "!#".
iLöb as "IH". iLöb as "IH".
wp_rec. wp_rec.
wp_bind (! #l)%E. wp_bind (! #l)%E.
...@@ -129,7 +132,7 @@ Section stacks. ...@@ -129,7 +132,7 @@ Section stacks.
wp_if. wp_if.
wp_load. wp_load.
wp_proj. wp_proj.
iLeft; auto. eauto.
* simpl in Hne. wp_cas_fail. * simpl in Hne. wp_cas_fail.
iMod ("Hclose" with "[Hl'' Hstack]"). iMod ("Hclose" with "[Hl'' Hstack]").
{ iExists v''; iFrame; auto. } { iExists v''; iFrame; auto. }
...@@ -172,3 +175,10 @@ Section stacks. ...@@ -172,3 +175,10 @@ Section stacks.
done. done.
Qed. Qed.
End stacks. End stacks.
Program Definition is_concurrent_bag `{!heapG Σ} : concurrent_bag Σ :=
{| spec.mk_bag := mk_stack |}.
Next Obligation.
iIntros (??? P Φ) "_ HΦ". iApply stack_works.
iNext. iIntros (f f) "Hpop Hpush". iApply "HΦ". iFrame.
Qed.
...@@ -3,6 +3,9 @@ stricter CAS requirements yet. *) ...@@ -3,6 +3,9 @@ stricter CAS requirements yet. *)
From iris.program_logic Require Export weakestpre hoare. From iris.program_logic Require Export weakestpre hoare.
From iris.heap_lang Require Export lang proofmode notation. From iris.heap_lang Require Export lang proofmode notation.
From iris.algebra Require Import excl. From iris.algebra Require Import excl.
From iris_examples.concurrent_stacks Require Import spec.
Set Default Proof Using "Type". Set Default Proof Using "Type".
(** Stack 2: With helping, bag spec. *) (** Stack 2: With helping, bag spec. *)
...@@ -268,7 +271,7 @@ Section stack_works. ...@@ -268,7 +271,7 @@ Section stack_works.
(* Per-element invariant (i.e., bag spec). *) (* Per-element invariant (i.e., bag spec). *)
Theorem stack_works {channelG0 : channelG Σ} P Φ : Theorem stack_works {channelG0 : channelG Σ} P Φ :
( (f f : val), ( (f f : val),
( WP f #() {{ v, ( (v' : val), v SOMEV v' P v') v NONEV }}) ( WP f #() {{ v, ( (v' : val), v SOMEV v' P v') v NONEV }})
- ( (v : val), (P v - WP f v {{ v, True }})) - ( (v : val), (P v - WP f v {{ v, True }}))
- Φ (f, f)%V)%I - Φ (f, f)%V)%I
...@@ -405,3 +408,10 @@ Section stack_works. ...@@ -405,3 +408,10 @@ Section stack_works.
done. done.
Qed. Qed.
End stack_works. End stack_works.
Program Definition is_concurrent_bag `{!heapG Σ, !channelG Σ} : concurrent_bag Σ :=
{| spec.mk_bag := mk_stack |}.
Next Obligation.
iIntros (???? P Φ) "_ HΦ". iApply stack_works.
iNext. iIntros (f f) "Hpop Hpush". iApply "HΦ". iFrame.
Qed.
From iris.program_logic Require Export weakestpre hoare. From iris.program_logic Require Export weakestpre hoare.
From iris.heap_lang Require Export lang proofmode notation. From iris.heap_lang Require Export lang proofmode notation.
From iris.algebra Require Import excl. From iris.algebra Require Import excl.
Set Default Proof Using "Type".
From iris_examples.concurrent_stacks Require Import spec. From iris_examples.concurrent_stacks Require Import spec.
Set Default Proof Using "Type".
(** Stack 3: No helping, view-shift spec. *) (** Stack 3: No helping, view-shift spec. *)
Definition mk_stack : val := Definition mk_stack : val :=
...@@ -213,11 +214,11 @@ Section stack_works. ...@@ -213,11 +214,11 @@ Section stack_works.
wp_if. wp_if.
iApply ("IH" with "Hpush"). iApply ("IH" with "Hpush").
Qed. Qed.
End stack_works.
Program Definition is_concurrent_stack : concurrent_stack Σ := Program Definition is_concurrent_stack `{!heapG Σ} : concurrent_stack Σ :=
{| spec.mk_stack := mk_stack |}. {| spec.mk_stack := mk_stack |}.
Next Obligation. Next Obligation.
iIntros (????? Φ) "HP HΦ". iApply (stack_works with "[HΦ] HP"). iIntros (??????? Φ) "HP HΦ". iApply (stack_works with "[HΦ] HP").
iNext. iIntros (f f) "Hpop Hpush". iApply "HΦ". iFrame. iNext. iIntros (f f) "Hpop Hpush". iApply "HΦ". iFrame.
Qed. Qed.
End stack_works.
...@@ -6,6 +6,8 @@ From iris.algebra Require Import excl. ...@@ -6,6 +6,8 @@ From iris.algebra Require Import excl.
From iris_examples.concurrent_stacks Require Import spec. From iris_examples.concurrent_stacks Require Import spec.
Set Default Proof Using "Type".
(** Stack 3: Helping, view-shift spec. *) (** Stack 3: Helping, view-shift spec. *)
Definition mk_offer : val := Definition mk_offer : val :=
...@@ -620,11 +622,11 @@ Section stack_works. ...@@ -620,11 +622,11 @@ Section stack_works.
wp_cas_fail. wp_cas_fail.
by iDestruct (own_valid_2 with "Hγ Hγ'") as %?. by iDestruct (own_valid_2 with "Hγ Hγ'") as %?.
Qed. Qed.
End stack_works.
Program Definition is_concurrent_stack `{!channelG Σ} : concurrent_stack Σ := Program Definition is_concurrent_stack `{!heapG Σ, !channelG Σ} : concurrent_stack Σ :=
{| spec.mk_stack := mk_stack |}. {| spec.mk_stack := mk_stack |}.
Next Obligation. Next Obligation.
iIntros (?????? Φ) "HP HΦ". iApply (stack_works with "[HΦ] HP"). iIntros (???????? Φ) "HP HΦ". iApply (stack_works with "[HΦ] HP").
iNext. iIntros (f f) "#[Hpop Hpush]". iApply "HΦ". iFrame "#". iNext. iIntros (f f) "#[Hpop Hpush]". iApply "HΦ". iFrame "#".
Qed. Qed.
End stack_works.
...@@ -2,6 +2,19 @@ From stdpp Require Import namespaces. ...@@ -2,6 +2,19 @@ From stdpp Require Import namespaces.
From iris.program_logic Require Export weakestpre. From iris.program_logic Require Export weakestpre.
From iris.heap_lang Require Export proofmode notation. From iris.heap_lang Require Export proofmode notation.
(** General (HoCAP-style) spec for a concurrent bag ("per-elemt spec") *)
Record concurrent_bag {Σ} `{!heapG Σ} := ConcurrentBag {
mk_bag : val;
mk_bag_spec (N : namespace) (P : val iProp Σ) :
{{{ True }}}
mk_bag #()
{{{ (f f : val), RET (f, f);
( WP f #() {{ v, ( (v' : val), v SOMEV v' P v') v NONEV }})
( (v : val), (P v - WP f v {{ v, True }}))
}}}
}.
Arguments concurrent_bag _ {_}.
(** General (HoCAP-style) spec for a concurrent stack *) (** General (HoCAP-style) spec for a concurrent stack *)
Record concurrent_stack {Σ} `{!heapG Σ} := ConcurrentStack { Record concurrent_stack {Σ} `{!heapG Σ} := ConcurrentStack {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment