ghost_ownership.v 6 KB
Newer Older
1
From prelude Require Export functions.
2 3 4
From algebra Require Export iprod.
From program_logic Require Export pviewshifts.
From program_logic Require Import ownership.
5 6
Import uPred.

Ralf Jung's avatar
Ralf Jung committed
7 8
(** Index of a CMRA in the product of global CMRAs. *)
Definition gid := nat.
9

Ralf Jung's avatar
Ralf Jung committed
10 11
(** Name of one instance of a particular CMRA in the ghost state. *)
Definition gname := positive.
12

Ralf Jung's avatar
Ralf Jung committed
13
(** The global CMRA: Indexed product over a gid i to (gname --fin--> Σ i) *)
14
Definition globalF (Σ : gid  iFunctor) : iFunctor :=
Ralf Jung's avatar
Ralf Jung committed
15
  iprodF (λ i, mapF gname (Σ i)).
16 17
Notation iFunctorG := (gid  iFunctor).
Notation iPropG Λ Σ := (iProp Λ (globalF Σ)).
18

19
Class inG (Λ : language) (Σ : iFunctorG) (A : cmraT) := InG {
20 21 22
  inG_id : gid;
  inG_prf : A = Σ inG_id (laterC (iPreProp Λ (globalF Σ)))
}.
23

24
Definition to_globalF `{inG Λ Σ A} (γ : gname) (a : A) : iGst Λ (globalF Σ) :=
25
  iprod_singleton inG_id {[ γ := cmra_transport inG_prf a ]}.
Ralf Jung's avatar
Ralf Jung committed
26
Definition own `{inG Λ Σ A} (γ : gname) (a : A) : iPropG Λ Σ :=
27 28 29
  ownG (to_globalF γ a).
Instance: Params (@to_globalF) 5.
Instance: Params (@own) 5.
30 31
Typeclasses Opaque to_globalF own.

32
(** Properties about ghost ownership *)
33
Section global.
34
Context `{i : inG Λ Σ A}.
35 36
Implicit Types a : A.

37
(** * Properties of to_globalC *)
38
Instance to_globalF_ne γ n : Proper (dist n ==> dist n) (to_globalF γ).
Robbert Krebbers's avatar
Robbert Krebbers committed
39
Proof. by intros a a' Ha; apply iprod_singleton_ne; rewrite Ha. Qed.
40
Lemma to_globalF_op γ a1 a2 :
41
  to_globalF γ (a1  a2)  to_globalF γ a1  to_globalF γ a2.
42
Proof.
43
  by rewrite /to_globalF iprod_op_singleton map_op_singleton cmra_transport_op.
44
Qed.
45
Lemma to_globalF_unit γ a : unit (to_globalF γ a)  to_globalF γ (unit a).
46
Proof.
47
  by rewrite /to_globalF
Robbert Krebbers's avatar
Robbert Krebbers committed
48
    iprod_unit_singleton map_unit_singleton cmra_transport_unit.
49
Qed.
50
Instance to_globalF_timeless γ m : Timeless m  Timeless (to_globalF γ m).
51
Proof. rewrite /to_globalF; apply _. Qed.
52

53
(** * Transport empty *)
54 55
Instance inG_empty `{Empty A} :
  Empty (Σ inG_id (laterC (iPreProp Λ (globalF Σ)))) := cmra_transport inG_prf .
