auth.v 6.18 KB
Newer Older
Ralf Jung's avatar
Ralf Jung committed
1
From algebra Require Export auth upred_tactics.
2
From program_logic Require Export invariants global_functor.
3
Import uPred.
4

5
Class authG Λ Σ (A : cmraT) `{Empty A} := AuthG {
6
  auth_inG :> inG Λ Σ (authR A);
7
  auth_identity :> CMRAIdentity A;
8
  auth_timeless :> CMRADiscrete A;
9
10
}.

11
Definition authGF (A : cmraT) : rFunctor := constRF (authR A).
12
Instance authGF_inGF (A : cmraT) `{inGF Λ Σ (authGF A)}
13
  `{CMRAIdentity A, CMRADiscrete A} : authG Λ Σ A.
14
Proof. split; try apply _. apply: inGF_inG. Qed.
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Section definitions.
  Context `{authG Λ Σ A} (γ : gname).
  Definition auth_own  (a : A) : iPropG Λ Σ :=
    own γ ( a).
  Definition auth_inv (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
    ( a, own γ ( a)  φ a)%I.
  Definition auth_ctx (N : namespace) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
    inv N (auth_inv φ).

  Global Instance auth_own_ne n : Proper (dist n ==> dist n) auth_own.
  Proof. solve_proper. Qed.
  Global Instance auth_own_proper : Proper (() ==> ()) auth_own.
  Proof. solve_proper. Qed.
  Global Instance auth_own_timeless a : TimelessP (auth_own a).
  Proof. apply _. Qed.
  Global Instance auth_ctx_always_stable N φ : AlwaysStable (auth_ctx N φ).
  Proof. apply _. Qed.
End definitions.
Ralf Jung's avatar
Ralf Jung committed
34

35
Typeclasses Opaque auth_own auth_ctx.
36
37
38
Instance: Params (@auth_inv) 6.
Instance: Params (@auth_own) 6.
Instance: Params (@auth_ctx) 7.
39

40
Section auth.
41
  Context `{AuthI : authG Λ Σ A}.
42
  Context (φ : A  iPropG Λ Σ) {φ_proper : Proper (() ==> ()) φ}.
43
  Implicit Types N : namespace.
44
  Implicit Types P Q R : iPropG Λ Σ.
45
46
47
  Implicit Types a b : A.
  Implicit Types γ : gname.

Ralf Jung's avatar
Ralf Jung committed
48
  Lemma auth_own_op γ a b :
49
    auth_own γ (a  b)  (auth_own γ a  auth_own γ b)%I.
50
  Proof. by rewrite /auth_own -own_op auth_frag_op. Qed.
Ralf Jung's avatar
Ralf Jung committed
51
  Lemma auth_own_valid γ a : auth_own γ a   a.
52
  Proof. by rewrite /auth_own own_valid auth_validI. Qed.
53

54
  Lemma auth_alloc N E a :
55
     a  nclose N  E 
56
     φ a  (|={E}=>  γ, auth_ctx γ N φ  auth_own γ a).
57
  Proof.
58
    intros Ha HN. eapply sep_elim_True_r.
59
60
    { by eapply (own_alloc (Auth (Excl a) a) E). }
    rewrite pvs_frame_l. apply pvs_strip_pvs.
61
    rewrite sep_exist_l. apply exist_elim=>γ. rewrite -(exist_intro γ).
62
    trans ( auth_inv γ φ  auth_own γ a)%I.
63
    { rewrite /auth_inv -(exist_intro a) later_sep.
Ralf Jung's avatar
Ralf Jung committed
64
      ecancel [ φ _]%I.
65
      by rewrite -later_intro -own_op auth_both_op. }
66
    rewrite (inv_alloc N E) // /auth_ctx pvs_frame_r. apply pvs_mono.
67
    by rewrite always_and_sep_l.
68
69
  Qed.

70
  Lemma auth_empty γ E : True  (|={E}=> auth_own γ ).
71
  Proof. by rewrite -own_update_empty. Qed.
72

73
  Lemma auth_opened E γ a :
74
    ( auth_inv γ φ  auth_own γ a)
75
     (|={E}=>  a',  (a  a')   φ (a  a')  own γ ( (a  a')   a)).
Ralf Jung's avatar
Ralf Jung committed
76
  Proof.
77
    rewrite /auth_inv. rewrite later_exist sep_exist_r. apply exist_elim=>b.
Ralf Jung's avatar
Ralf Jung committed
78
79
    rewrite later_sep [( own _ _)%I]pvs_timeless !pvs_frame_r. apply pvs_mono.
    rewrite own_valid_l discrete_valid -!assoc. apply const_elim_sep_l=>Hv.
80
    rewrite [(▷φ _  _)%I]comm assoc -own_op.
81
82
    rewrite own_valid_r auth_validI /= and_elim_l sep_exist_l sep_exist_r /=.
    apply exist_elim=>a'.
83
    rewrite left_id -(exist_intro a').
84
85
    apply (eq_rewrite b (a  a') (λ x,  x   φ x  own γ ( x   a))%I).
    { by move=>n x y /timeless_iff ->. }
86
    { by eauto with I. }
Ralf Jung's avatar
Ralf Jung committed
87
88
    rewrite -valid_intro; last by apply Hv.
    rewrite left_id comm. auto with I.
Ralf Jung's avatar
Ralf Jung committed
89
  Qed.
Ralf Jung's avatar
Ralf Jung committed
90

91
  Lemma auth_closing `{!LocalUpdate Lv L} E γ a a' :
92
    Lv a   (L a  a') 
93
    ( φ (L a  a')  own γ ( (a  a')   a))
94
     (|={E}=>  auth_inv γ φ  auth_own γ (L a)).
Ralf Jung's avatar
Ralf Jung committed
95
  Proof.
96
    intros HL Hv. rewrite /auth_inv -(exist_intro (L a  a')).
Ralf Jung's avatar
Ralf Jung committed
97
    (* TODO it would be really nice to use cancel here *)
98
    rewrite later_sep [(_  ▷φ _)%I]comm -assoc.
99
    rewrite -pvs_frame_l. apply sep_mono_r.
Ralf Jung's avatar
Ralf Jung committed
100
    rewrite -later_intro -own_op.
101
    by apply own_update, (auth_local_update_l L).
Ralf Jung's avatar
Ralf Jung committed
102
103
  Qed.

104
105
  Context {V} (fsa : FSA Λ (globalF Σ) V) `{!FrameShiftAssertion fsaV fsa}.

106
  Lemma auth_fsa E N P (Ψ : V  iPropG Λ Σ) γ a :
107
    fsaV 
Ralf Jung's avatar
Ralf Jung committed
108
    nclose N  E 
109
110
    P  auth_ctx γ N φ 
    P  ( auth_own γ a   a',
111
            (a  a')   φ (a  a') -
112
113
          fsa (E  nclose N) (λ x,  L Lv (Hup : LocalUpdate Lv L),
             (Lv a   (L a  a'))   φ (L a  a') 
114
115
            (auth_own γ (L a) - Ψ x))) 
    P  fsa E Ψ.
Ralf Jung's avatar
Ralf Jung committed
116
  Proof.
117
    rewrite /auth_ctx=>? HN Hinv Hinner.
118
    eapply (inv_fsa fsa); eauto. rewrite Hinner=>{Hinner Hinv P HN}.
119
    apply wand_intro_l. rewrite assoc.
120
121
    rewrite (pvs_timeless (E  N)) pvs_frame_l pvs_frame_r.
    apply (fsa_strip_pvs fsa).
122
    rewrite (auth_opened (E  N)) !pvs_frame_r !sep_exist_r.
123
    apply (fsa_strip_pvs fsa). apply exist_elim=>a'.
124
    rewrite (forall_elim a'). rewrite [(_  _)%I]comm.
125
    eapply wand_apply_r; first (by eapply (wand_frame_l (own γ _))); last first.
126
    { rewrite assoc [(_  own _ _)%I]comm -assoc discrete_valid.  done. }
127
    rewrite fsa_frame_l.
Ralf Jung's avatar
Ralf Jung committed
128
    apply (fsa_mono_pvs fsa)=> x.
129
130
131
    rewrite sep_exist_l; apply exist_elim=> L.
    rewrite sep_exist_l; apply exist_elim=> Lv.
    rewrite sep_exist_l; apply exist_elim=> ?.
132
    rewrite comm -!assoc. apply const_elim_sep_l=>-[HL Hv].
133
    rewrite assoc [(_  (_ - _))%I]comm -assoc.
134
135
    rewrite (auth_closing (E  N)) //; [].
    rewrite pvs_frame_l. apply pvs_mono.
136
    by rewrite assoc [(_  _)%I]comm -assoc wand_elim_l.
Ralf Jung's avatar
Ralf Jung committed
137
  Qed.
138
  Lemma auth_fsa' L `{!LocalUpdate Lv L} E N P (Ψ : V  iPropG Λ Σ) γ a :
139
140
    fsaV 
    nclose N  E 
141
142
    P  auth_ctx γ N φ 
    P  ( auth_own γ a  ( a',
143
            (a  a')   φ (a  a') -
144
145
          fsa (E  nclose N) (λ x,
             (Lv a   (L a  a'))   φ (L a  a') 
146
147
            (auth_own γ (L a) - Ψ x)))) 
    P  fsa E Ψ.
148
149
  Proof.
    intros ??? HP. eapply auth_fsa with N γ a; eauto.
Ralf Jung's avatar
Ralf Jung committed
150
    rewrite HP; apply sep_mono_r, forall_mono=> a'.
151
152
153
    apply wand_mono; first done. apply (fsa_mono fsa)=> b.
    rewrite -(exist_intro L). by repeat erewrite <-exist_intro by apply _.
  Qed.
154
End auth.