Commit bb7c8731 authored by Dan Frumin's avatar Dan Frumin

Full version of the "callback with lock" example

parent 52f32aaa
Pipeline #8690 passed with stage
in 6 minutes and 28 seconds
...@@ -186,10 +186,10 @@ Section refinement. ...@@ -186,10 +186,10 @@ Section refinement.
Qed. Qed.
(* Also known as "callback with lock" *) (* Also known as "callback with lock" *)
Definition i3 x x' b b' : iProp Σ := Definition i3 (x x' b b' : loc) : iProp Σ :=
(( (n : nat), x ↦ᵢ #n x' ↦ₛ #n ( (n:nat), x ↦ᵢ{1/2} #n x' ↦ₛ{1/2} #n
b ↦ᵢ #true b' ↦ₛ #true) ((b ↦ᵢ #true b' ↦ₛ #true x ↦ᵢ{1/2} #n x' ↦ₛ{1/2} #n)
(b ↦ᵢ #false b' ↦ₛ #false))%I. (b ↦ᵢ #false b' ↦ₛ #false)))%I.
Definition i3n := nroot .@ "i3". Definition i3n := nroot .@ "i3".
Lemma refinement3 Γ : Lemma refinement3 Γ :
Γ Γ
...@@ -197,15 +197,17 @@ Section refinement. ...@@ -197,15 +197,17 @@ Section refinement.
let: "x" := ref #0 in let: "x" := ref #0 in
(λ: "f", if: CAS "b" #true #false (λ: "f", if: CAS "b" #true #false
then "f" #();; "x" <- !"x" + #1 ;; "b" <- #true then "f" #();; "x" <- !"x" + #1 ;; "b" <- #true
else #()) else #(),
λ: <>, !"x")
log log
(let: "b" := ref #true in (let: "b" := ref #true in
let: "x" := ref #0 in let: "x" := ref #0 in
(λ: "f", if: CAS "b" #true #false (λ: "f", if: CAS "b" #true #false
then let: "n" := !"x" in then let: "n" := !"x" in
"f" #();; "x" <- "n" + #1 ;; "b" <- #true "f" #();; "x" <- "n" + #1 ;; "b" <- #true
else #())) else #(),
: TArrow (TArrow TUnit TUnit) TUnit. λ: <>, !"x"))
: ((Unit Unit) Unit) × (Unit TNat).
Proof. Proof.
iIntros (Δ). iIntros (Δ).
rel_alloc_l as b "Hb". rel_alloc_l as b "Hb".
...@@ -217,51 +219,77 @@ Section refinement. ...@@ -217,51 +219,77 @@ Section refinement.
rel_alloc_r as x' "Hx'". rel_alloc_r as x' "Hx'".
rel_let_r. rel_let_r.
iMod (inv_alloc i3n _ (i3 x x' b b') with "[-]") as "#Hinv". iMod (inv_alloc i3n _ (i3 x x' b b') with "[-]") as "#Hinv".
{ iNext. unfold i3. { iNext. unfold i3. iExists 0.
iLeft. iExists 0. iFrame. } iDestruct "Hx" as "[$ Hx]".
iApply bin_log_related_arrow; eauto. iDestruct "Hx'" as "[$ Hx']".
iLeft. iFrame. }
iApply bin_log_related_pair.
- iApply bin_log_related_arrow; eauto.
iAlways. iIntros (f f') "Hf". iAlways. iIntros (f f') "Hf".
rel_let_l. rel_let_l.
rel_let_r. rel_let_r.
rel_cas_l_atomic. rel_cas_l_atomic.
iInv i3n as ">Hbb" "Hcl". iInv i3n as (n) "(Hx & Hx' & >Hbb)" "Hcl".
rewrite {2}/i3. iDestruct "Hbb" as "[(Hb & Hb' & Hx1 & Hx'1) | (Hb & Hb')]"; last first.
iDestruct "Hbb" as "[Hbb | (Hb & Hb')]"; last first.
{ iModIntro; iExists _; iFrame. { iModIntro; iExists _; iFrame.
iSplitL; last by iIntros (?); congruence. iSplitL; last by iIntros (?); congruence.
iIntros (?); iNext; iIntros "Hb". iIntros (?); iNext; iIntros "Hb".
rel_cas_fail_r; rel_if_r; rel_if_l. rel_cas_fail_r; rel_if_r; rel_if_l.
iMod ("Hcl" with "[-]"). iMod ("Hcl" with "[-]").
{ iNext. iRight. iFrame. } { iNext. iExists n. iFrame. iRight. iFrame. }
rel_vals; eauto. rel_vals; eauto.
} }
{ iDestruct "Hbb" as (n) "(Hx & Hx' & Hb & Hb')". { iModIntro. iExists _; iFrame.
iModIntro. iExists _; iFrame.
iSplitR; first by iIntros (?); congruence. iSplitR; first by iIntros (?); congruence.
iIntros (?); iNext; iIntros "Hb". iIntros (?); iNext; iIntros "Hb".
rel_cas_suc_r; rel_if_r; rel_if_l. rel_cas_suc_r; rel_if_r; rel_if_l.
rel_load_r. rel_let_r. rel_load_r. rel_let_r.
iMod ("Hcl" with "[Hb Hb']") as "_". iMod ("Hcl" with "[Hb Hb' Hx Hx']") as "_".
{ iNext. iRight. iFrame. } { iNext. iExists _; iFrame. iRight. iFrame. }
iApply (bin_log_related_seq' with "[Hf]"); auto. iApply (bin_log_related_seq' with "[Hf]"); auto.
{ iApply (bin_log_related_app with "Hf"). { iApply (bin_log_related_app with "Hf").
iApply bin_log_related_unit. } iApply bin_log_related_unit. }
rel_load_l. rel_load_l.
rel_op_l. rel_op_r. rel_op_l. rel_op_r.
rel_store_l. rel_store_r.
rel_seq_l. rel_seq_r.
rel_store_l_atomic. rel_store_l_atomic.
iInv i3n as ">Hi3" "Hcl". iInv i3n as (n') "(>Hx & Hx' & >Hbb)" "Hcl".
iDestruct "Hi3" as "[Hi3 | [Hb Hb']]". iDestruct (mapsto_agree with "Hx Hx1") as %->.
{ iDestruct "Hi3" as (m) "(Hx1 & Hx1' & Hb & Hb')". iCombine "Hx Hx1" as "Hx".
iModIntro. iExists _; iFrame; iNext. iIntros "Hb". iModIntro. iExists _; iFrame. iNext.
iDestruct (mapsto_valid_2 x with "Hx Hx1") as %Hfoo. iIntros "Hx".
cbv in Hfoo. by exfalso. } iCombine "Hx' Hx'1" as "Hx'".
iModIntro; iExists _; iFrame; iNext; iIntros "Hb". rel_store_r.
iDestruct "Hx" as "[Hx Hx1]".
iDestruct "Hx'" as "[Hx' Hx'1]".
iDestruct "Hbb" as "[(Hb & Hb' & Hx2 & Hx'2) | Hbb]".
{ iCombine "Hx Hx1" as "Hx".
iDestruct (mapsto_valid_2 with "Hx Hx2") as %Hfoo. exfalso.
compute in Hfoo. eauto. }
iMod ("Hcl" with "[Hx Hx' Hbb]") as "_".
{ iNext. iExists _. iFrame. }
rel_seq_l. rel_seq_r.
rel_store_l_atomic. clear n'.
iInv i3n as (n') "(>Hx & Hx' & >Hbb)" "Hcl".
iDestruct (mapsto_agree with "Hx Hx1") as %->.
iDestruct "Hbb" as "[(Hb & Hb' & Hx2 & Hx'2) | (Hb & Hb')]".
{ iCombine "Hx Hx1" as "Hx".
iDestruct (mapsto_valid_2 with "Hx Hx2") as %Hfoo. exfalso.
compute in Hfoo. eauto. }
iModIntro; iExists _; iFrame; iNext. iIntros "Hb".
rel_store_r. rel_store_r.
iMod ("Hcl" with "[-]") as "_". iMod ("Hcl" with "[-]") as "_".
{ iNext. iLeft. iExists _. iFrame. } { iNext. iExists _. iFrame. iLeft. iFrame. }
rel_vals; eauto. } rel_vals; eauto. }
- iApply bin_log_related_arrow; eauto.
iAlways. iIntros (u u') "_".
rel_let_l. rel_let_r.
rel_load_l_atomic.
iInv i3n as (n) "(>Hx & Hx' & >Hbb)" "Hcl".
iModIntro. iExists _; iFrame; iNext. iIntros "Hx".
rel_load_r.
iMod ("Hcl" with "[-]") as "_".
{ iNext. iExists _. iFrame. }
iApply bin_log_related_nat.
Qed. Qed.
(* /Sort of/ a well-bracketedness example. (* /Sort of/ a well-bracketedness example.
......
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