Skip to content
Snippets Groups Projects
Commit 64751fcd authored by Ralf Jung's avatar Ralf Jung
Browse files

prove lemma for non-deterministic CAS on locations

parent 9e5b4d6a
No related branches found
No related tags found
No related merge requests found
...@@ -78,7 +78,7 @@ Proof. ...@@ -78,7 +78,7 @@ Proof.
iNext. iIntros (?? Heval). inversion_clear Heval. done. iNext. iIntros (?? Heval). inversion_clear Heval. done.
Qed. Qed.
(* TODO: Add lemmas for remaining binary operators. *) (* TODO: Add lemmas for equality test. *)
Lemma wp_if E (b : bool) e1 e2 Φ : Lemma wp_if E (b : bool) e1 e2 Φ :
(if b then WP e1 @ E {{ Φ }} else WP e2 @ E {{ Φ }})%I -∗ (if b then WP e1 @ E {{ Φ }} else WP e2 @ E {{ Φ }})%I -∗
......
...@@ -608,5 +608,28 @@ Section heap. ...@@ -608,5 +608,28 @@ Section heap.
iNext. iExists _, hF. iFrame. eauto using heap_freeable_rel_stable. iNext. iExists _, hF. iFrame. eauto using heap_freeable_rel_stable.
Qed. Qed.
(* TODO: Add a lemma for non-deterministic CAS on locations. *) Lemma wp_cas_loc_nondet E l l1 e2 l2 ll :
heapN E to_val e2 = Some $ LitV $ LitLoc l2
{{{ heap_ctx l (LitV $ LitLoc ll) }}}
CAS (Lit $ LitLoc l) (Lit $ LitLoc l1) e2 @ E
{{{ b, RET LitV $ lit_of_bool b;
if b is true then l LitV (LitLoc l2)
else l1 ll l LitV (LitLoc ll) }}}.
Proof.
iIntros (? <-%of_to_val?) "[#Hinv >Hv] HΦ".
rewrite /heap_ctx /heap_inv heap_mapsto_eq /heap_mapsto_def.
iInv heapN as (σ hF) ">(Hσ & Hvalσ & HhF & %)" "Hclose".
iDestruct (heap_mapsto_lookup_1 with "Hvalσ Hv") as %?.
iApply (wp_cas_pst with "[$Hσ]"); eauto.
{ destruct (decide (l1 = ll)) as [->|Hne].
- left. by constructor.
- right. by constructor. }
iNext. iIntros ([|]).
- iIntros "[_ Hσ]". iMod (heap_write_vs with "[$Hvalσ $Hv]") as "[Hvalσ Hv]"; first done.
iMod ("Hclose" with "[-Hv HΦ]"); last by iApply "HΦ"; iFrame.
iNext. iExists _, hF. iFrame. eauto using heap_freeable_rel_stable.
- iIntros "[Hneq Hσ]". iDestruct "Hneq" as %Hneq. inversion_clear Hneq.
iMod ("Hclose" with "[-Hv HΦ]"); last by iApply ("HΦ" $! false); iFrame.
iNext. iExists _, hF. iFrame. eauto using heap_freeable_rel_stable.
Qed.
End heap. End heap.
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