sts.v 5.25 KB
Newer Older
1 2
From iris.algebra Require Export sts upred_tactics.
From iris.program_logic Require Export invariants ghost_ownership.
3
From iris.proofmode Require Import invariants ghost_ownership.
Ralf Jung's avatar
Ralf Jung committed
4 5
Import uPred.

6
(** The CMRA we need. *)
7
Class stsG Λ Σ (sts : stsT) := StsG {
8
  sts_inG :> inG Λ Σ (stsR sts);
Robbert Krebbers's avatar
Robbert Krebbers committed
9
  sts_inhabited :> Inhabited (sts.state sts);
Ralf Jung's avatar
Ralf Jung committed
10
}.
11
Coercion sts_inG : stsG >-> inG.
12
(** The Functor we need. *)
13
Definition stsGF (sts : stsT) : gFunctor := GFunctor (constRF (stsR sts)).
14
(* Show and register that they match. *)
15
Instance inGF_stsG sts `{inGF Λ Σ (stsGF sts)}
16 17
  `{Inhabited (sts.state sts)} : stsG Λ Σ sts.
Proof. split; try apply _. apply: inGF_inG. Qed.
18

19 20 21 22 23 24 25 26 27 28
Section definitions.
  Context `{i : stsG Λ Σ sts} (γ : gname).
  Definition sts_ownS (S : sts.states sts) (T : sts.tokens sts) : iPropG Λ Σ:=
    own γ (sts_frag S T).
  Definition sts_own (s : sts.state sts) (T : sts.tokens sts) : iPropG Λ Σ :=
    own γ (sts_frag_up s T).
  Definition sts_inv (φ : sts.state sts  iPropG Λ Σ) : iPropG Λ Σ :=
    ( s, own γ (sts_auth s )  φ s)%I.
  Definition sts_ctx (N : namespace) (φ: sts.state sts  iPropG Λ Σ) : iPropG Λ Σ :=
    inv N (sts_inv φ).
Ralf Jung's avatar
Ralf Jung committed
29

30 31 32 33 34 35
  Global Instance sts_inv_ne n :
    Proper (pointwise_relation _ (dist n) ==> dist n) sts_inv.
  Proof. solve_proper. Qed.
  Global Instance sts_inv_proper :
    Proper (pointwise_relation _ () ==> ()) sts_inv.
  Proof. solve_proper. Qed.
36
  Global Instance sts_ownS_proper : Proper (() ==> () ==> ()) sts_ownS.
37
  Proof. solve_proper. Qed.
38
  Global Instance sts_own_proper s : Proper (() ==> ()) (sts_own s).
39 40 41 42 43
  Proof. solve_proper. Qed.
  Global Instance sts_ctx_ne n N :
    Proper (pointwise_relation _ (dist n) ==> dist n) (sts_ctx N).
  Proof. solve_proper. Qed.
  Global Instance sts_ctx_proper N :
44
    Proper (pointwise_relation _ () ==> ()) (sts_ctx N).
45
  Proof. solve_proper. Qed.
46
  Global Instance sts_ctx_persistent N φ : PersistentP (sts_ctx N φ).
47 48 49
  Proof. apply _. Qed.
End definitions.
Typeclasses Opaque sts_own sts_ownS sts_ctx.
50 51 52 53
Instance: Params (@sts_inv) 5.
Instance: Params (@sts_ownS) 5.
Instance: Params (@sts_own) 6.
Instance: Params (@sts_ctx) 6.
Ralf Jung's avatar
Ralf Jung committed
54 55

Section sts.
56
  Context `{stsG Λ Σ sts} (φ : sts.state sts  iPropG Λ Σ).
Ralf Jung's avatar
Ralf Jung committed
57 58 59
  Implicit Types N : namespace.
  Implicit Types P Q R : iPropG Λ Σ.
  Implicit Types γ : gname.
Robbert Krebbers's avatar
Robbert Krebbers committed
60 61 62
  Implicit Types S : sts.states sts.
  Implicit Types T : sts.tokens sts.

63 64
  (* The same rule as implication does *not* hold, as could be shown using
     sts_frag_included. *)
Ralf Jung's avatar
Ralf Jung committed
65
  Lemma sts_ownS_weaken E γ S1 S2 T1 T2 :
66
    T2  T1  S1  S2  sts.closed S2 T2 
67
    sts_ownS γ S1 T1  (|={E}=> sts_ownS γ S2 T2).
