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

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

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

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

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

  Definition cinv (N : namespace) (γ : gname) (P : iProp Σ) : iProp Σ :=
    inv N (P  cinv_own γ 1%Qp)%I.
End defs.

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

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

  Global Instance cinv_own_timeless γ p : TimelessP (cinv_own γ p).
  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 39 40

  Global Instance cinv_persistent N γ P : PersistentP (cinv N γ P).
  Proof. rewrite /cinv; apply _. Qed.

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
41 42 43 44
  Global Instance cinv_own_fractionnal γ : Fractional (cinv_own γ).
  Proof. intros ??. by rewrite -own_op. Qed.
  Global Instance cinv_own_as_fractionnal γ q :
    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
  Lemma cinv_alloc E N P :  P ={E}=  γ, cinv N γ P  cinv_own γ 1.
Robbert Krebbers's avatar
Robbert Krebbers committed
57 58
  Proof.
    rewrite /cinv /cinv_own. iIntros "HP".
59 60
    iMod (own_alloc 1%Qp) as (γ) "H1"; first done.
    iMod (inv_alloc N _ (P  own γ 1%Qp)%I with "[HP]"); eauto.
Robbert Krebbers's avatar
Robbert Krebbers committed
61 62
  Qed.

63
  Lemma cinv_cancel E N γ P : N  E  cinv N γ P - cinv_own γ 1 ={E}=  P.
Robbert Krebbers's avatar
Robbert Krebbers committed
64 65 66
  Proof.
    rewrite /cinv. iIntros (?) "#Hinv Hγ".
    iInv N as "[$|>Hγ']" "Hclose"; first iApply "Hclose"; eauto.
67
    iDestruct (cinv_own_1_l with "Hγ Hγ'") as %[].
Robbert Krebbers's avatar
Robbert Krebbers committed
68 69 70
  Qed.

  Lemma cinv_open E N γ p P :
71
    N  E 
72
    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
73 74
  Proof.
    rewrite /cinv. iIntros (?) "#Hinv Hγ".
75
    iInv N as "[$ | >Hγ']" "Hclose".
76
    - iIntros "!> {$Hγ} HP". iApply "Hclose"; eauto.
77
    - iDestruct (cinv_own_1_l with "Hγ' Hγ") as %[].
Robbert Krebbers's avatar
Robbert Krebbers committed
78 79
  Qed.
End proofs.