ghost_ownership.v 3.67 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
  ownG (to_globalF γ a).
Instance: Params (@own) 5.
10
Typeclasses Opaque own.
11

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

17
(** * Properties of own *)
18
Global Instance own_ne γ n : Proper (dist n ==> dist n) (own γ).
Robbert Krebbers's avatar
Robbert Krebbers committed
19
Proof. solve_proper. Qed.
20
Global Instance own_proper γ : Proper (() ==> ()) (own γ) := ne_proper _.
Robbert Krebbers's avatar
Robbert Krebbers committed
21

22
Lemma own_op γ a1 a2 : own γ (a1  a2)  own γ a1  own γ a2.
23
Proof. by rewrite /own -ownG_op to_globalF_op. Qed.
24
Global Instance own_mono γ : Proper (flip () ==> ()) (own γ).
25
Proof. move=>a b [c ->]. rewrite own_op. eauto with I. Qed.
26
Lemma own_valid γ a : own γ a   a.
27
Proof.
28
  rewrite /own ownG_valid /to_globalF.
29
  rewrite iprod_validI (forall_elim (inG_id i)) iprod_lookup_singleton.
30
  rewrite gmap_validI (forall_elim γ) lookup_singleton option_validI.
31
32
  (* implicit arguments differ a bit *)
  by trans ( cmra_transport inG_prf a : iPropG Λ Σ)%I; last destruct inG_prf.
33
Qed.
34
Lemma own_valid_r γ a : own γ a  own γ a   a.
35
Proof. apply: uPred.always_entails_r. apply own_valid. Qed.
36
Lemma own_valid_l γ a : own γ a   a  own γ a.
37
Proof. by rewrite comm -own_valid_r. Qed.
38
Global Instance own_timeless γ a : Timeless a  TimelessP (own γ a).
39
40
41
Proof. rewrite /own; apply _. Qed.
Global Instance own_core_persistent γ a : Persistent a  PersistentP (own γ a).
Proof. rewrite /own; apply _. Qed.
42

Robbert Krebbers's avatar
Robbert Krebbers committed
43
44
(* 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. *)
45
Lemma own_alloc_strong a E (G : gset gname) :
46
   a  True ={E}=>  γ, (γ  G)  own γ a.
47
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
48
  intros Ha.
49
  rewrite -(pvs_mono _ _ ( m,  ( γ, γ  G  m = to_globalF γ a)  ownG m)%I).
50
  - rewrite ownG_empty.
51
    eapply pvs_ownG_updateP, (iprod_singleton_updateP_empty (inG_id i));
52
      first (eapply alloc_updateP_strong', cmra_transport_valid, Ha);
53
      naive_solver.
54
  - apply exist_elim=>m; apply const_elim_l=>-[γ [Hfresh ->]].
55
    by rewrite -(exist_intro γ) const_equiv // left_id.
56
Qed.
57
Lemma own_alloc a E :  a  True ={E}=>  γ, own γ a.
58
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
59
60
  intros Ha. rewrite (own_alloc_strong a E ) //; [].
  apply pvs_mono, exist_mono=>?. eauto with I.
61
Qed.
62

63
Lemma own_updateP P γ a E :
64
  a ~~>: P  own γ a ={E}=>  a',  P a'  own γ a'.
65
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
66
  intros Ha.
67
  rewrite -(pvs_mono _ _ ( m,  ( a', m = to_globalF γ a'  P a')  ownG m)%I).
68
  - eapply pvs_ownG_updateP, iprod_singleton_updateP;
69
      first by (eapply singleton_updateP', cmra_transport_updateP', Ha).
Robbert Krebbers's avatar
Robbert Krebbers committed
70
    naive_solver.
71
  - apply exist_elim=>m; apply const_elim_l=>-[a' [-> HP]].
Robbert Krebbers's avatar
Robbert Krebbers committed
72
    rewrite -(exist_intro a'). by apply and_intro; [apply const_intro|].
73
74
Qed.

75
Lemma own_update γ a a' E : a ~~> a'  own γ a ={E}=> own γ a'.
76
Proof.
77
78
79
  intros; rewrite (own_updateP (a' =)); last by apply cmra_update_updateP.
  by apply pvs_mono, exist_elim=> a''; apply const_elim_l=> ->.
Qed.
80
End global.
81

82
83
84
85
Section global_empty.
Context `{i : inG Λ Σ (A:ucmraT)}.
Implicit Types a : A.

86
Lemma own_empty γ E : True ={E}=> own γ .
87
Proof.
88
  rewrite ownG_empty /own. apply pvs_ownG_update, iprod_singleton_update_empty.
89
  apply (alloc_unit_singleton_update (cmra_transport inG_prf )); last done.
90
91
  - apply cmra_transport_valid, ucmra_unit_valid.
  - intros x; destruct inG_prf. by rewrite left_id.
92
Qed.
93
End global_empty.