56
Instance inG_empty_spec `{Empty A} :
57
  CMRAIdentity A  CMRAIdentity (Σ inG_id (laterC (iPreProp Λ (globalF Σ)))).
58 59
Proof.
  split.
60 61 62
  - apply cmra_transport_valid, cmra_empty_valid.
  - intros x; rewrite /empty /inG_empty; destruct inG_prf. by rewrite left_id.
  - apply _.
63 64 65
Qed.

(** * Properties of own *)
66
Global Instance own_ne γ n : Proper (dist n ==> dist n) (own γ).
Robbert Krebbers's avatar
Robbert Krebbers committed
67
Proof. solve_proper. Qed.
68
Global Instance own_proper γ : Proper (() ==> ()) (own γ) := ne_proper _.
Robbert Krebbers's avatar
Robbert Krebbers committed
69

70
Lemma own_op γ a1 a2 : own γ (a1  a2)  (own γ a1  own γ a2)%I.
71
Proof. by rewrite /own -ownG_op to_globalF_op. Qed.
72
Global Instance own_mono γ : Proper (flip () ==> ()) (own γ).
Ralf Jung's avatar
Ralf Jung committed
73
Proof. move=>a b [c H]. rewrite H own_op. eauto with I. Qed.
74
Lemma always_own_unit γ a : ( own γ (unit a))%I  own γ (unit a).
75
Proof. by rewrite /own -to_globalF_unit always_ownG_unit. Qed.
76 77
Lemma always_own γ a : unit a  a  ( own γ a)%I  own γ a.
Proof. by intros <-; rewrite always_own_unit. Qed.
78
Lemma own_valid γ a : own γ a   a.
79
Proof.
80
  rewrite /own ownG_valid /to_globalF.
81
  rewrite iprod_validI (forall_elim inG_id) iprod_lookup_singleton.
82
  rewrite map_validI (forall_elim γ) lookup_singleton option_validI.
83
  by destruct inG_prf.
84
Qed.
85
Lemma own_valid_r γ a : own γ a  (own γ a   a).
86
Proof. apply: uPred.always_entails_r. apply own_valid. Qed.
87
Lemma own_valid_l γ a : own γ a  ( a  own γ a).
88
Proof. by rewrite comm -own_valid_r. Qed.
89
Global Instance own_timeless γ a : Timeless a  TimelessP (own γ a).
Robbert Krebbers's avatar
Robbert Krebbers committed
90
Proof. unfold own; apply _. Qed.
91 92
Global Instance own_unit_always_stable γ a : AlwaysStable (own γ (unit a)).
Proof. by rewrite /AlwaysStable always_own_unit. Qed.
93

Robbert Krebbers's avatar
Robbert Krebbers committed
94 95
(* TODO: This also holds if we just have ✓ a at the current step-idx, as Iris
   assertion. However, the map_updateP_alloc does not suffice to show this. *)
96
Lemma own_alloc_strong a E (G : gset gname) :
97
   a  True  (|={E}=>  γ, (γ  G)  own γ a).
98
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
99
  intros Ha.
100
  rewrite -(pvs_mono _ _ ( m,  ( γ, γ  G  m = to_globalF γ a)  ownG m)%I).
101
  - eapply pvs_ownG_updateP_empty, (iprod_singleton_updateP_empty inG_id);
102 103
      first (eapply map_updateP_alloc_strong', cmra_transport_valid, Ha);
      naive_solver.
104
  - apply exist_elim=>m; apply const_elim_l=>-[γ [Hfresh ->]].
105
    by rewrite -(exist_intro γ) const_equiv // left_id.
106
Qed.
107
Lemma own_alloc a E :  a  True  (|={E}=>  γ, own γ a).
108 109 110
Proof.
  intros Ha. rewrite (own_alloc_strong a E ) //; []. apply pvs_mono.
  apply exist_mono=>?. eauto with I.
111
Qed.
112

113
Lemma own_updateP P γ a E :
114
  a ~~>: P  own γ a  (|={E}=>  a',  P a'  own γ a').
115
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
116
  intros Ha.
117
  rewrite -(pvs_mono _ _ ( m,  ( a', m = to_globalF γ a'  P a')  ownG m)%I).
118
  - eapply pvs_ownG_updateP, iprod_singleton_updateP;
119
      first by (eapply map_singleton_updateP', cmra_transport_updateP', Ha).
Robbert Krebbers's avatar
Robbert Krebbers committed
120
    naive_solver.
121
  - apply exist_elim=>m; apply const_elim_l=>-[a' [-> HP]].
Robbert Krebbers's avatar
Robbert Krebbers committed
122
    rewrite -(exist_intro a'). by apply and_intro; [apply const_intro|].
123 124
Qed.

125
Lemma own_updateP_empty `{Empty A, !CMRAIdentity A} P γ E :
126
   ~~>: P  True  (|={E}=>  a,  P a  own γ a).
127
Proof.
128
  intros Hemp.
129
  rewrite -(pvs_mono _ _ ( m,  ( a', m = to_globalF γ a'  P a')  ownG m)%I).
130
  - eapply pvs_ownG_updateP_empty, iprod_singleton_updateP_empty;
131
      first eapply map_singleton_updateP_empty', cmra_transport_updateP', Hemp.
132
    naive_solver.
133
  - apply exist_elim=>m; apply const_elim_l=>-[a' [-> HP]].
134 135 136
    rewrite -(exist_intro a'). by apply and_intro; [apply const_intro|].
Qed.

137
Lemma own_update γ a a' E : a ~~> a'  own γ a  (|={E}=> own γ a').
138
Proof.
139 140 141 142 143
  intros; rewrite (own_updateP (a' =)); last by apply cmra_update_updateP.
  by apply pvs_mono, exist_elim=> a''; apply const_elim_l=> ->.
Qed.

Lemma own_update_empty `{Empty A, !CMRAIdentity A} γ E :
144
  True  (|={E}=> own γ ).
145 146 147
Proof.
  rewrite (own_updateP_empty ( =)); last by apply cmra_updateP_id.
  apply pvs_mono, exist_elim=>a. by apply const_elim_l=>->.
148
Qed.
149
End global.