auth.v 4.74 KB
Newer Older
Robbert Krebbers's avatar
Robbert Krebbers committed
1
From algebra Require Export auth.
2
From program_logic Require Export invariants ghost_ownership.
3
Import uPred.
4

5 6 7 8 9 10 11
Class AuthInG Λ Σ (i : gid) (A : cmraT) `{Empty A} := {
  auth_inG :> InG Λ Σ i (authRA A);
  auth_identity :> CMRAIdentity A;
  auth_timeless (a : A) :> Timeless a;
}.

Definition auth_inv {Λ Σ A} (i : gid) `{AuthInG Λ Σ i A}
12
  (γ : gname) (φ : A  iPropG Λ Σ) : iPropG Λ Σ := ( a, (■✓a  own i γ ( a))  φ a)%I.
13 14 15 16 17 18 19 20
Definition auth_own {Λ Σ A} (i : gid) `{AuthInG Λ Σ i A}
  (γ : gname) (a : A) : iPropG Λ Σ := own i γ ( a).
Definition auth_ctx {Λ Σ A} (i : gid) `{AuthInG Λ Σ i A}
    (γ : gname) (N : namespace) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
  inv N (auth_inv i γ φ).
Instance: Params (@auth_inv) 7.
Instance: Params (@auth_own) 7.
Instance: Params (@auth_ctx) 8.
21

22
Section auth.
23
  Context `{AuthInG Λ Σ AuthI A}.
24
  Context (φ : A  iPropG Λ Σ) {φ_proper : Proper (() ==> ()) φ}.
25
  Implicit Types N : namespace.
26
  Implicit Types P Q R : iPropG Λ Σ.
27 28 29
  Implicit Types a b : A.
  Implicit Types γ : gname.

30 31
  Lemma auth_alloc N a :
     a  φ a  pvs N N ( γ, auth_ctx AuthI γ N φ  auth_own AuthI γ a).
32
  Proof.
33 34 35 36
    intros Ha. rewrite -(right_id True%I ()%I (φ _)).
    rewrite (own_alloc AuthI (Auth (Excl a) a) N) //; [].
    rewrite pvs_frame_l. apply pvs_strip_pvs.
    rewrite sep_exist_l. apply exist_elim=>γ. rewrite -(exist_intro γ).
37
    transitivity ( auth_inv AuthI γ φ  auth_own AuthI γ a)%I.
38
    { rewrite /auth_inv -later_intro -(exist_intro a).
39
      rewrite const_equiv // left_id.
40
      rewrite [(_  φ _)%I]comm -assoc. apply sep_mono; first done.
41 42
      rewrite /auth_own -own_op auth_both_op. done. }
    rewrite (inv_alloc N) /auth_ctx pvs_frame_r. apply pvs_mono.
43
    by rewrite always_and_sep_l.
44 45
  Qed.

46
  Lemma auth_empty γ E : True  pvs E E (auth_own AuthI γ ).
47 48
  Proof. by rewrite own_update_empty /auth_own. Qed.

49
  Lemma auth_opened E a γ :
50
    ( auth_inv AuthI γ φ  auth_own AuthI γ a)
51
     pvs E E ( a', ■✓(a  a')   φ (a  a')  own AuthI γ ( (a  a')   a)).
Ralf Jung's avatar
Ralf Jung committed
52
  Proof.
53
    rewrite /auth_inv. rewrite later_exist sep_exist_r. apply exist_elim=>b.
54 55 56
    rewrite later_sep [((_  _))%I]pvs_timeless !pvs_frame_r. apply pvs_mono.
    rewrite always_and_sep_l -!assoc. apply const_elim_sep_l=>Hv.
    rewrite /auth_own [(▷φ _  _)%I]comm assoc -own_op.
57 58
    rewrite own_valid_r auth_validI /= and_elim_l sep_exist_l sep_exist_r /=.
    apply exist_elim=>a'.
59
    rewrite left_id -(exist_intro a').
Ralf Jung's avatar
Ralf Jung committed
60
    apply (eq_rewrite b (a  a')
61 62
              (λ x, ■✓x  ▷φ x  own AuthI γ ( x   a))%I).
    { by move=>n ? ? /timeless_iff ->. }
63
    { by eauto with I. }
64
    rewrite const_equiv // left_id comm.
Ralf Jung's avatar
Ralf Jung committed
65 66 67
    apply sep_mono; first done.
    by rewrite sep_elim_l.
  Qed.
Ralf Jung's avatar
Ralf Jung committed
68

69 70
  Lemma auth_closing E `{!LocalUpdate Lv L} a a' γ :
    Lv a   (L a  a') 
71
    ( φ (L a  a')  own AuthI γ ( (a  a')   a))
72
     pvs E E ( auth_inv AuthI γ φ  auth_own AuthI γ (L a)).
Ralf Jung's avatar
Ralf Jung committed
73
  Proof.
74
    intros HL Hv. rewrite /auth_inv /auth_own -(exist_intro (L a  a')).
75
    rewrite later_sep [(_  ▷φ _)%I]comm -assoc.
Ralf Jung's avatar
Ralf Jung committed
76
    rewrite -pvs_frame_l. apply sep_mono; first done.
77
    rewrite const_equiv // left_id -later_intro -own_op.
78
    by apply own_update, (auth_local_update_l L).
Ralf Jung's avatar
Ralf Jung committed
79 80
  Qed.

81
  (* Notice how the user has to prove that `b⋅a'` is valid at all
82 83
     step-indices. However, since A is timeless, that should not be
     a restriction.  *)
84
  Lemma auth_fsa {X : Type} {FSA} (FSAs : FrameShiftAssertion (A:=X) FSA)
85
        Lv L `{!LocalUpdate Lv L} N E P (Q : X  iPropG Λ Σ) γ a :
Ralf Jung's avatar
Ralf Jung committed
86
    nclose N  E 
87 88 89
    P  auth_ctx AuthI γ N φ 
    P  (auth_own AuthI γ a  ( a', ■✓(a  a')  ▷φ (a  a') -
        FSA (E  nclose N) (λ x, (Lv a  (L aa'))  ▷φ (L a  a')  (auth_own AuthI γ (L a) - Q x)))) 
90
    P  FSA E Q.
Ralf Jung's avatar
Ralf Jung committed
91
  Proof.
92
    rewrite /auth_ctx=>HN Hinv Hinner.
93
    eapply inv_fsa; [eassumption..|]. rewrite Hinner=>{Hinner Hinv P}.
94
    apply wand_intro_l.
95
    rewrite assoc auth_opened !pvs_frame_r !sep_exist_r.
96
    apply fsa_strip_pvs; first done. apply exist_elim=>a'.
97
    rewrite (forall_elim a'). rewrite [(_  _)%I]comm.
98 99 100
    (* Getting this wand eliminated is really annoying. *)
    rewrite [(_  _)%I]comm -!assoc [(▷φ _  _  _)%I]assoc [(▷φ _  _)%I]comm.
    rewrite wand_elim_r fsa_frame_l.
101
    apply fsa_mono_pvs; first done. intros x. rewrite comm -!assoc.
102
    apply const_elim_sep_l=>-[HL Hv].
103
    rewrite assoc [(_  (_ - _))%I]comm -assoc.
104
    rewrite auth_closing //; []. erewrite pvs_frame_l. apply pvs_mono.
105
    by rewrite assoc [(_  _)%I]comm -assoc wand_elim_l.
Ralf Jung's avatar
Ralf Jung committed
106
  Qed.
107
End auth.