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

Ralf Jung's avatar
Ralf Jung committed
7
Definition own `{inG Λ Σ A} (γ : gname) (a : A) : iPropG Λ Σ :=
8 9 10
  ownG (to_globalF γ a).
Instance: Params (@to_globalF) 5.
Instance: Params (@own) 5.
11 12
Typeclasses Opaque to_globalF own.

13
(** Properties about ghost ownership *)
14
Section global.
15
Context `{i : inG Λ Σ A}.
16 17
Implicit Types a : A.

18
(** * Transport empty *)
19
Instance inG_empty `{Empty A} :
20
  Empty (projT2 Σ inG_id (iPreProp Λ (globalF Σ))) := cmra_transport inG_prf .
21
Instance inG_empty_spec `{Empty A} :
22
  CMRAUnit A  CMRAUnit (projT2 Σ inG_id (iPreProp Λ (globalF Σ))).
23 24
Proof.
  split.
25
  - apply cmra_transport_valid, cmra_unit_valid.
26 27
  - intros x; rewrite /empty /inG_empty; destruct inG_prf. by rewrite left_id.
  - apply _.
28 29 30
Qed.

(** * Properties of own *)
31
Global Instance own_ne γ n : Proper (dist n ==> dist n) (own γ).
Robbert Krebbers's avatar
Robbert Krebbers committed
32
Proof. solve_proper. Qed.
33
Global Instance own_proper γ : Proper (() ==> ()) (own γ) := ne_proper _.
Robbert Krebbers's avatar
Robbert Krebbers committed
34

35
Lemma own_op γ a1 a2 : own γ (a1  a2)  (own γ a1  own γ a2).
36
Proof. by rewrite /own -ownG_op to_globalF_op. Qed.
37
Global Instance own_mono γ : Proper (flip () ==> ()) (own γ).
38
Proof. move=>a b [c H]. rewrite H own_op. eauto with I. Qed.
39
Lemma own_valid γ a : own γ a   a.
40
Proof.
41
  rewrite /own ownG_valid /to_globalF.
42
  rewrite iprod_validI (forall_elim inG_id) iprod_lookup_singleton.
43
  rewrite map_validI (forall_elim γ) lookup_singleton option_validI.
44 45
  (* implicit arguments differ a bit *)
  by trans ( cmra_transport inG_prf a : iPropG Λ Σ)%I; last destruct inG_prf.
46
Qed.
47
Lemma own_valid_r γ a : own γ a  (own γ a   a).
48
Proof. apply: uPred.always_entails_r. apply own_valid. Qed.
49
Lemma own_valid_l γ a : own γ a  ( a  own γ a).
50
Proof. by rewrite comm -own_valid_r. Qed.
51
Global Instance own_timeless γ a : Timeless a  TimelessP (own γ a).
52 53 54
Proof. rewrite /own; apply _. Qed.
Global Instance own_core_persistent γ a : Persistent a  PersistentP (own γ a).
Proof. rewrite /own; apply _. Qed.
55

Robbert Krebbers's avatar
Robbert Krebbers committed
56 57
(* 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. *)
58
Lemma own_alloc_strong a E (G : gset gname) :
59
   a  True  (|={E}=>  γ, (γ  G)  own γ a).
60
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
61
  intros Ha.
62
  rewrite -(pvs_mono _ _ ( m,  ( γ, γ  G  m = to_globalF γ a)  ownG m)%I).
63
  - rewrite ownG_empty. eapply pvs_ownG_updateP, (iprod_singleton_updateP_empty inG_id);
64 65
      first (eapply map_updateP_alloc_strong', cmra_transport_valid, Ha);
      naive_solver.
66
  - apply exist_elim=>m; apply const_elim_l=>-[γ [Hfresh ->]].
67
    by rewrite -(exist_intro γ) const_equiv // left_id.
68
Qed.
69
Lemma own_alloc a E :  a  True  (|={E}=>  γ, own γ a).
70 71 72
Proof.
  intros Ha. rewrite (own_alloc_strong a E ) //; []. apply pvs_mono.
  apply exist_mono=>?. eauto with I.
73
Qed.
74

75
Lemma own_updateP P γ a E :
76
  a ~~>: P  own γ a  (|={E}=>  a',  P a'  own γ a').
77
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
78
  intros Ha.
79
  rewrite -(pvs_mono _ _ ( m,  ( a', m = to_globalF γ a'  P a')  ownG m)%I).
80
  - eapply pvs_ownG_updateP, iprod_singleton_updateP;
81
      first by (eapply map_singleton_updateP', cmra_transport_updateP', Ha).
Robbert Krebbers's avatar
Robbert Krebbers committed
82
    naive_solver.
83
  - apply exist_elim=>m; apply const_elim_l=>-[a' [-> HP]].
Robbert Krebbers's avatar
Robbert Krebbers committed
84
    rewrite -(exist_intro a'). by apply and_intro; [apply const_intro|].
85 86
Qed.

87
Lemma own_update γ a a' E : a ~~> a'  own γ a  (|={E}=> own γ a').
88
Proof.
89 90 91 92
  intros; rewrite (own_updateP (a' =)); last by apply cmra_update_updateP.
  by apply pvs_mono, exist_elim=> a''; apply const_elim_l=> ->.
Qed.

93
Lemma own_empty `{Empty A, !CMRAUnit A} γ E :
94
  True  (|={E}=> own γ ).
95
Proof.
96 97 98
  rewrite ownG_empty /own. apply pvs_ownG_update, cmra_update_updateP.
  eapply iprod_singleton_updateP_empty;
      first by eapply map_singleton_updateP_empty', cmra_transport_updateP',
99
               cmra_update_updateP, cmra_update_unit.
100
  naive_solver.
101
Qed.
102
End global.