-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdurable_ms_queue.v
More file actions
661 lines (597 loc) · 19.5 KB
/
Copy pathdurable_ms_queue.v
File metadata and controls
661 lines (597 loc) · 19.5 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
(* This in an implementation of a durable variant of the fine-grained concurrent
Michael-Scott queue. *)
From iris.bi Require Import lib.fractional.
From iris.proofmode Require Import tactics.
From iris.bi.lib Require Export fixpoint.
From self.base Require Import primitive_laws.
From self.lang Require Import lang.
From self.high Require Import dprop.
From self.lang Require Import notation lang.
From self.algebra Require Import view.
From self.base Require Import primitive_laws class_instances.
From self.high Require Import proofmode wpc_proofmode if_rec.
From self.high Require Import dprop abstract_state_instances modalities
resources crash_weakestpre weakestpre weakestpre_na weakestpre_at
recovery_weakestpre lifted_modalities protocol protocols no_buffer mapsto_na_flushed.
From self.high.modalities Require Import fence.
(* Implementation. *)
Section implementation.
Notation NONE := (InjL #()).
Definition MS_nilv := NONEV.
Definition MS_consv x nOut : val := SOMEV ((SOMEV x), nOut).
Definition MS_nil := NONE.
Definition MS_cons x nOut := SOME ((SOME x), nOut).
Definition getValue : val :=
λ: "x", match: "x" with
NONE => assert #false (* rec: "spin" <> := "spin" #() *)
| SOME "v" => "v"
end.
Definition mk_MS_queue : expr :=
λ: <>,
let: "nilNode" := ref_AT NONE in
Flush "nilNode" ;;
Fence ;;
let: "toNil" := ref_AT "nilNode" in
Flush "toNil" ;;
Fence ;;
let: "node" := ref_AT (SOME (NONE, "toNil")) in
Flush "node" ;;
Fence ;;
let: "toSent" := ref_AT "node" in
let: "toTail" := ref_AT "node" in
Flush "toSent" ;;
Flush "toTail" ;;
Fence ;;
("toSent", "toTail").
Definition MS_dequeue : expr :=
rec: "try" "queue" :=
let: "toSent" := Fst "queue" in
let: "sent" := !_AT "toSent" in
let: "cont" := getValue (!_AT "sent") in
let: "next" := !_AT (Snd "cont") in
match: !_AT "next" with
NONE => NONE
| SOME "n'" =>
Fence ;;
if: CAS "toSent" "sent" "next"
then SOME (getValue (Fst ("n'")))
else "try" "queue"
end.
Definition MS_enqueue : val :=
λ: "queue" "x",
let: "toTail" := Snd "queue" in
let: "nilNode" := ref_AT MS_nil in
Flush "nilNode" ;;
Fence ;;
let: "toNil" := ref_AT "nilNode" in
Flush "toNil" ;;
Fence ;;
let: "node" := ref_AT (MS_cons "x" "toNil") in
Flush "node" ;;
Fence ;;
let: "tail" := !_AT "toTail" in
(rec: "try" "c" :=
let: "t" := !_AT "c" in
match: !_AT "t" with
NONE =>
(* The tail is nil, we can try to insert *)
if: (CAS "c" "t" "node")
then (* Insertion succeeded, update to tail pointer *)
(* CAS "toTail" "tail" "node" ;; #() *)
"toTail" <-_AT "node" ;; #()
else (* Insertion failed, we try again*)
"try" "c"
| SOME "c'" => "try" (Snd "c'")
end
) (Snd (getValue !_AT "tail")).
End implementation.
Section definitions.
Implicit Types (ℓ : loc).
Context `{nvmG Σ}.
(* We assume a per-element predicate. *)
Context (R : val → dProp Σ).
(* The per-element predicate must be stable under the <PCF> modality and not
use anything from the buffer. *)
Context `{∀ a, IntoCrashFlush (R a) (R a),
∀ a, BufferFree (R a)}.
(* A nil node is never mutated so we use a constant protocol to represent
it. *)
Definition nil_node_prot := constant_prot (InjLV #()).
(* The invariant for the location out of a node. *)
Definition toNext_prot_inv (next_inv : loc_predO bool) :
loc_predO unit :=
(λ ml v, ∃ (ℓ : loc),
⌜ v = #ℓ ⌝ ∗
((* No successor *)
ℓ ↦_AT^{nil_node_prot} [()] ∗
flush_lb ℓ (nil_node_prot) ()
∨
ℓ ↦_AT^{MkProt next_inv id} [true] ∗
flush_lb ℓ (MkProt next_inv id) true))%I.
Global Instance toNext_prot_inv_ne :
NonExpansive toNext_prot_inv.
Proof.
rewrite /toNext_prot_inv.
intros ??????.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
- rewrite /mapsto_at.
f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv.
f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv.
f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv.
rewrite /know_protocol.
f_equiv; last done.
simpl.
f_equiv.
rewrite /know_pred_d.
f_equiv.
intros ?? ->.
f_equiv.
assumption.
- rewrite /flush_lb.
f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv.
rewrite /lb_base.
f_equiv.
rewrite /know_protocol.
f_equiv.
f_equiv; last done.
f_equiv.
rewrite /know_pred_d.
f_equiv.
intros ?? ->.
f_equiv.
simpl.
assumption.
Qed.
Definition toNext_prot (next_inv : loc_pred bool) :=
MkProt (toNext_prot_inv next_inv) id.
(* The invariant for the location into a node. *)
Definition pre_node_prot_inv :
(loc_predO bool) -d> loc_predO bool :=
λ self b v,
(∃ (ℓtoNext : loc) mx state,
⌜ v = (InjRV (mx, #ℓtoNext)) ⌝ ∗
match b with
(* Is initial sentinel. *)
false => True
(* Is not a sentinel node. *)
| true => ∃ x, ⌜ mx = SOMEV x ⌝ ∗ R x
end ∗
ℓtoNext ↦_AT^{toNext_prot self} [state] ∗
flush_lb ℓtoNext (toNext_prot self) state)%I.
Global Instance pre_node_prot_inv_contractive :
Contractive pre_node_prot_inv.
Proof.
rewrite /pre_node_prot_inv.
intros ??????.
rewrite /pre_node_prot_inv.
simpl.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
f_equiv.
- rewrite /toNext_prot.
apply mapsto_at_contractive.
destruct n. { apply dist_later_0. }
apply dist_later_S in H2.
apply dist_later_S.
rewrite H2.
done.
- rewrite /flush_lb.
f_equiv. f_equiv. f_equiv. f_equiv. f_equiv. f_equiv.
rewrite /lb_base.
f_equiv.
rewrite /know_protocol.
f_equiv.
f_equiv; last done.
f_equiv.
rewrite /know_pred_d.
f_equiv.
intros ?? ->.
f_contractive.
simpl.
f_equiv.
assumption.
Qed.
Definition node_prot_inv := fixpoint pre_node_prot_inv.
Lemma node_prot_inv_unfold :
node_prot_inv ≡ pre_node_prot_inv (node_prot_inv).
Proof. rewrite /node_prot_inv. apply fixpoint_unfold. Qed.
Instance if_else_persistent {PROP : bi} (b : bool) (P Q : PROP) :
Persistent P →
Persistent Q →
Persistent (if b then P else Q).
Proof. intros ??. destruct b; done. Qed.
Global Instance node_prot_inv_persistent `{∀ v, Persistent (R v)} s v :
Persistent (node_prot_inv s v).
Proof.
rewrite /Persistent.
(* iLöb as "IH" forall (ℓtoNext s v). *)
rewrite /node_prot_inv.
rewrite (fixpoint_unfold (pre_node_prot_inv) s v).
iDestruct 1 as (???) "(-> & #HR & #prot & #lb)".
iModIntro.
repeat iExists _.
iSplitPure; first done.
iFrame "#".
Qed.
Global Instance toNext_prot_inv_persistent s v :
Persistent (toNext_prot_inv (node_prot_inv) s v).
Proof. apply _. Qed.
Definition cons_node_prot : LocationProtocol bool :=
{| p_inv := node_prot_inv;
p_bumper := id |}.
Global Instance cons_node_prot_conditions :
ProtocolConditions cons_node_prot.
Proof.
split; try apply _.
- intros ??. simpl.
rewrite /node_prot_inv (fixpoint_unfold (pre_node_prot_inv) s v).
apply _.
- iLöb as "IH".
iIntros (??) "nodeProt".
simpl.
rewrite /node_prot_inv.
rewrite (fixpoint_unfold (pre_node_prot_inv) s v).
iDestruct "nodeProt" as (???) "(-> & HR & prot & lb)".
iModIntro.
simpl.
iDestruct "lb" as "(persLb & (%state' & #incl & #crashedIn))".
iExists _, mx, state'.
iSplitPure; first done.
iFrameF "HR".
iDestruct (crashed_in_if_rec with "crashedIn prot")
as (?) "(crashedIn2 & toNextPts)".
iDestruct (crashed_in_agree with "crashedIn crashedIn2") as %<-.
iFrame "toNextPts".
iApply persist_lb_to_flush_lb.
iApply (crashed_in_persist_lb with "crashedIn").
Qed.
Global Instance toNext_prot_conditions :
ProtocolConditions (toNext_prot node_prot_inv).
Proof.
split; try apply _.
iIntros ([] ?) "(% & -> & [(B & C) | (B & C)]) /=";
iCrashIntro.
* iExists _.
iSplitPure; first done.
iDestruct "C" as "[? (% & le & #crashedIn)]".
iDestruct (crashed_in_if_rec with "crashedIn B") as ([]) "[crashedIn2 pts]".
iLeft.
iFrame "pts".
iApply persist_lb_to_flush_lb.
iFrame.
* iExists _.
iSplitPure; first done.
iDestruct "C" as "[? (% & %le & #crashedIn)]".
inversion le.
iDestruct (crashed_in_if_rec with "crashedIn B") as (b) "[crashedIn2 pts]".
iDestruct (crashed_in_agree with "crashedIn crashedIn2") as %<-.
iRight.
iFrame "pts".
iApply persist_lb_to_flush_lb.
iFrame.
Qed.
Definition toSent_prot :=
{| p_inv := λ (_ : unit) v, (∃ (ℓsent : loc) sb,
⌜ v = #ℓsent ⌝ ∗
ℓsent ↦_AT^{cons_node_prot} [sb] ∗
flush_lb ℓsent (cons_node_prot) sb)%I;
p_bumper v := v |}.
Global Instance toSent_prot_conditions :
ProtocolConditions toSent_prot.
Proof.
split; try apply _.
iIntros (??).
iDestruct 1 as (??) "(A & B & C)".
iModIntro.
iDestruct "C" as "(HI & (% & % & #crashedIn1))".
iDestruct (crashed_in_if_rec with "crashedIn1 B") as (?) "(crashedIn2 & sentPts)".
iDestruct (crashed_in_agree with "crashedIn1 crashedIn2") as %<-.
iExists _, s__pc.
iFrameF "A".
simpl.
iFrameF "sentPts".
iApply persist_lb_to_flush_lb.
iApply (crashed_in_persist_lb with "crashedIn1").
Qed.
(* The tail pointer might point to the sentinel, so in general what it points
to satisfies the exact same invariant as the sentinel pointer. *)
Definition toTail_prot := toSent_prot.
(* The representation predicate for the MS queue. *)
Definition is_queue (queue : val) : dProp Σ :=
∃ (ℓtoS ℓtoT : loc),
⌜ queue = (#ℓtoS, #ℓtoT)%V ⌝ ∗
(* ℓtoS *)
ℓtoS ↦_AT^{toSent_prot} [()] ∗
flush_lb ℓtoS toSent_prot () ∗
(* ℓtoT *)
ℓtoT ↦_AT^{toTail_prot} [()] ∗
flush_lb ℓtoS toSent_prot ().
End definitions.
Section specification.
Context `{nvmG Σ}.
(* We assume a per-element predicate. *)
Context (R : val → dProp Σ).
(* The per-element predicate must be stable under the <PCF> modality and not
{ use anything from the buffer. *)
Context `{∀ a, IntoCrashFlush (R a) (R a),
∀ a, BufferFree (R a),
∀ a, Persistent (R a)}.
Lemma wp_mk_queue s E :
{{{ True }}}
mk_MS_queue #() @ s ; E
{{{ qv, RET qv; is_queue R qv }}}.
Proof.
iIntros (Φ) "_ Φpost".
rewrite /mk_MS_queue.
wp_pures.
(* Allocate nil node. *)
wp_apply (wp_alloc_at _ () nil_node_prot); first done.
iIntros (ℓnil) "#nilPts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "nilPts"). simpl.
iIntros "(_ & #nilFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
(* Allocate next pointer to nil node. *)
wp_apply (wp_alloc_at _ ()
(toNext_prot (node_prot_inv R))).
{ iExists _.
iSplitPure; first done.
iLeft. iFrame "nilPts nilFlushLb". }
iIntros (ℓtoNext) "#toNextPts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "toNextPts"). simpl.
iIntros "(_ & #toNextFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
wp_apply (wp_alloc_at _ false (cons_node_prot R)).
{ rewrite /= (node_prot_inv_unfold _ _ _).
repeat iExists _.
iSplitPure; first done.
rewrite left_id.
iFrame "toNextPts".
iFrame "toNextFlushLb". }
iIntros (ℓsent) "#sentPts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "sentPts"). simpl.
iIntros "(_ & #sentFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
wp_apply (wp_alloc_at _ () (toSent_prot R)).
{ repeat iExists _. iFrame "#". done. }
iIntros (ℓtoS) "#toSPts".
wp_pures.
wp_apply (wp_alloc_at _ () (toTail_prot R)).
{ repeat iExists _. iFrame "#". done. }
iIntros (ℓtoT) "#toTPts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "toSPts").
iIntros "(_ & #toSFlushLb & _)".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "toTPts").
iIntros "(_ & #toTFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
iModIntro.
iApply "Φpost".
repeat iExists _.
iSplitPure; first done.
iFrame "toSPts toTPts #".
Qed.
Lemma post_fence_or (P Q : dProp Σ) :
<fence> (P ∨ Q) ⊣⊢ <fence> P ∨ <fence> Q.
Proof. iModel. rewrite 2!post_fence_at monPred_at_or. naive_solver. Qed.
Global Instance into_or_into_fence (P Q1 Q2 : dProp Σ) :
IntoOr P Q1 Q2 →
IntoOr (<fence> P) (<fence> Q1) (<fence> Q2).
Proof. rewrite /IntoOr=>->. rewrite post_fence_or. done. Qed.
Lemma wp_dequeue queue s E :
{{{ is_queue R queue }}}
MS_dequeue queue @ s ; E
{{{ v, RET v;
(⌜ v = NONEV ⌝) ∨ (∃ x, ⌜ v = InjRV x ⌝ ∗ R x) }}}.
Proof.
iIntros (Φ) "(%ℓtoS & %_ & -> & toSPts & _) Φpost".
rewrite /MS_dequeue.
wp_pure1.
iLöb as "IH".
wp_pures.
(* Load of sentinel pointer. *)
wp_apply (wp_load_at_simple_pers with "toSPts").
iIntros ([] v) "(_ & #toSPts & inv)".
iDestruct "inv" as (ℓsent sb) "(>-> & >sentPts & sentFlushLb)".
wp_pures.
(* Load of the pointer into the sentinel's content. *)
wp_apply (wp_load_at_simple_pers with "sentPts").
iIntros (?sb ?v) "(_ & sentPts & nodeInv)".
simpl. rewrite (node_prot_inv_unfold _ _ _).
iDestruct "nodeInv" as (??? ->) "(_ & >toNextPts & nodeInv)".
rewrite {6}/getValue.
wp_pures.
(* Load the pointer out of the sentinel. *)
wp_apply (wp_load_at_simple_pers with "toNextPts").
iIntros (??) "(_ & toNextPts & toNextInv)".
rewrite /= /toNext_prot_inv.
wp_pures.
iDestruct "toNextInv" as (?) "(>-> & [(>nextPts & flushLb)|(>nextPts & flushLb)])".
- (* nil node *)
wp_apply (wp_load_at_simple_pers with "nextPts").
iIntros ([] ?) "(? & nextPts & ><-) /=".
wp_pures.
iModIntro.
iApply "Φpost".
iLeft. done.
- (* cons node *)
wp_apply (wp_load_at_simple_pers with "nextPts").
iIntros (??) "(%le & nextPts & nextInv) /=".
inversion le.
rewrite (node_prot_inv_unfold R _ _).
rewrite /pre_node_prot_inv.
iDestruct "nextInv" as (? mx' ?) "(>-> & HR & >toNextPts' & ?)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
wp_apply
(wp_cas_at (λ _, True)%I (λ _, True)%I True _ (toSent_prot R) []
_ _ _ (λ _, True)%I with "[-HR Φpost]").
{ iFrameF "toSPts".
iIntros ([] ? ?).
rewrite 3!right_id.
iSplitL "".
{ iIntros "_". iLeft. done. }
iSplit; last first.
{ iModIntro. iIntros "$". }
iSplitPure; first done.
iSplitL ""; first naive_solver.
iSplitL "". { iModIntro. iIntros "$". }
iIntros "_".
repeat iExists _.
iSplitPure; first done.
iFrameF "nextPts".
iFrame "flushLb". }
iIntros (? []) "[(-> & H)|(-> & H)]".
* wp_pures.
iDestruct "HR" as (? ->) "R".
rewrite /getValue.
wp_pures.
iModIntro.
iApply "Φpost".
iRight.
iExists _. iFrame "R". done.
* wp_pure1.
iApply ("IH" with "toSPts").
iApply "Φpost".
Qed.
Lemma wpc_enqueue queue x s E :
{{{ is_queue R queue ∗ R x }}}
MS_enqueue queue x @ s ; E
{{{ RET #(); True }}}.
Proof.
iIntros (Φ) "[(%_ & %ℓtoT & -> & _ & _ & toTPts & _) HR] Φpost".
rewrite /MS_enqueue.
wp_pures.
(* Allocate nil node. *)
wp_apply (wp_alloc_at _ () nil_node_prot); first done.
iIntros (ℓnil) "#nilPts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "nilPts"). simpl.
iIntros "(_ & #nilFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
(* Allocate next pointer to nil node. *)
wp_apply (wp_alloc_at _ () (toNext_prot (node_prot_inv R))).
{ iExists _.
iSplitPure; first done.
iLeft. iFrame "nilPts nilFlushLb". }
iIntros (ℓtoNext) "#toNextPts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "toNextPts"). simpl.
iIntros "(_ & #toNextFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
wp_apply (wp_alloc_at _ true (cons_node_prot R) with "[HR]").
{ rewrite /= (node_prot_inv_unfold _ _ _).
repeat iExists _.
iSplitPure; first done.
iSplitL "HR". { iExists x. iFrame "HR". done. }
iFrame "toNextPts".
iFrame "toNextFlushLb". }
iIntros (ℓnode) "#nodePts".
wp_pures.
wp_apply (wp_flush_at _ _ [] with "nodePts"). simpl.
iIntros "(_ & #nodeFlushLb & _)".
wp_pures.
wp_apply wp_fence.
do 2 iModIntro.
wp_pures.
wp_apply (wp_load_at_simple_pers with "toTPts").
iIntros ([] v) "(_ & #toTPts & inv)".
iDestruct "inv" as (ℓtail sb) "(>-> & >tailPts & _)".
wp_pures.
wp_apply (wp_load_at_simple_pers with "tailPts").
iIntros (? ?) "(_ & #tailPts & inv)".
rewrite /= (node_prot_inv_unfold R _ _).
iDestruct "inv" as (ℓtoNext2 ? []) "(>-> & _ & >toNextPts2 & _)".
rewrite /getValue.
do 6 wp_pure1.
iLöb as "IH" forall (ℓtoNext2).
wp_pures.
wp_apply (wp_load_at_simple_pers with "toNextPts2").
iIntros ([] ?) "(%le & nextPts & toNextInv) /=".
wp_pures.
iDestruct "toNextInv" as
(?) "(>-> & [(>nil2pts & flushLb)|(>toNextPts2 & flushLb)])".
- (* nil node *)
wp_apply (wp_load_at_simple_pers with "nil2pts").
iIntros ([] ?) "(? & ? & ><-) /=".
wp_pures.
wp_apply
(wp_cas_at (λ _, True)%I (λ _, True)%I True _ _ []
_ _ _ (λ _, True)%I with "[-Φpost]").
{ iFrameF "nextPts".
iIntros (?? incl).
iSplitL "".
{ iIntros "_". iLeft. done. }
rewrite !right_id.
iSplit; last first.
{ iModIntro. iIntros "$". }
iSplitPure; first done.
iSplitL "". { iIntros. done. }
iSplitL "". { iIntros "!> $". }
iIntros "_". simpl.
repeat iExists _.
iSplitPure; first done.
iRight. iFrame "nodePts nodeFlushLb". }
iIntros (? []) "[(-> & H) | (-> & _ & pts & Hi)]".
* wp_pures.
wp_apply (wp_store_at ℓtoT (toTail_prot R) [] () ()).
{ iFrameF "toTPts".
iSplitL "".
{ repeat iExists _. iSplitPure; first done.
iFrame "nodePts nodeFlushLb". }
iSplitPure; first done.
iIntros. done. }
iIntros "_".
wp_pures.
iModIntro.
iApply "Φpost".
done.
* wp_pure1.
iApply ("IH" with "Φpost pts").
- wp_apply (wp_load_at_simple_pers with "toNextPts2").
iIntros (??) "(_ & ? & toNextInv)".
rewrite /= (node_prot_inv_unfold _ _ _).
iDestruct "toNextInv" as (?? []) "(>-> & _ & >pts & H)".
wp_pure1.
wp_pure1.
wp_pure1.
wp_pure1.
iApply ("IH" with "Φpost pts").
Unshelve.
* apply ().
* apply toNext_prot_conditions.
Qed.
End specification.