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

Ralf Jung's avatar
Ralf Jung committed
6
7
8
9
10
(** Index of a CMRA in the product of global CMRAs. *)
Definition gid := nat.
(** Name of one instance of a particular CMRA in the ghost state. *)
Definition gname := positive.
(** The global CMRA: Indexed product over a gid i to (gname --fin--> Σ i) *)
11
Definition globalF (Σ : gid  iFunctor) : iFunctor :=
Ralf Jung's avatar
Ralf Jung committed
12
  iprodF (λ i, mapF gname (Σ i)).
13

14
Class InG (Λ : language) (Σ : gid  iFunctor) (i : gid) (A : cmraT) :=
15
  inG : A = Σ i (laterC (iPreProp Λ (globalF Σ))).
16

17
18
Definition to_globalF {Λ Σ A}
    (i : gid) `{!InG Λ Σ i A} (γ : gname) (a : A) : iGst Λ (globalF Σ) :=
Robbert Krebbers's avatar
Robbert Krebbers committed
19
20
  iprod_singleton i {[ γ  cmra_transport inG a ]}.
Definition own {Λ Σ A}
21
22
23
    (i : gid) `{!InG Λ Σ i A} (γ : gname) (a : A) : iProp Λ (globalF Σ) :=
  ownG (to_globalF i γ a).
Instance: Params (@to_globalF) 6.
Robbert Krebbers's avatar
Robbert Krebbers committed
24
Instance: Params (@own) 6.
25
26
27
28
Typeclasses Opaque to_globalF own.

Notation iPropG Λ Σ := (iProp Λ (globalF Σ)).
Notation iFunctorG := (gid  iFunctor).
Robbert Krebbers's avatar
Robbert Krebbers committed
29

30
Section global.
31
Context {Λ : language} {Σ : iFunctorG} (i : gid) `{!InG Λ Σ i A}.
32
33
Implicit Types a : A.

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

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

(** * Properties of own *)
Robbert Krebbers's avatar
Robbert Krebbers committed
63
64
65
66
67
Global Instance own_ne γ n : Proper (dist n ==> dist n) (own i γ).
Proof. by intros m m' Hm; rewrite /own Hm. Qed.
Global Instance own_proper γ : Proper (() ==> ()) (own i γ) := ne_proper _.

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

Robbert Krebbers's avatar
Robbert Krebbers committed
87
88
(* 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. *)
89
Lemma own_alloc_strong a E (G : gset gname) :  a  True  pvs E E ( γ, (γ  G)  own i γ a).
90
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
91
  intros Ha.
92
  rewrite -(pvs_mono _ _ ( m,  ( γ, γ  G  m = to_globalF i γ a)  ownG m)%I).
Robbert Krebbers's avatar
Robbert Krebbers committed
93
  * eapply pvs_ownG_updateP_empty, (iprod_singleton_updateP_empty i);
94
95
96
97
98
99
100
101
      first (eapply map_updateP_alloc_strong', cmra_transport_valid, Ha); naive_solver.
  * apply exist_elim=>m; apply const_elim_l=>-[γ [Hfresh ->]].
    by rewrite -(exist_intro γ) const_equiv.
Qed.
Lemma own_alloc a E :  a  True  pvs E E ( γ, own i γ a).
Proof.
  intros Ha. rewrite (own_alloc_strong a E ) //; []. apply pvs_mono.
  apply exist_mono=>?. eauto with I.
102
Qed.
103

104
Lemma own_updateP P γ a E :
Robbert Krebbers's avatar
Robbert Krebbers committed
105
  a ~~>: P  own i γ a  pvs E E ( a',  P a'  own i γ a').
106
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
107
  intros Ha.
108
  rewrite -(pvs_mono _ _ ( m,  ( a', m = to_globalF i γ a'  P a')  ownG m)%I).
Robbert Krebbers's avatar
Robbert Krebbers committed
109
  * eapply pvs_ownG_updateP, iprod_singleton_updateP;
110
      first by (eapply map_singleton_updateP', cmra_transport_updateP', Ha).
Robbert Krebbers's avatar
Robbert Krebbers committed
111
112
113
    naive_solver.
  * apply exist_elim=>m; apply const_elim_l=>-[a' [-> HP]].
    rewrite -(exist_intro a'). by apply and_intro; [apply const_intro|].
114
115
Qed.

116
Lemma own_updateP_empty `{Empty A, !CMRAIdentity A} P γ E :
117
   ~~>: P  True  pvs E E ( a,  P a  own i γ a).
118
Proof.
119
  intros Hemp.
120
  rewrite -(pvs_mono _ _ ( m,  ( a', m = to_globalF i γ a'  P a')  ownG m)%I).
121
122
  * eapply pvs_ownG_updateP_empty, iprod_singleton_updateP_empty;
      first eapply map_singleton_updateP_empty', cmra_transport_updateP', Hemp.
123
124
125
126
127
    naive_solver.
  * apply exist_elim=>m; apply const_elim_l=>-[a' [-> HP]].
    rewrite -(exist_intro a'). by apply and_intro; [apply const_intro|].
Qed.

Ralf Jung's avatar
Ralf Jung committed
128
Lemma own_update γ a a' E : a ~~> a'  own i γ a  pvs E E (own i γ a').
129
Proof.
130
131
132
133
134
135
136
137
138
  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 :
  True  pvs E E (own i γ ).
Proof.
  rewrite (own_updateP_empty ( =)); last by apply cmra_updateP_id.
  apply pvs_mono, exist_elim=>a. by apply const_elim_l=>->.
139
Qed.
140
End global.