sts.v 6.78 KB
 Robbert Krebbers committed Mar 10, 2016 1 2 ``````From iris.algebra Require Export sts upred_tactics. From iris.program_logic Require Export invariants ghost_ownership. `````` Ralf Jung committed Feb 15, 2016 3 4 ``````Import uPred. `````` Ralf Jung committed Mar 06, 2016 5 ``````(** The CMRA we need. *) `````` Robbert Krebbers committed Feb 17, 2016 6 ``````Class stsG Λ Σ (sts : stsT) := StsG { `````` Robbert Krebbers committed Mar 01, 2016 7 `````` sts_inG :> inG Λ Σ (stsR sts); `````` Robbert Krebbers committed Feb 16, 2016 8 `````` sts_inhabited :> Inhabited (sts.state sts); `````` Ralf Jung committed Feb 15, 2016 9 ``````}. `````` Robbert Krebbers committed Feb 17, 2016 10 ``````Coercion sts_inG : stsG >-> inG. `````` Ralf Jung committed Mar 06, 2016 11 ``````(** The Functor we need. *) `````` Ralf Jung committed Mar 07, 2016 12 ``````Definition stsGF (sts : stsT) : gFunctor := GFunctor (constRF (stsR sts)). `````` Ralf Jung committed Mar 06, 2016 13 ``````(* Show and register that they match. *) `````` Ralf Jung committed Feb 23, 2016 14 ``````Instance inGF_stsG sts `{inGF Λ Σ (stsGF sts)} `````` Robbert Krebbers committed Feb 22, 2016 15 16 `````` `{Inhabited (sts.state sts)} : stsG Λ Σ sts. Proof. split; try apply _. apply: inGF_inG. Qed. `````` Ralf Jung committed Feb 22, 2016 17 `````` `````` Ralf Jung committed Mar 06, 2016 18 19 20 21 22 23 24 25 26 27 ``````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 committed Feb 24, 2016 28 `````` `````` Ralf Jung committed Mar 06, 2016 29 30 31 32 33 34 `````` 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. `````` Ralf Jung committed Mar 10, 2016 35 `````` Global Instance sts_ownS_proper : Proper ((≡) ==> (≡) ==> (⊣⊢)) sts_ownS. `````` Ralf Jung committed Mar 06, 2016 36 `````` Proof. solve_proper. Qed. `````` Ralf Jung committed Mar 10, 2016 37 `````` Global Instance sts_own_proper s : Proper ((≡) ==> (⊣⊢)) (sts_own s). `````` Ralf Jung committed Mar 06, 2016 38 39 40 41 42 `````` 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 : `````` Ralf Jung committed Mar 10, 2016 43 `````` Proper (pointwise_relation _ (≡) ==> (⊣⊢)) (sts_ctx N). `````` Ralf Jung committed Mar 06, 2016 44 `````` Proof. solve_proper. Qed. `````` Robbert Krebbers committed Mar 15, 2016 45 `````` Global Instance sts_ctx_persistent N φ : PersistentP (sts_ctx N φ). `````` Ralf Jung committed Mar 06, 2016 46 47 48 `````` Proof. apply _. Qed. End definitions. Typeclasses Opaque sts_own sts_ownS sts_ctx. `````` Robbert Krebbers committed Feb 17, 2016 49 50 51 52 ``````Instance: Params (@sts_inv) 5. Instance: Params (@sts_ownS) 5. Instance: Params (@sts_own) 6. Instance: Params (@sts_ctx) 6. `````` Ralf Jung committed Feb 15, 2016 53 54 `````` Section sts. `````` Robbert Krebbers committed Feb 17, 2016 55 `````` Context `{stsG Λ Σ sts} (φ : sts.state sts → iPropG Λ Σ). `````` Ralf Jung committed Feb 15, 2016 56 57 58 `````` Implicit Types N : namespace. Implicit Types P Q R : iPropG Λ Σ. Implicit Types γ : gname. `````` Robbert Krebbers committed Feb 16, 2016 59 60 61 `````` Implicit Types S : sts.states sts. Implicit Types T : sts.tokens sts. `````` Ralf Jung committed Feb 15, 2016 62 63 `````` (* The same rule as implication does *not* hold, as could be shown using sts_frag_included. *) `````` Ralf Jung committed Feb 17, 2016 64 `````` Lemma sts_ownS_weaken E γ S1 S2 T1 T2 : `````` 65 `````` T2 ⊆ T1 → S1 ⊆ S2 → sts.closed S2 T2 → `````` Ralf Jung committed Mar 10, 2016 66 `````` sts_ownS γ S1 T1 ⊢ (|={E}=> sts_ownS γ S2 T2). `````` Ralf Jung committed Feb 25, 2016 67 `````` Proof. intros ? ? ?. by apply own_update, sts_update_frag. Qed. `````` Ralf Jung committed Feb 15, 2016 68 `````` `````` Ralf Jung committed Feb 17, 2016 69 `````` Lemma sts_own_weaken E γ s S T1 T2 : `````` 70 `````` T2 ⊆ T1 → s ∈ S → sts.closed S T2 → `````` Ralf Jung committed Mar 10, 2016 71 `````` sts_own γ s T1 ⊢ (|={E}=> sts_ownS γ S T2). `````` Ralf Jung committed Feb 25, 2016 72 `````` Proof. intros ???. by apply own_update, sts_update_frag_up. Qed. `````` Ralf Jung committed Feb 15, 2016 73 `````` `````` Ralf Jung committed Feb 17, 2016 74 `````` Lemma sts_ownS_op γ S1 S2 T1 T2 : `````` Robbert Krebbers committed Mar 23, 2016 75 `````` T1 ⊥ T2 → sts.closed S1 T1 → sts.closed S2 T2 → `````` Ralf Jung committed Mar 10, 2016 76 `````` sts_ownS γ (S1 ∩ S2) (T1 ∪ T2) ⊣⊢ (sts_ownS γ S1 T1 ★ sts_ownS γ S2 T2). `````` Ralf Jung committed Feb 25, 2016 77 `````` Proof. intros. by rewrite /sts_ownS -own_op sts_op_frag. Qed. `````` Ralf Jung committed Feb 17, 2016 78 `````` `````` Ralf Jung committed Feb 17, 2016 79 80 `````` Lemma sts_alloc E N s : nclose N ⊆ E → `````` Ralf Jung committed Mar 10, 2016 81 `````` ▷ φ s ⊢ (|={E}=> ∃ γ, sts_ctx γ N φ ∧ sts_own γ s (⊤ ∖ sts.tok s)). `````` Ralf Jung committed Feb 15, 2016 82 `````` Proof. `````` Ralf Jung committed Feb 17, 2016 83 `````` intros HN. eapply sep_elim_True_r. `````` Ralf Jung committed Mar 05, 2016 84 `````` { apply (own_alloc (sts_auth s (⊤ ∖ sts.tok s)) E). `````` Robbert Krebbers committed Feb 17, 2016 85 `````` apply sts_auth_valid; set_solver. } `````` Ralf Jung committed Mar 05, 2016 86 `````` rewrite pvs_frame_l. apply pvs_strip_pvs. `````` Ralf Jung committed Feb 15, 2016 87 `````` rewrite sep_exist_l. apply exist_elim=>γ. rewrite -(exist_intro γ). `````` Ralf Jung committed Feb 20, 2016 88 `````` trans (▷ sts_inv γ φ ★ sts_own γ s (⊤ ∖ sts.tok s))%I. `````` Ralf Jung committed Feb 17, 2016 89 `````` { rewrite /sts_inv -(exist_intro s) later_sep. `````` Ralf Jung committed Feb 25, 2016 90 `````` ecancel [▷ φ _]%I. `````` Robbert Krebbers committed Feb 17, 2016 91 `````` by rewrite -later_intro -own_op sts_op_auth_frag_up; last set_solver. } `````` Ralf Jung committed Mar 05, 2016 92 `````` rewrite (inv_alloc N E) // /sts_ctx pvs_frame_r. `````` Ralf Jung committed Feb 15, 2016 93 94 95 `````` by rewrite always_and_sep_l. Qed. `````` Robbert Krebbers committed Feb 16, 2016 96 `````` Lemma sts_opened E γ S T : `````` Robbert Krebbers committed Feb 17, 2016 97 `````` (▷ sts_inv γ φ ★ sts_ownS γ S T) `````` Ralf Jung committed Mar 10, 2016 98 `````` ⊢ (|={E}=> ∃ s, ■ (s ∈ S) ★ ▷ φ s ★ own γ (sts_auth s T)). `````` Ralf Jung committed Feb 15, 2016 99 `````` Proof. `````` Ralf Jung committed Feb 25, 2016 100 `````` rewrite /sts_inv later_exist sep_exist_r. apply exist_elim=>s. `````` Ralf Jung committed Feb 15, 2016 101 `````` rewrite later_sep pvs_timeless !pvs_frame_r. apply pvs_mono. `````` Ralf Jung committed Mar 05, 2016 102 103 104 `````` rewrite -(exist_intro s). ecancel [▷ φ _]%I. rewrite -own_op own_valid_l discrete_valid. apply const_elim_sep_l=> Hvalid. `````` Robbert Krebbers committed Feb 24, 2016 105 `````` assert (s ∈ S) by eauto using sts_auth_frag_valid_inv. `````` Ralf Jung committed Mar 05, 2016 106 `````` rewrite const_equiv // left_id sts_op_auth_frag //. `````` Robbert Krebbers committed Feb 24, 2016 107 `````` by assert (✓ sts_frag S T) as [??] by eauto using cmra_valid_op_r. `````` Ralf Jung committed Feb 15, 2016 108 109 `````` Qed. `````` Robbert Krebbers committed Feb 16, 2016 110 `````` Lemma sts_closing E γ s T s' T' : `````` Ralf Jung committed Feb 20, 2016 111 `````` sts.steps (s, T) (s', T') → `````` Ralf Jung committed Mar 10, 2016 112 `````` (▷ φ s' ★ own γ (sts_auth s T)) ⊢ (|={E}=> ▷ sts_inv γ φ ★ sts_own γ s' T'). `````` Ralf Jung committed Feb 15, 2016 113 `````` Proof. `````` Ralf Jung committed Feb 25, 2016 114 `````` intros Hstep. rewrite /sts_inv -(exist_intro s') later_sep. `````` Ralf Jung committed Feb 23, 2016 115 `````` (* TODO it would be really nice to use cancel here *) `````` 116 `````` rewrite [(_ ★ ▷ φ _)%I]comm -assoc. `````` Robbert Krebbers committed Feb 16, 2016 117 `````` rewrite -pvs_frame_l. apply sep_mono_r. rewrite -later_intro. `````` Robbert Krebbers committed Feb 24, 2016 118 `````` rewrite own_valid_l discrete_valid. apply const_elim_sep_l=>Hval. `````` Ralf Jung committed Feb 20, 2016 119 `````` trans (|={E}=> own γ (sts_auth s' T'))%I. `````` Robbert Krebbers committed Feb 16, 2016 120 `````` { by apply own_update, sts_update_auth. } `````` Ralf Jung committed Feb 20, 2016 121 `````` by rewrite -own_op sts_op_auth_frag_up. `````` Ralf Jung committed Feb 15, 2016 122 `````` Qed. `````` Ralf Jung committed Feb 15, 2016 123 `````` `````` Ralf Jung committed Feb 15, 2016 124 125 `````` Context {V} (fsa : FSA Λ (globalF Σ) V) `{!FrameShiftAssertion fsaV fsa}. `````` Robbert Krebbers committed Feb 18, 2016 126 `````` Lemma sts_fsaS E N P (Ψ : V → iPropG Λ Σ) γ S T : `````` Ralf Jung committed Feb 15, 2016 127 `````` fsaV → nclose N ⊆ E → `````` Ralf Jung committed Mar 10, 2016 128 129 `````` P ⊢ sts_ctx γ N φ → P ⊢ (sts_ownS γ S T ★ ∀ s, `````` Ralf Jung committed Feb 15, 2016 130 `````` ■ (s ∈ S) ★ ▷ φ s -★ `````` Ralf Jung committed Feb 15, 2016 131 `````` fsa (E ∖ nclose N) (λ x, ∃ s' T', `````` Ralf Jung committed Feb 20, 2016 132 `````` ■ sts.steps (s, T) (s', T') ★ ▷ φ s' ★ `````` Robbert Krebbers committed Feb 18, 2016 133 `````` (sts_own γ s' T' -★ Ψ x))) → `````` Ralf Jung committed Mar 10, 2016 134 `````` P ⊢ fsa E Ψ. `````` Ralf Jung committed Feb 15, 2016 135 `````` Proof. `````` Robbert Krebbers committed Feb 16, 2016 136 `````` rewrite /sts_ctx=>? HN Hinv Hinner. `````` Ralf Jung committed Feb 15, 2016 137 138 `````` eapply (inv_fsa fsa); eauto. rewrite Hinner=>{Hinner Hinv P HN}. apply wand_intro_l. rewrite assoc. `````` Robbert Krebbers committed Feb 16, 2016 139 `````` rewrite (sts_opened (E ∖ N)) !pvs_frame_r !sep_exist_r. `````` Ralf Jung committed Feb 15, 2016 140 141 `````` apply (fsa_strip_pvs fsa). apply exist_elim=>s. rewrite (forall_elim s). rewrite [(▷_ ★ _)%I]comm. `````` Ralf Jung committed Feb 20, 2016 142 143 144 `````` eapply wand_apply_r; first (by eapply (wand_frame_l (own γ _))); last first. { rewrite assoc [(_ ★ own _ _)%I]comm -assoc. done. } rewrite fsa_frame_l. `````` Ralf Jung committed Feb 15, 2016 145 `````` apply (fsa_mono_pvs fsa)=> x. `````` Ralf Jung committed Feb 15, 2016 146 `````` rewrite sep_exist_l; apply exist_elim=> s'. `````` Ralf Jung committed Feb 15, 2016 147 148 `````` rewrite sep_exist_l; apply exist_elim=>T'. rewrite comm -!assoc. apply const_elim_sep_l=>-Hstep. `````` Ralf Jung committed Feb 15, 2016 149 `````` rewrite assoc [(_ ★ (_ -★ _))%I]comm -assoc. `````` Robbert Krebbers committed Feb 16, 2016 150 `````` rewrite (sts_closing (E ∖ N)) //; []. `````` Ralf Jung committed Feb 15, 2016 151 152 153 154 `````` rewrite pvs_frame_l. apply pvs_mono. by rewrite assoc [(_ ★ ▷_)%I]comm -assoc wand_elim_l. Qed. `````` Robbert Krebbers committed Feb 18, 2016 155 `````` Lemma sts_fsa E N P (Ψ : V → iPropG Λ Σ) γ s0 T : `````` Ralf Jung committed Feb 15, 2016 156 `````` fsaV → nclose N ⊆ E → `````` Ralf Jung committed Mar 10, 2016 157 158 `````` P ⊢ sts_ctx γ N φ → P ⊢ (sts_own γ s0 T ★ ∀ s, `````` Robbert Krebbers committed Feb 16, 2016 159 `````` ■ (s ∈ sts.up s0 T) ★ ▷ φ s -★ `````` Ralf Jung committed Feb 15, 2016 160 `````` fsa (E ∖ nclose N) (λ x, ∃ s' T', `````` Ralf Jung committed Feb 20, 2016 161 `````` ■ (sts.steps (s, T) (s', T')) ★ ▷ φ s' ★ `````` Robbert Krebbers committed Feb 18, 2016 162 `````` (sts_own γ s' T' -★ Ψ x))) → `````` Ralf Jung committed Mar 10, 2016 163 `````` P ⊢ fsa E Ψ. `````` Ralf Jung committed Feb 25, 2016 164 `````` Proof. by apply sts_fsaS. Qed. `````` Ralf Jung committed Feb 15, 2016 165 ``End sts.``