-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathor_lost.v
More file actions
208 lines (177 loc) · 7.24 KB
/
Copy pathor_lost.v
File metadata and controls
208 lines (177 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
From iris.bi Require Import fractional.
From Perennial.Helpers Require Import ipm NamedProps.
From self Require Import extra ipm_tactics.
From self.base Require Import primitive_laws wpr_lifting.
From self.high Require Import dprop dprop_liftings monpred_simpl.
Set Default Proof Using "Type".
Section or_lost_post_crash.
Context `{nvmBaseFixedG Σ, nvmBaseDeltaG}.
Definition or_lost_post_crash ℓ (P : nat → iProp Σ) :=
(∃ (CV : view),
crashed_at CV ∗
((∃ t, ⌜CV !! ℓ = Some (MaxNat t)⌝ ∗ persisted_loc ℓ 0 ∗ P t)
∨ ⌜CV !! ℓ = None⌝))%I.
Global Instance or_lost_post_crash_proper ℓ :
Proper (pointwise_relation _ (⊣⊢) ==> (⊣⊢)) (or_lost_post_crash ℓ).
Proof. solve_proper. Qed.
Definition or_lost_post_crash_no_t ℓ (P : iProp Σ) :=
or_lost_post_crash ℓ (λ _, P).
Global Instance or_lost_post_crash_no_t_proper ℓ :
Proper ((⊣⊢) ==> (⊣⊢)) (or_lost_post_crash_no_t ℓ).
Proof. solve_proper. Qed.
End or_lost_post_crash.
Section or_lost_with_t.
Context `{nvmBaseFixedG Σ}.
(* A [dProp] version of [or_lost_post_crash]. *)
Definition or_lost_with_t ℓ (P : time → dProp Σ) : dProp Σ :=
∃ CV,
crashed_at_d CV ∗
((∃ t, ⌜CV !! ℓ = Some (MaxNat t)⌝ ∗ persisted_loc_d ℓ 0 ∗ P t) ∨
⌜ CV !! ℓ = None ⌝).
Global Instance or_lost_with_t_proper ℓ :
Proper (pointwise_relation _ (⊣⊢) ==> (⊣⊢)) (or_lost_with_t ℓ).
Proof. solve_proper. Qed.
(* The predicate [P] holds for [ℓ] or [ℓ] has been lost. *)
Definition or_lost ℓ (P : dProp Σ) : dProp Σ :=
or_lost_with_t ℓ (λ _, P).
Global Instance or_lost_proper ℓ :
Proper ((⊣⊢) ==> (⊣⊢)) (or_lost ℓ).
Proof. solve_proper. Qed.
Lemma or_lost_post_crash_lookup `{nvmBaseDeltaG} (CV : view) ℓ t P :
CV !! ℓ = Some (MaxNat t) →
crashed_at CV -∗
or_lost_post_crash ℓ P -∗
P t.
Proof.
iIntros (look) "crash".
iIntros "(% & crash' & [l|%])";
iDestruct (crashed_at_agree with "crash crash'") as %<-;
last congruence.
iDestruct "l" as (t' eq) "(per & P)".
by simplify_eq.
Qed.
(* Lemma or_lost_post_crash_no_t_lookup (CV : view) ℓ t P : *)
(* CV !! ℓ = Some (MaxNat t) → *)
(* crashed_at CV -∗ *)
(* or_lost_post_crash_no_t ℓ P -∗ *)
(* P. *)
(* Proof. apply or_lost_post_crash_lookup. Qed. *)
Lemma or_lost_post_crash_sep `{nvmBaseDeltaG} ℓ P Q :
or_lost_post_crash ℓ (λ t, P t ∗ Q t) ⊣⊢
or_lost_post_crash ℓ (λ t, P t) ∗ or_lost_post_crash ℓ (λ t, Q t).
Proof.
iSplit.
- iDestruct 1 as (?) "(#CV & [(%t & %look & #per & P & Q)|%look])".
* iSplitL "P"; iExists _; iFrame "CV"; iLeft; naive_solver.
* iSplitL; iExists _; naive_solver.
- iIntros "[(%CV & cr1 & [(%t1 & %look1 & #per & P)|%look1])
(%CV' & cr2 & [(%t2 & %look2 & #? & Q)|%look2])]";
iDestruct (crashed_at_agree with "cr1 cr2") as %eq;
simplify_eq.
* iExists _. iFrame. iLeft. iExists _. iFrame "∗#%".
* iExists _. iFrame. iRight. done.
Qed.
Lemma or_lost_post_crash_mono `{nvmBaseDeltaG} ℓ P Q :
(∀ t CV,
("#per" ∷ persisted_loc ℓ 0 ∗
"#crashed" ∷ crashed_at CV ∗
"%cvLook" ∷ ⌜ CV !! ℓ = Some (MaxNat t) ⌝) -∗ P t -∗ Q t) -∗
or_lost_post_crash ℓ P -∗ or_lost_post_crash ℓ Q.
Proof.
iIntros "pToQ (%CV & #crashed & disj)".
iExists CV. iFrame "crashed". iDestruct "disj" as "[(% & % & #per & P) | %lost]".
- iLeft. iExists _. iFrame "#". iSplitPure; first done.
iApply ("pToQ" with "[$per $crashed //] P").
- iRight. iFrame (lost).
Qed.
Global Instance or_lost_post_crash_fractional `{nvmBaseDeltaG} ℓ P :
(∀ t, Fractional (P t)) →
Fractional (λ q, or_lost_post_crash ℓ (λ t, P t q)).
Proof.
intros F q p.
rewrite -or_lost_post_crash_sep.
setoid_rewrite fractional.
done.
Qed.
(* Lemma or_lost_to_with_t ℓ P : or_lost ℓ P ⊣⊢ or_lost_with_t ℓ (λ _, P). *)
(* Proof. rewrite /or_lost. done. Qed. *)
Lemma or_lost_with_t_at ℓ (P : _ → dProp Σ) TV gnames :
or_lost_post_crash ℓ (λ t, P t (TV, gnames)) -∗
(or_lost_with_t ℓ P) (TV, gnames).
Proof.
iDestruct 1 as (CV) "[crash disj]".
iExists _.
simpl.
setoid_rewrite monPred_at_embed.
iFrame "crash disj".
Qed.
Lemma or_lost_with_t_sep ℓ (P Q : _ → dProp Σ) :
or_lost_with_t ℓ P ∗ or_lost_with_t ℓ Q ⊣⊢ or_lost_with_t ℓ (λ t, P t ∗ Q t)%I.
Proof.
iSplit.
- iIntros "[(%CV & crash & MP) (%CV' & crash' & MQ)]".
iDestruct (crashed_at_d_agree with "crash crash'") as %<-.
iExists CV. iFrame.
iDestruct "MP" as "[(% & % & #per & P)|%]"; iDestruct "MQ" as "[(% & % & #? & Q)|%]";
try (by iRight).
simplify_eq.
iLeft. iExists _. iFrame "∗#". done.
- iIntros "(%CV & #crash & [(% & % & #per & [P Q])|%])".
* iSplitL "P".
+ iExists CV. iFrame "#". iLeft. iExists _. iFrame. done.
+ iExists CV. iFrame "#". iLeft. iExists _. iFrame. done.
* iSplitL; iExists CV; iFrame "#%".
Qed.
Lemma or_lost_sep ℓ (P Q : dProp Σ) :
or_lost ℓ P ∗ or_lost ℓ Q ⊣⊢ or_lost ℓ (P ∗ Q)%I.
Proof. rewrite /or_lost. apply or_lost_with_t_sep. Qed.
Lemma or_lost_with_t_mono_strong ℓ (P Q : _ → dProp Σ) :
(∀ t CV,
("%look" ∷ ⌜ CV !! ℓ = Some (MaxNat t) ⌝ ∗
"#per" ∷ persisted_loc_d ℓ 0 ∗
"#crashed" ∷ crashed_at_d CV) -∗
P t -∗ Q t) -∗
or_lost_with_t ℓ P -∗ or_lost_with_t ℓ Q.
Proof.
iIntros "pToQ (%CV & #crashed & disj)".
iExists CV. iFrame "crashed". iDestruct "disj" as "[(% & % & #per & P) | %lost]".
- iLeft. iExists _. iFrame "#%". (* iSplitPure; first done. *)
iApply ("pToQ" with "[] P"). iFrame "#%".
- iRight. iFrame (lost).
Qed.
Lemma or_lost_with_t_mono ℓ (P Q : _ → dProp Σ) :
(∀ t, P t -∗ Q t) -∗ or_lost_with_t ℓ P -∗ or_lost_with_t ℓ Q.
Proof.
iIntros "pToQ".
iApply (or_lost_with_t_mono_strong).
iIntros (??) "_". iApply "pToQ".
Qed.
Lemma or_lost_mono ℓ (P Q : dProp Σ) :
(P -∗ Q) -∗ or_lost ℓ P -∗ or_lost ℓ Q.
Proof. iIntros "I". iApply or_lost_with_t_mono. iIntros (_). done. Qed.
Lemma or_lost_embed ℓ P TV gnames :
or_lost_post_crash_no_t ℓ P -∗ or_lost ℓ ⎡ P ⎤ (TV, gnames).
Proof.
iDestruct 1 as (CV) "[crash disj]". iExists _.
simpl. setoid_rewrite monPred_at_embed.
iFrame "crash". done.
Qed.
Lemma or_lost_get CV ℓ P :
is_Some (CV !! ℓ) → crashed_at_d CV -∗ or_lost ℓ P -∗ P.
Proof.
iIntros ([[t] look]) "crash (%CV' & crash' & [(% & ? & #per & $)|%look'])".
iDestruct (crashed_at_d_agree with "crash crash'") as %<-.
congruence.
Qed.
Lemma or_lost_with_t_get CV ℓ t P :
CV !! ℓ = Some (MaxNat t) → crashed_at_d CV -∗ or_lost_with_t ℓ P -∗ P t.
Proof.
rewrite /or_lost_with_t.
iIntros (look) "crash (%CV' & crash' & [(%t' & %look' & #per & P)|%look'])";
iDestruct (crashed_at_d_agree with "crash crash'") as %<-.
- simplify_eq. iFrame "P".
- congruence.
Qed.
End or_lost_with_t.
Opaque or_lost_with_t.
Opaque or_lost_post_crash.