ownership.v 3.42 KB
Newer Older
1
From program_logic Require Export model.
Robbert Krebbers's avatar
Robbert Krebbers committed
2

3
Definition ownI {Λ Σ} (i : positive) (P : iProp Λ Σ) : iProp Λ Σ :=
Ralf Jung's avatar
Ralf Jung committed
4
  uPred_ownM (Res {[ i  to_agree (Next (iProp_unfold P)) ]}  ).
5
Arguments ownI {_ _} _ _%I.
Ralf Jung's avatar
Ralf Jung committed
6 7
Definition ownP {Λ Σ} (σ: state Λ) : iProp Λ Σ := uPred_ownM (Res  (Excl σ) ).
Definition ownG {Λ Σ} (m: iGst Λ Σ) : iProp Λ Σ := uPred_ownM (Res   (Some m)).
8
Instance: Params (@ownI) 3.
9 10
Instance: Params (@ownP) 2.
Instance: Params (@ownG) 2.
Robbert Krebbers's avatar
Robbert Krebbers committed
11

12
Typeclasses Opaque ownI ownG ownP.
Robbert Krebbers's avatar
Robbert Krebbers committed
13

Robbert Krebbers's avatar
Robbert Krebbers committed
14
Section ownership.
15 16 17 18 19
Context {Λ : language} {Σ : iFunctor}.
Implicit Types r : iRes Λ Σ.
Implicit Types σ : state Λ.
Implicit Types P : iProp Λ Σ.
Implicit Types m : iGst Λ Σ.
Robbert Krebbers's avatar
Robbert Krebbers committed
20 21

(* Invariants *)
22
Global Instance ownI_contractive i : Contractive (@ownI Λ Σ i).
Robbert Krebbers's avatar
Robbert Krebbers committed
23
Proof.
24
  intros n P Q HPQ. rewrite /ownI.
25
  apply uPred.ownM_ne, Res_ne; auto; apply singleton_ne, to_agree_ne.
26
  by apply Next_contractive=> j ?; rewrite (HPQ j).
Robbert Krebbers's avatar
Robbert Krebbers committed
27
Qed.
28
Lemma always_ownI i P : ( ownI i P)%I  ownI i P.
Robbert Krebbers's avatar
Robbert Krebbers committed
29
Proof.
30
  apply uPred.always_ownM.
31
  by rewrite Res_unit !cmra_unit_empty map_unit_singleton.
Robbert Krebbers's avatar
Robbert Krebbers committed
32
Qed.
33 34 35
Global Instance ownI_always_stable i P : AlwaysStable (ownI i P).
Proof. by rewrite /AlwaysStable always_ownI. Qed.
Lemma ownI_sep_dup i P : ownI i P  (ownI i P  ownI i P)%I.
36
Proof. apply (uPred.always_sep_dup _). Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
37 38

(* physical state *)
39
Lemma ownP_twice σ1 σ2 : (ownP σ1  ownP σ2 : iProp Λ Σ)  False.
Robbert Krebbers's avatar
Robbert Krebbers committed
40
Proof.
41 42
  rewrite /ownP -uPred.ownM_op Res_op.
  by apply uPred.ownM_invalid; intros (_&?&_).
Robbert Krebbers's avatar
Robbert Krebbers committed
43
Qed.
44
Global Instance ownP_timeless σ : TimelessP (@ownP Λ Σ σ).
Robbert Krebbers's avatar
Robbert Krebbers committed
45
Proof. rewrite /ownP; apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
46 47

(* ghost state *)
48
Global Instance ownG_ne n : Proper (dist n ==> dist n) (@ownG Λ Σ).
Robbert Krebbers's avatar
Robbert Krebbers committed
49
Proof. by intros m m' Hm; unfold ownG; rewrite Hm. Qed.
50
Global Instance ownG_proper : Proper (() ==> ()) (@ownG Λ Σ) := ne_proper _.
Robbert Krebbers's avatar
Robbert Krebbers committed
51
Lemma ownG_op m1 m2 : ownG (m1  m2)  (ownG m1  ownG m2)%I.
52
Proof. by rewrite /ownG -uPred.ownM_op Res_op !left_id. Qed.
Ralf Jung's avatar
Ralf Jung committed
53 54
Global Instance ownG_mono : Proper (flip () ==> ()) (@ownG Λ Σ).
Proof. move=>a b [c H]. rewrite H ownG_op. eauto with I. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
55 56
Lemma always_ownG_unit m : ( ownG (unit m))%I  ownG (unit m).
Proof.
57
  apply uPred.always_ownM.
58
  by rewrite Res_unit !cmra_unit_empty -{2}(cmra_unit_idemp m).
Robbert Krebbers's avatar
Robbert Krebbers committed
59
Qed.
60 61 62 63 64
Lemma ownG_valid m : ownG m   m.
Proof.
  rewrite /ownG uPred.ownM_valid res_validI /= option_validI; auto with I.
Qed.
Lemma ownG_valid_r m : ownG m  (ownG m   m).
65
Proof. apply (uPred.always_entails_r _ _), ownG_valid. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
66 67
Global Instance ownG_timeless m : Timeless m  TimelessP (ownG m).
Proof. rewrite /ownG; apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
68

Ralf Jung's avatar
Ralf Jung committed
69

Robbert Krebbers's avatar
Robbert Krebbers committed
70
(* inversion lemmas *)
71
Lemma ownI_spec r n i P :
Robbert Krebbers's avatar
Robbert Krebbers committed
72
  {n} r 
73
  (ownI i P) n r  wld r !! i {n} Some (to_agree (Next (iProp_unfold P))).
Robbert Krebbers's avatar
Robbert Krebbers committed
74 75 76 77 78
Proof.
  intros [??]; rewrite /uPred_holds/=res_includedN/=singleton_includedN; split.
  * intros [(P'&Hi&HP) _]; rewrite Hi.
    by apply Some_dist, symmetry, agree_valid_includedN,
      (cmra_included_includedN _ P'),HP; apply map_lookup_validN with (wld r) i.
79
  * intros ?; split_ands; try apply cmra_empty_leastN; eauto.
Robbert Krebbers's avatar
Robbert Krebbers committed
80
Qed.
81
Lemma ownP_spec r n σ : {n} r  (ownP σ) n r  pst r {n} Excl σ.
Robbert Krebbers's avatar
Robbert Krebbers committed
82 83
Proof.
  intros (?&?&?); rewrite /uPred_holds /= res_includedN /= Excl_includedN //.
84
  naive_solver (apply cmra_empty_leastN).
Robbert Krebbers's avatar
Robbert Krebbers committed
85
Qed.
86
Lemma ownG_spec r n m : (ownG m) n r  Some m {n} gst r.
Robbert Krebbers's avatar
Robbert Krebbers committed
87
Proof.
88
  rewrite /uPred_holds /= res_includedN; naive_solver (apply cmra_empty_leastN).
Robbert Krebbers's avatar
Robbert Krebbers committed
89 90
Qed.
End ownership.