na_invariants.v 3.43 KB
Newer Older
1
From iris.base_logic.lib Require Export invariants.
2
From iris.algebra Require Export gmap gset coPset.
3
From iris.proofmode Require Import tactics.
4 5
Import uPred.

6 7
(* Non-atomic ("thread-local") invariants. *)

Ralf Jung's avatar
Ralf Jung committed
8
Definition na_inv_pool_name := gname.
9

10
Class na_invG Σ :=
11
  tl_inG :> inG Σ (prodR coPset_disjR (gset_disjR positive)).
12 13

Section defs.
14
  Context `{invG Σ, na_invG Σ}.
15

Ralf Jung's avatar
Ralf Jung committed
16 17
  Definition na_own (p : na_inv_pool_name) (E : coPset) : iProp Σ :=
    own p (CoPset E, ).
18

Ralf Jung's avatar
Ralf Jung committed
19
  Definition na_inv (p : na_inv_pool_name) (N : namespace) (P : iProp Σ) : iProp Σ :=
20
    ( i, i  N 
Ralf Jung's avatar
Ralf Jung committed
21
          inv N (P  own p (, GSet {[i]})  na_own p {[i]}))%I.
22 23
End defs.

24 25
Instance: Params (@na_inv) 3.
Typeclasses Opaque na_own na_inv.
26 27

Section proofs.
28
  Context `{invG Σ, na_invG Σ}.
29

Ralf Jung's avatar
Ralf Jung committed
30
  Global Instance na_own_timeless p E : TimelessP (na_own p E).
31
  Proof. rewrite /na_own; apply _. Qed.
32

Ralf Jung's avatar
Ralf Jung committed
33
  Global Instance na_inv_ne p N n : Proper (dist n ==> dist n) (na_inv p N).
34
  Proof. rewrite /na_inv. solve_proper. Qed.
Ralf Jung's avatar
Ralf Jung committed
35
  Global Instance na_inv_proper p N : Proper (() ==> ()) (na_inv p N).
36 37
  Proof. apply (ne_proper _). Qed.

Ralf Jung's avatar
Ralf Jung committed
38
  Global Instance na_inv_persistent p N P : PersistentP (na_inv p N P).
39
  Proof. rewrite /na_inv; apply _. Qed.
40

Ralf Jung's avatar
Ralf Jung committed
41
  Lemma na_alloc : (|==>  p, na_own p )%I.
42
  Proof. by apply own_alloc. Qed.
43

Ralf Jung's avatar
Ralf Jung committed
44
  Lemma na_own_disjoint p E1 E2 : na_own p E1 - na_own p E2 - E1  E2.
45
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
46
    apply wand_intro_r.
47
    rewrite /na_own -own_op own_valid -coPset_disj_valid_op. by iIntros ([? _]).
48 49
  Qed.

Ralf Jung's avatar
Ralf Jung committed
50 51
  Lemma na_own_union p E1 E2 :
    E1  E2  na_own p (E1  E2)  na_own p E1  na_own p E2.
52
  Proof.
53
    intros ?. by rewrite /na_own -own_op pair_op left_id coPset_disj_union.
54 55
  Qed.

Ralf Jung's avatar
Ralf Jung committed
56
  Lemma na_inv_alloc p E N P :  P ={E}= na_inv p N P.
57 58
  Proof.
    iIntros "HP".
Ralf Jung's avatar
Ralf Jung committed
59
    iMod (own_empty (prodUR coPset_disjUR (gset_disjUR positive)) p) as "Hempty".
60
    iMod (own_updateP with "Hempty") as ([m1 m2]) "[Hm Hown]".
61
    { apply prod_updateP'. apply cmra_updateP_id, (reflexivity (R:=eq)).
62 63
      apply (gset_disj_alloc_empty_updateP_strong' (λ i, i  N)).
      intros Ef. exists (coPpick ( N  coPset.of_gset Ef)).
64 65 66 67
      rewrite -coPset.elem_of_of_gset comm -elem_of_difference.
      apply coPpick_elem_of=> Hfin.
      eapply nclose_infinite, (difference_finite_inv _ _), Hfin.
      apply of_gset_finite. }
68
    simpl. iDestruct "Hm" as %(<- & i & -> & ?).
69
    rewrite /na_inv.
70
    iMod (inv_alloc N with "[-]"); last (iModIntro; iExists i; eauto).
71 72 73
    iNext. iLeft. by iFrame.
  Qed.

Ralf Jung's avatar
Ralf Jung committed
74
  Lemma na_inv_open p E F N P :
75
    N  E  N  F 
Ralf Jung's avatar
Ralf Jung committed
76 77
    na_inv p N P - na_own p F ={E}=  P  na_own p (F∖↑N) 
                       ( P  na_own p (F∖↑N) ={E}= na_own p F).
78
  Proof.
79
    rewrite /na_inv. iIntros (??) "#Htlinv Htoks".
80
    iDestruct "Htlinv" as (i) "[% Hinv]".
Ralf Jung's avatar
Ralf Jung committed
81
    rewrite [F as X in na_own p X](union_difference_L (N) F) //.
82
    rewrite [X in (X  _)](union_difference_L {[i]} (N)) ?na_own_union; [|set_solver..].
Robbert Krebbers's avatar
Robbert Krebbers committed
83
    iDestruct "Htoks" as "[[Htoki $] $]".
84
    iInv N as "[[$ >Hdis]|>Htoki2]" "Hclose".
85 86
    - iMod ("Hclose" with "[Htoki]") as "_"; first auto.
      iIntros "!> [HP $]".
87
      iInv N as "[[_ >Hdis2]|>Hitok]" "Hclose".
88
      + iDestruct (own_valid_2 with "Hdis Hdis2") as %[_ Hval%gset_disj_valid_op].
Robbert Krebbers's avatar
Tweak.  
Robbert Krebbers committed
89
        set_solver.
90
      + iFrame. iApply "Hclose". iNext. iLeft. by iFrame.
91
    - iDestruct (na_own_disjoint with "Htoki Htoki2") as %?. set_solver.
92
  Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
93
End proofs.