cancelable_invariants.v 3.8 KB
Newer Older
Robbert Krebbers's avatar
Robbert Krebbers committed
1
From iris.base_logic.lib Require Export invariants.
2
From iris.bi.lib Require Import fractional.
Robbert Krebbers's avatar
Robbert Krebbers committed
3
From iris.algebra Require Export frac.
4
From iris.proofmode Require Import tactics.
5
Set Default Proof Using "Type".
Robbert Krebbers's avatar
Robbert Krebbers committed
6 7 8
Import uPred.

Class cinvG Σ := cinv_inG :> inG Σ fracR.
9 10 11 12
Definition cinvΣ : gFunctors := #[GFunctor fracR].

Instance subG_cinvΣ {Σ} : subG cinvΣ Σ  cinvG Σ.
Proof. solve_inG. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
13 14

Section defs.
15
  Context `{invG Σ, cinvG Σ}.
Robbert Krebbers's avatar
Robbert Krebbers committed
16 17 18 19

  Definition cinv_own (γ : gname) (p : frac) : iProp Σ := own γ p.

  Definition cinv (N : namespace) (γ : gname) (P : iProp Σ) : iProp Σ :=
20
    ( P',   (P  P')  inv N (P'  cinv_own γ 1%Qp))%I.
Robbert Krebbers's avatar
Robbert Krebbers committed
21 22
End defs.

23
Instance: Params (@cinv) 5.
Robbert Krebbers's avatar
Robbert Krebbers committed
24 25

Section proofs.
26
  Context `{invG Σ, cinvG Σ}.
Robbert Krebbers's avatar
Robbert Krebbers committed
27

28
  Global Instance cinv_own_timeless γ p : Timeless (cinv_own γ p).
Robbert Krebbers's avatar
Robbert Krebbers committed
29 30
  Proof. rewrite /cinv_own; apply _. Qed.

31 32
  Global Instance cinv_contractive N γ : Contractive (cinv N γ).
  Proof. solve_contractive. Qed.
33
  Global Instance cinv_ne N γ : NonExpansive (cinv N γ).
34
  Proof. exact: contractive_ne. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
35
  Global Instance cinv_proper N γ : Proper (() ==> ()) (cinv N γ).
36
  Proof. exact: ne_proper. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
37

38
  Global Instance cinv_persistent N γ P : Persistent (cinv N γ P).
Robbert Krebbers's avatar
Robbert Krebbers committed
39 40
  Proof. rewrite /cinv; apply _. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
41
  Global Instance cinv_own_fractional γ : Fractional (cinv_own γ).
42
  Proof. intros ??. by rewrite /cinv_own -own_op. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
43
  Global Instance cinv_own_as_fractional γ q :
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
44
    AsFractional (cinv_own γ q) (cinv_own γ) q.
45
  Proof. split. done. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
46

47 48
  Lemma cinv_own_valid γ q1 q2 : cinv_own γ q1 - cinv_own γ q2 -  (q1 + q2)%Qp.
  Proof. apply (own_valid_2 γ q1 q2). Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
49

50 51 52 53 54
  Lemma cinv_own_1_l γ q : cinv_own γ 1 - cinv_own γ q - False.
  Proof.
    iIntros "H1 H2".
    iDestruct (cinv_own_valid with "H1 H2") as %[]%(exclusive_l 1%Qp).
  Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
55

56 57 58 59
  Lemma cinv_iff N γ P P' :
      (P  P') - cinv N γ P - cinv N γ P'.
  Proof.
    iIntros "#HP' Hinv". iDestruct "Hinv" as (P'') "[#HP'' Hinv]".
60
    iExists _. iFrame "Hinv". iAlways. iNext. iSplit.
61 62 63 64
    - iIntros "?". iApply "HP''". iApply "HP'". done.
    - iIntros "?". iApply "HP'". iApply "HP''". done.
  Qed.

65
  Lemma cinv_alloc E N P :  P ={E}=  γ, cinv N γ P  cinv_own γ 1.
Robbert Krebbers's avatar
Robbert Krebbers committed
66
  Proof.
67
    iIntros "HP".
68
    iMod (own_alloc 1%Qp) as (γ) "H1"; first done.
69 70
    iMod (inv_alloc N _ (P  own γ 1%Qp)%I with "[HP]"); first by eauto.
    iExists _. iFrame. iExists _. iFrame. iIntros "!> !# !>". iSplit; by iIntros "?".
Robbert Krebbers's avatar
Robbert Krebbers committed
71 72
  Qed.

73
  Lemma cinv_cancel E N γ P : N  E  cinv N γ P - cinv_own γ 1 ={E}=  P.
Robbert Krebbers's avatar
Robbert Krebbers committed
74
  Proof.
75
    iIntros (?) "#Hinv Hγ". iDestruct "Hinv" as (P') "[#HP' Hinv]".
Ralf Jung's avatar
Ralf Jung committed
76 77
    iInv N as "[HP|>Hγ']".
    - iModIntro. iFrame "Hγ". iModIntro. iApply "HP'". done.
78
    - iDestruct (cinv_own_1_l with "Hγ Hγ'") as %[].
Robbert Krebbers's avatar
Robbert Krebbers committed
79 80 81
  Qed.

  Lemma cinv_open E N γ p P :
82
    N  E 
83
    cinv N γ P - cinv_own γ p ={E,E∖↑N}=  P  cinv_own γ p  ( P ={E∖↑N,E}= True).
Robbert Krebbers's avatar
Robbert Krebbers committed
84
  Proof.
85
    iIntros (?) "#Hinv Hγ". iDestruct "Hinv" as (P') "[#HP' Hinv]".
Ralf Jung's avatar
Ralf Jung committed
86
    iMod (inv_open with "Hinv") as "[[HP | >Hγ'] Hclose]"; first done.
87
    - iIntros "!> {$Hγ}". iSplitL "HP".
Ralf Jung's avatar
Ralf Jung committed
88
      + iApply "HP'". done.
89
      + iIntros "HP". iApply "Hclose". iLeft. iNext. by iApply "HP'".
90
    - iDestruct (cinv_own_1_l with "Hγ' Hγ") as %[].
Robbert Krebbers's avatar
Robbert Krebbers committed
91
  Qed.
Joseph Tassarotti's avatar
Joseph Tassarotti committed
92 93

  Global Instance into_inv_cinv N γ P : IntoInv (cinv N γ P) N.
Ralf Jung's avatar
Ralf Jung committed
94 95 96 97

  Global Instance elim_inv_cinv E N γ P p Q Q' :
    InvOpener E (E∖↑N) ( P  cinv_own γ p) ( P) None Q Q' 
    ElimInv (N  E) (cinv N γ P) (cinv_own γ p) ( P  cinv_own γ p) Q Q'.
Joseph Tassarotti's avatar
Joseph Tassarotti committed
98
  Proof.
Ralf Jung's avatar
Ralf Jung committed
99 100 101
    rewrite /ElimInv /InvOpener. iIntros (Helim ?) "(#Hinv & Hown & Hcont)".
    iApply (Helim with "Hcont"). clear Helim. rewrite -assoc.
    iApply (cinv_open with "Hinv"); done.
Joseph Tassarotti's avatar
Joseph Tassarotti committed
102
  Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
103
End proofs.
104 105

Typeclasses Opaque cinv_own cinv.