68
  Proof. intros ???. by apply own_update, sts_update_frag. Qed.
69

Ralf Jung's avatar
Ralf Jung committed
70
  Lemma sts_own_weaken E γ s S T1 T2 :
71
    T2  T1  s  S  sts.closed S T2 
72
    sts_own γ s T1  (|={E}=> sts_ownS γ S T2).
73
  Proof. intros ???. by apply own_update, sts_update_frag_up. Qed.
74

Ralf Jung's avatar
Ralf Jung committed
75
  Lemma sts_ownS_op γ S1 S2 T1 T2 :
Robbert Krebbers's avatar
Robbert Krebbers committed
76
    T1  T2  sts.closed S1 T1  sts.closed S2 T2 
77
    sts_ownS γ (S1  S2) (T1  T2)  (sts_ownS γ S1 T1  sts_ownS γ S2 T2).
78
  Proof. intros. by rewrite /sts_ownS -own_op sts_op_frag. Qed.
Ralf Jung's avatar
Ralf Jung committed
79

80 81
  Lemma sts_alloc E N s :
    nclose N  E 
82
     φ s  (|={E}=>  γ, sts_ctx γ N φ  sts_own γ s (  sts.tok s)).
83
  Proof.
84 85 86 87 88 89
    iIntros {?} "Hφ". rewrite /sts_ctx /sts_own.
    iPvs (own_alloc (sts_auth s (  sts.tok s))) as {γ} "Hγ".
    { apply sts_auth_valid; set_solver. }
    iExists γ; iRevert "Hγ"; rewrite -sts_op_auth_frag_up; iIntros "[Hγ $]".
    iPvs (inv_alloc N _ (sts_inv γ φ) with "[Hφ Hγ]") as "#?"; auto.
    iNext. iExists s. by iFrame "Hφ".
Ralf Jung's avatar
Ralf Jung committed
90
  Qed.
91

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

94
  Lemma sts_fsaS E N (Ψ : V  iPropG Λ Σ) γ S T :
Ralf Jung's avatar
Ralf Jung committed
95
    fsaV  nclose N  E 
96 97 98 99 100
    (sts_ctx γ N φ  sts_ownS γ S T   s,
       (s  S)   φ s -
      fsa (E  nclose N) (λ x,  s' T',
         sts.steps (s, T) (s', T')   φ s'  (sts_own γ s' T' - Ψ x)))
     fsa E Ψ.
101
  Proof.
102 103 104 105 106 107 108 109 110 111 112 113 114
    iIntros {??} "(#? & Hγf & HΨ)". rewrite /sts_ctx /sts_ownS /sts_inv /sts_own.
    iInv N as {s} "[Hγ Hφ]"; iTimeless "Hγ".
    iCombine "Hγ" "Hγf" as "Hγ"; iDestruct (own_valid with "Hγ !") as %Hvalid.
    assert (s  S) by eauto using sts_auth_frag_valid_inv.
    assert ( sts_frag S T) as [??] by eauto using cmra_valid_op_r.
    iRevert "Hγ"; rewrite sts_op_auth_frag //; iIntros "Hγ".
    iApply pvs_fsa_fsa; iApply fsa_wand_r; iSplitL "HΨ Hφ".
    { iApply "HΨ"; by iSplit. }
    iIntros {a} "H"; iDestruct "H" as {s' T'} "(% & Hφ & HΨ)".
    iPvs (own_update with "Hγ") as "Hγ"; first eauto using sts_update_auth.
    iRevert "Hγ"; rewrite -sts_op_auth_frag_up; iIntros "[Hγ Hγf]".
    iPvsIntro; iSplitL "Hφ Hγ"; last by iApply "HΨ".
    iNext; iExists s'; by iFrame "Hφ".
115 116
  Qed.

117
  Lemma sts_fsa E N (Ψ : V  iPropG Λ Σ) γ s0 T :
Ralf Jung's avatar
Ralf Jung committed
118
    fsaV  nclose N  E 
119 120 121 122 123 124
    (sts_ctx γ N φ  sts_own γ s0 T   s,
       (s  sts.up s0 T)   φ s -
      fsa (E  nclose N) (λ x,  s' T',
         (sts.steps (s, T) (s', T'))   φ s' 
        (sts_own γ s' T' - Ψ x)))
     fsa E Ψ.
125
  Proof. by apply sts_fsaS. Qed.
Ralf Jung's avatar
Ralf Jung committed
126
End sts.