ghost_ownership.v 6.08 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 15 16
Definition globalF (Σ : gid  rFunctor) : rFunctor :=
  iprodRF (λ i, mapRF gname (Σ i)).
Notation rFunctorG := (gid  rFunctor).
17
Notation iPropG Λ Σ := (iProp Λ (globalF Σ)).
18

19
Class inG (Λ : language) (Σ : rFunctorG) (A : cmraT) := InG {
20
  inG_id : gid;
21
  inG_prf : A = Σ inG_id (iPreProp Λ (globalF Σ))
22
}.
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
Instance inG_empty `{Empty A} :
55
  Empty (Σ inG_id (iPreProp Λ (globalF Σ))) := cmra_transport inG_prf .
56
Instance inG_empty_spec `{Empty A} :
57
  CMRAIdentity A  CMRAIdentity (Σ inG_id (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 84
  (* implicit arguments differ a bit *)
  by trans ( cmra_transport inG_prf a : iPropG Λ Σ)%I; last destruct inG_prf.
85
Qed.
86
Lemma own_valid_r γ a : own γ a  (own γ a   a).
87
Proof. apply: uPred.always_entails_r. apply own_valid. Qed.
88
Lemma own_valid_l γ a : own γ a  ( a  own γ a).
89
Proof. by rewrite comm -own_valid_r. Qed.
90
Global Instance own_timeless γ a : Timeless a  TimelessP (own γ a).
Robbert Krebbers's avatar
Robbert Krebbers committed
91
Proof. unfold own; apply _. Qed.
92 93
Global Instance own_unit_always_stable γ a : AlwaysStable (own γ (unit a)).
Proof. by rewrite /AlwaysStable always_own_unit. Qed.
94

Robbert Krebbers's avatar
Robbert Krebbers committed
95 96
(* 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. *)
97
Lemma own_alloc_strong a E (G : gset gname) :
98
   a  True  (|={E}=>  γ, (γ  G)  own γ a).
99
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
100
  intros Ha.
101
  rewrite -(pvs_mono _ _ ( m,  ( γ, γ  G  m = to_globalF γ a)  ownG m)%I).
102
  - eapply pvs_ownG_updateP_empty, (iprod_singleton_updateP_empty inG_id);
103 104
      first (eapply map_updateP_alloc_strong', cmra_transport_valid, Ha);
      naive_solver.
105
  - apply exist_elim=>m; apply const_elim_l=>-[γ [Hfresh ->]].
106
    by rewrite -(exist_intro γ) const_equiv // left_id.
107
Qed.
108
Lemma own_alloc a E :  a  True  (|={E}=>  γ, own γ a).
109 110 111
Proof.
  intros Ha. rewrite (own_alloc_strong a E ) //; []. apply pvs_mono.
  apply exist_mono=>?. eauto with I.
112
Qed.
113

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

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

138
Lemma own_update γ a a' E : a ~~> a'  own γ a  (|={E}=> own γ a').
139
Proof.
140 141 142 143 144
  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 :
145
  True  (|={E}=> own γ ).
146 147 148
Proof.
  rewrite (own_updateP_empty ( =)); last by apply cmra_updateP_id.
  apply pvs_mono, exist_elim=>a. by apply const_elim_l=>->.
149
Qed.
150
End global.