counter_examples.v 7.13 KB
 Robbert Krebbers committed Oct 25, 2016 1 ``````From iris.base_logic Require Import base_logic soundness. `````` Ralf Jung committed Aug 04, 2016 2 ``````From iris.proofmode Require Import tactics. `````` Ralf Jung committed Jan 03, 2017 3 ``````Set Default Proof Using "All". `````` Ralf Jung committed Aug 04, 2016 4 5 `````` (** This proves that we need the ▷ in a "Saved Proposition" construction with `````` Derek Dreyer committed Aug 08, 2016 6 ``````name-dependent allocation. *) `````` Ralf Jung committed Aug 05, 2016 7 ``````Module savedprop. Section savedprop. `````` Ralf Jung committed Aug 04, 2016 8 9 `````` Context (M : ucmraT). Notation iProp := (uPred M). `````` Robbert Krebbers committed Aug 04, 2016 10 11 `````` Notation "¬ P" := (□ (P → False))%I : uPred_scope. Implicit Types P : iProp. `````` Ralf Jung committed Aug 04, 2016 12 `````` `````` Robbert Krebbers committed Oct 25, 2016 13 `````` (** Saved Propositions and the update modality *) `````` Robbert Krebbers committed Aug 05, 2016 14 `````` Context (sprop : Type) (saved : sprop → iProp → iProp). `````` Robbert Krebbers committed Aug 04, 2016 15 `````` Hypothesis sprop_persistent : ∀ i P, PersistentP (saved i P). `````` Ralf Jung committed Aug 04, 2016 16 `````` Hypothesis sprop_alloc_dep : `````` 17 `````` ∀ (P : sprop → iProp), (|==> (∃ i, saved i (P i)))%I. `````` Ralf Jung committed Aug 08, 2016 18 `````` Hypothesis sprop_agree : ∀ i P Q, saved i P ∧ saved i Q ⊢ □ (P ↔ Q). `````` Ralf Jung committed Aug 04, 2016 19 `````` `````` Ralf Jung committed Aug 08, 2016 20 `````` (** A bad recursive reference: "Assertion with name [i] does not hold" *) `````` Robbert Krebbers committed Nov 03, 2016 21 `````` Definition A (i : sprop) : iProp := ∃ P, ¬ P ∗ saved i P. `````` Ralf Jung committed Aug 08, 2016 22 `````` `````` 23 `````` Lemma A_alloc : (|==> ∃ i, saved i (A i))%I. `````` Ralf Jung committed Aug 08, 2016 24 `````` Proof. by apply sprop_alloc_dep. Qed. `````` Ralf Jung committed Aug 04, 2016 25 `````` `````` Ralf Jung committed Aug 08, 2016 26 `````` Lemma saved_NA i : saved i (A i) ⊢ ¬ A i. `````` Ralf Jung committed Aug 04, 2016 27 `````` Proof. `````` Ralf Jung committed Aug 08, 2016 28 29 30 31 32 `````` iIntros "#Hs !# #HA". iPoseProof "HA" as "HA'". iDestruct "HA'" as (P) "[#HNP HsP]". iApply "HNP". iDestruct (sprop_agree i P (A i) with "[]") as "#[_ HP]". { eauto. } iApply "HP". done. `````` Ralf Jung committed Aug 04, 2016 33 34 `````` Qed. `````` Ralf Jung committed Aug 08, 2016 35 `````` Lemma saved_A i : saved i (A i) ⊢ A i. `````` Ralf Jung committed Aug 04, 2016 36 `````` Proof. `````` Ralf Jung committed Aug 08, 2016 37 38 `````` iIntros "#Hs". iExists (A i). iFrame "#". by iApply saved_NA. `````` Ralf Jung committed Aug 04, 2016 39 `````` Qed. `````` Robbert Krebbers committed Aug 05, 2016 40 41 42 `````` Lemma contradiction : False. Proof. `````` Robbert Krebbers committed Oct 25, 2016 43 `````` apply (@soundness M False 1); simpl. `````` Robbert Krebbers committed Oct 25, 2016 44 `````` iIntros "". iMod A_alloc as (i) "#H". `````` Ralf Jung committed Aug 08, 2016 45 `````` iPoseProof (saved_NA with "H") as "HN". `````` Robbert Krebbers committed Oct 25, 2016 46 `````` iModIntro. iNext. `````` Ralf Jung committed Aug 08, 2016 47 `````` iApply "HN". iApply saved_A. done. `````` Robbert Krebbers committed Aug 05, 2016 48 `````` Qed. `````` Ralf Jung committed Aug 08, 2016 49 `````` `````` Ralf Jung committed Aug 05, 2016 50 ``````End savedprop. End savedprop. `````` Ralf Jung committed Aug 05, 2016 51 52 53 `````` (** This proves that we need the ▷ when opening invariants. *) (** We fork in [uPred M] for any M, but the proof would work in any BI. *) `````` Ralf Jung committed Aug 05, 2016 54 ``````Module inv. Section inv. `````` Ralf Jung committed Aug 05, 2016 55 56 57 58 59 `````` Context (M : ucmraT). Notation iProp := (uPred M). Implicit Types P : iProp. (** Assumptions *) `````` Robbert Krebbers committed Oct 25, 2016 60 `````` (** We have the update modality (two classes: empty/full mask) *) `````` Robbert Krebbers committed Aug 05, 2016 61 `````` Inductive mask := M0 | M1. `````` Robbert Krebbers committed Oct 25, 2016 62 `````` Context (fupd : mask → iProp → iProp). `````` Ralf Jung committed Aug 05, 2016 63 `````` `````` Robbert Krebbers committed Oct 25, 2016 64 65 66 `````` Hypothesis fupd_intro : ∀ E P, P ⊢ fupd E P. Hypothesis fupd_mono : ∀ E P Q, (P ⊢ Q) → fupd E P ⊢ fupd E Q. Hypothesis fupd_fupd : ∀ E P, fupd E (fupd E P) ⊢ fupd E P. `````` Robbert Krebbers committed Nov 03, 2016 67 `````` Hypothesis fupd_frame_l : ∀ E P Q, P ∗ fupd E Q ⊢ fupd E (P ∗ Q). `````` Robbert Krebbers committed Oct 25, 2016 68 `````` Hypothesis fupd_mask_mono : ∀ P, fupd M0 P ⊢ fupd M1 P. `````` Ralf Jung committed Aug 05, 2016 69 `````` `````` Robbert Krebbers committed Oct 25, 2016 70 `````` (** We have invariants *) `````` Ralf Jung committed Aug 05, 2016 71 `````` Context (name : Type) (inv : name → iProp → iProp). `````` Robbert Krebbers committed Aug 05, 2016 72 `````` Hypothesis inv_persistent : ∀ i P, PersistentP (inv i P). `````` Robbert Krebbers committed Oct 25, 2016 73 `````` Hypothesis inv_alloc : ∀ P, P ⊢ fupd M1 (∃ i, inv i P). `````` Ralf Jung committed Aug 05, 2016 74 `````` Hypothesis inv_open : `````` Robbert Krebbers committed Nov 03, 2016 75 `````` ∀ i P Q R, (P ∗ Q ⊢ fupd M0 (P ∗ R)) → (inv i P ∗ Q ⊢ fupd M1 R). `````` Ralf Jung committed Aug 05, 2016 76 `````` `````` Ralf Jung committed Aug 05, 2016 77 78 79 `````` (* We have tokens for a little "two-state STS": [start] -> [finish]. state. [start] also asserts the exact state; it is only ever owned by the invariant. [finished] is duplicable. *) `````` Ralf Jung committed Aug 08, 2016 80 81 82 83 84 85 `````` (* Posssible implementations of these axioms: * Using the STS monoid of a two-state STS, where [start] is the authoritative saying the state is exactly [start], and [finish] is the "we are at least in state [finish]" typically owned by threads. * Ex () +_⊥ () *) `````` Ralf Jung committed Aug 05, 2016 86 87 88 `````` Context (gname : Type). Context (start finished : gname → iProp). `````` 89 `````` Hypothesis sts_alloc : fupd M0 (∃ γ, start γ). `````` Robbert Krebbers committed Oct 25, 2016 90 `````` Hypotheses start_finish : ∀ γ, start γ ⊢ fupd M0 (finished γ). `````` Ralf Jung committed Aug 05, 2016 91 `````` `````` Robbert Krebbers committed Nov 03, 2016 92 `````` Hypothesis finished_not_start : ∀ γ, start γ ∗ finished γ ⊢ False. `````` Ralf Jung committed Aug 05, 2016 93 `````` `````` Robbert Krebbers committed Nov 03, 2016 94 `````` Hypothesis finished_dup : ∀ γ, finished γ ⊢ finished γ ∗ finished γ. `````` Ralf Jung committed Aug 05, 2016 95 `````` `````` Robbert Krebbers committed Oct 25, 2016 96 `````` (** We assume that we cannot update to false. *) `````` 97 `````` Hypothesis consistency : ¬ (fupd M1 False). `````` Ralf Jung committed Aug 05, 2016 98 99 `````` (** Some general lemmas and proof mode compatibility. *) `````` Robbert Krebbers committed Nov 03, 2016 100 `````` Lemma inv_open' i P R : inv i P ∗ (P -∗ fupd M0 (P ∗ fupd M1 R)) ⊢ fupd M1 R. `````` Ralf Jung committed Aug 05, 2016 101 `````` Proof. `````` Robbert Krebbers committed Oct 25, 2016 102 `````` iIntros "(#HiP & HP)". iApply fupd_fupd. iApply inv_open; last first. `````` Ralf Jung committed Aug 05, 2016 103 104 105 106 `````` { iSplit; first done. iExact "HP". } iIntros "(HP & HPw)". by iApply "HPw". Qed. `````` Robbert Krebbers committed Oct 25, 2016 107 108 109 `````` Instance fupd_mono' E : Proper ((⊢) ==> (⊢)) (fupd E). Proof. intros P Q ?. by apply fupd_mono. Qed. Instance fupd_proper E : Proper ((⊣⊢) ==> (⊣⊢)) (fupd E). `````` Ralf Jung committed Aug 05, 2016 110 `````` Proof. `````` Robbert Krebbers committed Oct 25, 2016 111 `````` intros P Q; rewrite !uPred.equiv_spec=> -[??]; split; by apply fupd_mono. `````` Ralf Jung committed Aug 05, 2016 112 113 `````` Qed. `````` 114 `````` Lemma fupd_frame_r E P Q : fupd E P ∗ Q ⊢ fupd E (P ∗ Q). `````` Robbert Krebbers committed Oct 25, 2016 115 `````` Proof. by rewrite comm fupd_frame_l comm. Qed. `````` Ralf Jung committed Aug 05, 2016 116 `````` `````` Robbert Krebbers committed Oct 25, 2016 117 118 `````` Global Instance elim_fupd_fupd E P Q : ElimModal (fupd E P) P (fupd E Q) (fupd E Q). Proof. by rewrite /ElimModal fupd_frame_r uPred.wand_elim_r fupd_fupd. Qed. `````` Ralf Jung committed Aug 05, 2016 119 `````` `````` Robbert Krebbers committed Oct 25, 2016 120 `````` Global Instance elim_fupd0_fupd1 P Q : ElimModal (fupd M0 P) P (fupd M1 Q) (fupd M1 Q). `````` Ralf Jung committed Aug 05, 2016 121 `````` Proof. `````` Robbert Krebbers committed Oct 25, 2016 122 `````` by rewrite /ElimModal fupd_frame_r uPred.wand_elim_r fupd_mask_mono fupd_fupd. `````` Ralf Jung committed Aug 05, 2016 123 124 `````` Qed. `````` Robbert Krebbers committed Oct 25, 2016 125 126 `````` Global Instance exists_split_fupd0 {A} E P (Φ : A → iProp) : FromExist P Φ → FromExist (fupd E P) (λ a, fupd E (Φ a)). `````` Ralf Jung committed Aug 05, 2016 127 128 `````` Proof. rewrite /FromExist=>HP. apply uPred.exist_elim=> a. `````` Robbert Krebbers committed Oct 25, 2016 129 `````` apply fupd_mono. by rewrite -HP -(uPred.exist_intro a). `````` Ralf Jung committed Aug 05, 2016 130 131 `````` Qed. `````` Derek Dreyer committed Aug 08, 2016 132 `````` (** Now to the actual counterexample. We start with a weird form of saved propositions. *) `````` Ralf Jung committed Aug 05, 2016 133 `````` Definition saved (γ : gname) (P : iProp) : iProp := `````` Robbert Krebbers committed Nov 03, 2016 134 `````` ∃ i, inv i (start γ ∨ (finished γ ∗ □ P)). `````` Robbert Krebbers committed Aug 05, 2016 135 `````` Global Instance saved_persistent γ P : PersistentP (saved γ P) := _. `````` Ralf Jung committed Aug 05, 2016 136 `````` `````` 137 `````` Lemma saved_alloc (P : gname → iProp) : fupd M1 (∃ γ, saved γ (P γ)). `````` Ralf Jung committed Aug 05, 2016 138 `````` Proof. `````` Robbert Krebbers committed Oct 25, 2016 139 `````` iIntros "". iMod (sts_alloc) as (γ) "Hs". `````` Robbert Krebbers committed Nov 03, 2016 140 `````` iMod (inv_alloc (start γ ∨ (finished γ ∗ □ (P γ))) with "[Hs]") as (i) "#Hi". `````` Robbert Krebbers committed Aug 05, 2016 141 `````` { auto. } `````` Robbert Krebbers committed Oct 25, 2016 142 `````` iApply fupd_intro. by iExists γ, i. `````` Ralf Jung committed Aug 05, 2016 143 144 `````` Qed. `````` Robbert Krebbers committed Nov 03, 2016 145 `````` Lemma saved_cast γ P Q : saved γ P ∗ saved γ Q ∗ □ P ⊢ fupd M1 (□ Q). `````` Ralf Jung committed Aug 05, 2016 146 `````` Proof. `````` Ralf Jung committed Aug 05, 2016 147 `````` iIntros "(#HsP & #HsQ & #HP)". iDestruct "HsP" as (i) "HiP". `````` Ralf Jung committed Aug 05, 2016 148 `````` iApply (inv_open' i). iSplit; first done. `````` Robbert Krebbers committed Oct 25, 2016 149 `````` iIntros "HaP". iAssert (fupd M0 (finished γ)) with "[HaP]" as "> Hf". `````` Ralf Jung committed Aug 05, 2016 150 151 `````` { iDestruct "HaP" as "[Hs | [Hf _]]". - by iApply start_finish. `````` Robbert Krebbers committed Oct 25, 2016 152 `````` - by iApply fupd_intro. } `````` Robbert Krebbers committed Aug 08, 2016 153 `````` iDestruct (finished_dup with "Hf") as "[Hf Hf']". `````` Robbert Krebbers committed Oct 25, 2016 154 `````` iApply fupd_intro. iSplitL "Hf'"; first by eauto. `````` Ralf Jung committed Aug 05, 2016 155 `````` (* Step 2: Open the Q-invariant. *) `````` Robbert Krebbers committed Sep 27, 2016 156 `````` iClear (i) "HiP ". iDestruct "HsQ" as (i) "HiQ". `````` Ralf Jung committed Aug 05, 2016 157 158 `````` iApply (inv_open' i). iSplit; first done. iIntros "[HaQ | [_ #HQ]]". `````` Robbert Krebbers committed Aug 05, 2016 159 `````` { iExFalso. iApply finished_not_start. by iFrame. } `````` Robbert Krebbers committed Oct 25, 2016 160 `````` iApply fupd_intro. iSplitL "Hf". `````` Robbert Krebbers committed Aug 05, 2016 161 `````` { iRight. by iFrame. } `````` Robbert Krebbers committed Oct 25, 2016 162 `````` by iApply fupd_intro. `````` Ralf Jung committed Aug 05, 2016 163 164 `````` Qed. `````` Ralf Jung committed Aug 05, 2016 165 `````` (** And now we tie a bad knot. *) `````` Robbert Krebbers committed Nov 03, 2016 166 167 `````` Notation "¬ P" := (□ (P -∗ fupd M1 False))%I : uPred_scope. Definition A i : iProp := ∃ P, ¬P ∗ saved i P. `````` Robbert Krebbers committed Aug 05, 2016 168 `````` Global Instance A_persistent i : PersistentP (A i) := _. `````` Ralf Jung committed Aug 05, 2016 169 `````` `````` 170 `````` Lemma A_alloc : fupd M1 (∃ i, saved i (A i)). `````` Ralf Jung committed Aug 05, 2016 171 `````` Proof. by apply saved_alloc. Qed. `````` Ralf Jung committed Aug 05, 2016 172 `````` `````` Ralf Jung committed Aug 08, 2016 173 `````` Lemma saved_NA i : saved i (A i) ⊢ ¬A i. `````` Ralf Jung committed Aug 05, 2016 174 `````` Proof. `````` Ralf Jung committed Aug 05, 2016 175 176 `````` iIntros "#Hi !# #HA". iPoseProof "HA" as "HA'". iDestruct "HA'" as (P) "#[HNP Hi']". `````` Robbert Krebbers committed Oct 25, 2016 177 `````` iMod (saved_cast i (A i) P with "[]") as "HP". `````` Ralf Jung committed Aug 08, 2016 178 `````` { eauto. } `````` Ralf Jung committed Aug 05, 2016 179 `````` by iApply "HNP". `````` Ralf Jung committed Aug 05, 2016 180 `````` Qed. `````` Ralf Jung committed Aug 05, 2016 181 `````` `````` Ralf Jung committed Aug 08, 2016 182 `````` Lemma saved_A i : saved i (A i) ⊢ A i. `````` Ralf Jung committed Aug 05, 2016 183 `````` Proof. `````` Ralf Jung committed Aug 08, 2016 184 185 `````` iIntros "#Hi". iExists (A i). iFrame "#". by iApply saved_NA. `````` Ralf Jung committed Aug 05, 2016 186 `````` Qed. `````` Ralf Jung committed Aug 05, 2016 187 `````` `````` Ralf Jung committed Aug 05, 2016 188 189 `````` Lemma contradiction : False. Proof. `````` Ralf Jung committed Oct 07, 2016 190 `````` apply consistency. iIntros "". `````` Robbert Krebbers committed Oct 25, 2016 191 `````` iMod A_alloc as (i) "#H". `````` Ralf Jung committed Aug 08, 2016 192 193 `````` iPoseProof (saved_NA with "H") as "HN". iApply "HN". iApply saved_A. done. `````` Ralf Jung committed Aug 05, 2016 194 195 `````` Qed. End inv. End inv.``````