-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproof_cldeque.v
1368 lines (1270 loc) · 57.3 KB
/
proof_cldeque.v
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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From iris.algebra Require Import list excl_auth.
From iris.bi Require Import derived_laws_later.
From iris.bi.lib Require Import fractional.
From iris.base_logic.lib Require Import invariants.
From smr Require Import ghost_var mono_list mono_nat atomic.
From smr.lang Require Import proofmode notation.
From iris.prelude Require Import options.
From smr.hazptr Require Import spec_cldeque code_cldeque.
From smr Require Import helpers hazptr.spec_hazptr.
Local Ltac extended_auto :=
eauto;
try rewrite Nat2Z.id;
try rewrite length_replicate;
try rewrite Qp.half_half;
repeat rewrite Loc.add_0; repeat rewrite Loc.add_assoc;
try by (
repeat iNext; repeat iIntros; repeat intros;
try case_decide; try iPureIntro;
try rewrite lookup_lt_is_Some;
try lia; done
).
Local Ltac fr :=
repeat iIntros; repeat iSplit; extended_auto;
repeat iIntros; repeat iExists _;
try iFrame "arr↦"; try iFrame "arr↦1"; try iFrame "arr↦2";
iFrame; eauto.
(** Ghost state for the deque *)
Class cldequeG Σ := CLDequeG {
(* spec *)
#[local] deque_tokG :: inG Σ (excl_authR $ listO valO);
(* info: era, arrptr, C, bot, popping *)
#[local] deque_infoG :: ghost_varG Σ (nat * blk * list val * nat * bool * gname);
(* RA *)
#[local] topbotG :: mono_natG Σ;
#[local] topeltG :: mono_listG val Σ;
#[local] roomG :: mono_listG (gname * gname * nat) Σ;
#[local] museumG :: mono_listG (list val * nat * nat) Σ;
(* SMR *)
#[local] smrG :: ghost_varG Σ (list val);
#[local] lengthG :: ghost_varG Σ nat
}.
Definition cldequeΣ : gFunctors :=
#[ (*invariant *)
GFunctor (excl_authR $ listO valO);
ghost_varΣ (nat * blk * list val * nat * bool * gname);
(* RA *)
mono_natΣ;
mono_listΣ val;
mono_listΣ (gname * gname * nat);
mono_listΣ (list val * nat * nat);
(* SMR *)
ghost_varΣ (list val);
ghost_varΣ nat
].
Global Instance subG_cldequeΣ {Σ} : subG cldequeΣ Σ → cldequeG Σ.
Proof. solve_inG. Qed.
Section dqst.
Context `{!heapGS Σ, !cldequeG Σ}.
Notation iProp := (iProp Σ).
Definition dqst_gnames : Type := gname*gname*gname*gname.
Definition top_bot_state (t b : nat) : nat :=
2*t + (if bool_decide (t < b) then 1 else 0).
Definition dqst_frag (γdqst : dqst_gnames) (era : nat)
(γhp : gname) (l : list val) (t b : nat) : iProp :=
let (γ' , γmus) := γdqst in
let (γ'' , γroom) := γ' in
let (γtb, γelt) := γ'' in
∃ (γtbe : gname),
⌜1 ≤ t ≤ b ∧ b < t + length l ∧ length l ≠ 0⌝ ∗
(* top-bot profile *)
( mono_nat_lb_own γtb (top_bot_state t b) ∗
mono_nat_lb_own γtbe (top_bot_state t b)
) ∗
(* top element preservation *)
( ∃ (elts : list val),
mono_list_lb_own γelt elts ∗
⌜t = b ∨ mod_get l t = elts !! t⌝
) ∗
(* museum of past gnames and circles *)
( ∃ (room : list (gname * gname * nat)),
⌜room !! era = Some (γtbe, γhp, length l)⌝ ∗
mono_list_lb_own γroom room
).
Definition dqst_archived (γdqst : dqst_gnames) (era : nat)
(γhp : gname) (l : list val) (t b : nat) : iProp :=
let (γ' , γmus) := γdqst in
let (γ'' , γroom) := γ' in
let (γtb, γelt) := γ'' in
∃ (γtbe : gname),
⌜1 ≤ t ≤ b ∧ b < t + length l ∧ length l ≠ 0⌝ ∗
(* top-bot profile *)
( mono_nat_lb_own γtb (top_bot_state t b) ∗
mono_nat_persistent γtbe (top_bot_state t b)
) ∗
(* top element preservation *)
( ∃ (elts : list val),
mono_list_lb_own γelt elts ∗
⌜t = b ∨ mod_get l t = elts !! t⌝
) ∗
(* museum of past gnames and circles *)
( ∃ (room : list (gname * gname * nat))
(museum : list (list val * nat * nat)),
⌜room !! era = Some (γtbe, γhp, length l)⌝ ∗
⌜museum !! era = Some (l, t, b)⌝ ∗
mono_list_lb_own γroom room ∗
mono_list_lb_own γmus museum
) ∗
(* persistent circle *)
persistent_ghost_var γhp l.
Definition dqst_auth (γdqst : dqst_gnames) (era : nat)
(γhp : gname) (l : list val) (t b : nat) : iProp :=
let (γ' , γmus) := γdqst in
let (γ'' , γroom) := γ' in
let (γtb, γelt) := γ'' in
∃ (γtbe : gname),
⌜1 ≤ t ≤ b ∧ b < t + length l ∧ length l ≠ 0⌝ ∗
(* top-bot profile *)
(mono_nat_auth_own γtb 1 (top_bot_state t b) ∗
mono_nat_auth_own γtbe 1 (top_bot_state t b)
) ∗
(* top element preservation *)
(∃ (elts : list val),
mono_list_auth_own γelt 1 elts ∗
⌜if (bool_decide (t = b))
then length elts = t
else (length elts = S t ∧ mod_get l t = elts !! t)⌝
) ∗
(* museum of past gnames and circles *)
( ∃ (proom : list (gname * gname * nat))
(museum : list (list val * nat * nat)),
⌜length proom = era ∧ length museum = era⌝ ∗
mono_list_auth_own γroom 1 (proom ++ [(γtbe, γhp, length l)]) ∗
mono_list_auth_own γmus 1 museum ∗
[∗ list] i ↦ gne ; ltbi ∈ proom ; museum, (
dqst_archived γdqst i (gne.1.2) (ltbi.1.1) (ltbi.1.2) (ltbi.2)
)
).
(* Timeless & Persistent *)
Ltac desγ H :=
destruct H as (((γtb, γelt), γroom), γmuseum).
Global Instance dqst_frag_timeless γdqst era γhp l t b :
Timeless (dqst_frag γdqst era γhp l t b).
Proof. desγ γdqst. apply _. Qed.
Global Instance dqst_frag_persistent γdqst era γhp l t b :
Persistent (dqst_frag γdqst era γhp l t b).
Proof. desγ γdqst. apply _. Qed.
Global Instance dqst_archived_timeless γdqst era γhp l t b :
Timeless (dqst_archived γdqst era γhp l t b).
Proof. desγ γdqst. apply _. Qed.
Global Instance dqst_archived_persistent γdqst era γhp l t b :
Persistent (dqst_archived γdqst era γhp l t b).
Proof. desγ γdqst. apply _. Qed.
Global Instance dqst_auth_timeless γdqst era γhp l t b :
Timeless (dqst_auth γdqst era γhp l t b).
Proof. desγ γdqst. apply _. Qed.
Lemma top_bot_state_le t1 b1 t2 b2 :
top_bot_state t1 b1 ≤ top_bot_state t2 b2 ↔
t1 ≤ t2 ∧ (t1 = t2 ∧ t1 < b1 → t2 < b2).
Proof. unfold top_bot_state. do 2 case_bool_decide; lia. Qed.
Lemma dqst_auth_alloc γhp l :
length l ≠ 0 →
⊢ |==> ∃ (γdqst : dqst_gnames),
dqst_auth γdqst 0 γhp l 1 1.
Proof.
intros Hl. unfold dqst_auth.
iMod (mono_nat_own_alloc 2) as (γtb) "[tb _]".
iMod (mono_nat_own_alloc 2) as (γtbe) "[tbe _]".
iMod (mono_list_own_alloc ([NONEV])) as (γelt) "[topelt _]".
iMod (mono_list_own_alloc ([(γtbe, γhp, length l)])) as (γroom) "[room _]".
iMod (mono_list_own_alloc ([] : list (list val * nat * nat))) as (γmus) "[museum _]".
iExists (γtb, γelt, γroom, γmus).
iModIntro. fr. fr.
iSplit; fr.
Qed.
Lemma dqst_frag_agree γdqst era γhp1 l1 t1 b1 γhp2 l2 t2 b2 :
dqst_frag γdqst era γhp1 l1 t1 b1 -∗
dqst_frag γdqst era γhp2 l2 t2 b2 -∗
⌜γhp1 = γhp2 ∧ length l1 = length l2⌝.
Proof.
desγ γdqst.
iIntros "F1 F2".
iDestruct "F1" as (γtbe1) "(%Hlt1 & tb1 & elt1 & muse1)".
iDestruct "muse1" as (room1) "[%Hroom1 Lb1]".
iDestruct "F2" as (γtbe2) "(%Hlt2 & tb2 & elt2 & muse2)".
iDestruct "muse2" as (room2) "[%Hroom2 Lb2]".
iDestruct (mono_list_lb_valid with "Lb1 Lb2") as "[%Pref|%Pref]".
- eapply prefix_lookup_Some in Hroom1; eauto.
rewrite Hroom2 in Hroom1. by injection Hroom1.
- eapply prefix_lookup_Some in Hroom2; eauto.
rewrite Hroom2 in Hroom1. by injection Hroom1.
Qed.
Lemma dqst_get_frag γdqst era γhp l t b :
dqst_auth γdqst era γhp l t b -∗
dqst_frag γdqst era γhp l t b.
Proof with extended_auto.
desγ γdqst.
iIntros "Auth".
iDestruct "Auth" as (γtbeO) "(%HltO & [tbO tbeO] & eltO & museO)".
iDestruct "eltO" as (elts) "[Elt %Heltslen]".
iDestruct "museO" as (room museum) "museO".
iDestruct "museO" as "([%Hroomlen %Hmuslen] & museO)".
iDestruct "museO" as "(Room & Museum & Archives)".
iDestruct (mono_nat_lb_own_get with "tbO") as "#lb".
iDestruct (mono_nat_lb_own_get with "tbeO") as "#lbe".
iDestruct (mono_list_lb_own_get with "Elt") as "#eltlb".
iDestruct (mono_list_lb_own_get with "Room") as "#rlb".
fr. fr.
- fr. case_bool_decide; [iLeft|iRight]... destruct Heltslen...
- fr. rewrite lookup_app_r... replace (era - length room) with 0...
Qed.
Lemma dqst_get_archived γdqst era1 γhp1 l1 t1 b1
era2 γhp2 l2 t2 b2 :
(* era1 is later than era2 *)
era1 ≠ era2 →
dqst_auth γdqst era1 γhp1 l1 t1 b1 -∗
dqst_frag γdqst era2 γhp2 l2 t2 b2 -∗
∃ l' t' b', dqst_archived γdqst era2 γhp2 l' t' b'.
Proof with extended_auto.
desγ γdqst.
iIntros (Hneq) "Auth F".
iDestruct "Auth" as (γtbeO) "(%HltO & tbO & eltO & museO)".
iDestruct "museO" as (room museum) "museO".
iDestruct "museO" as "([%Hroomlen %Hmuslen] & museO)".
iDestruct "museO" as "(Room & Museum & Archives)".
iDestruct "F" as (γtbe) "(%Hlt & tb & elt & muse)".
iDestruct "muse" as (room') "[%Hroom'2 Lb']".
iDestruct (mono_list_auth_lb_valid with "Room Lb'") as "%Pref".
destruct Pref as [_ Pref].
eapply prefix_lookup_Some in Hroom'2; eauto.
assert (era2 < era1) as Hera21.
{ apply lookup_lt_Some in Hroom'2.
rewrite length_app Hroomlen in Hroom'2. simpl in Hroom'2... }
assert (is_Some (museum !! era2)) as [ltbera2 Hltbera2].
{ rewrite lookup_lt_is_Some... }
rewrite lookup_app_l in Hroom'2...
iDestruct (big_sepL2_lookup with "Archives") as "Arch2"...
Qed.
Lemma dqst_get_lb γdqst era1 γhp1 l1 t1 b1
era2 γhp2 l2 t2 b2 :
(* era1 is later than era2 *)
dqst_auth γdqst era1 γhp1 l1 t1 b1 -∗
dqst_frag γdqst era2 γhp2 l2 t2 b2 -∗
⌜t2 ≤ t1 ∧ (
(t2 = t1 ∧ t2 < b2) →
(t1 < b1 ∧ mod_get l2 t2 = mod_get l1 t1)
)⌝.
Proof with extended_auto.
desγ γdqst.
iIntros "Auth F".
iDestruct "Auth" as (γtbeO) "(%HltO & [tbO tbeO] & eltO & museO)".
iDestruct "F" as (γtbe) "(%Hlt & [tb tbe] & elt & muse)".
iDestruct (mono_nat_lb_own_valid with "tbO tb") as "[_ %Htb]".
apply top_bot_state_le in Htb as [Ht21 Htb21]. fr.
iIntros ([H1 Ht1b2]). subst t2. assert (t1 < b1) as Htb1... fr.
iDestruct "elt" as (elts') "[lb %Helts]"...
destruct Helts as [NO|Helts]...
iDestruct "eltO" as (elts) "[Elts %Heltslen]".
iDestruct (mono_list_auth_lb_lookup t1 with "Elts lb") as "%Heqg"...
{ rewrite -lookup_lt_is_Some -Helts. apply mod_get_is_Some... }
iDestruct (mono_list_auth_lb_valid with "Elts lb") as "[_ %Pref]".
case_bool_decide... destruct Heltslen as [_ Hget].
rewrite Hget Helts...
Qed.
Lemma dqst_archived_get_array γdqst era γhp l t b :
dqst_archived γdqst era γhp l t b -∗
persistent_ghost_var γhp l.
Proof.
desγ γdqst.
iIntros "Arc".
by iDestruct "Arc" as (γtbeA) "(_&_&_&_& pers)".
Qed.
Lemma dqst_archived_get_frag γdqst era γhp l t b :
dqst_archived γdqst era γhp l t b -∗
dqst_frag γdqst era γhp l t b.
Proof.
desγ γdqst.
iIntros "Arc".
iDestruct "Arc" as (γtbeA) "(%Hlt & [tb tbe] & elt & muse & pers)".
iDestruct "muse" as (room museum) "(%Hroom & Hmuseum & Room & Museum)".
fr. fr. by iApply mono_nat_persistent_lb_own_get.
Qed.
Lemma dqst_archived_get_lb γdqst era γhp l1 t1 b1 l2 t2 b2 :
dqst_archived γdqst era γhp l1 t1 b1 -∗
dqst_frag γdqst era γhp l2 t2 b2 -∗
⌜t2 ≤ t1 ∧ (
(t2 = t1 ∧ t2 < b2) →
(t1 < b1 ∧ mod_get l2 t2 = mod_get l1 t1)
)⌝.
Proof with extended_auto.
desγ γdqst.
iIntros "Arc F".
iDestruct "Arc" as (γtbeA) "(%Hlt1 & [tb1 tbe1] & elt1 & muse1 & pers1)".
iDestruct "muse1" as (room1 museum1) "muse1".
iDestruct "muse1" as "(%Hroom1 & %Hmuse1 & Lbroom1 & Lbmuse1)".
iDestruct "F" as (γtbe) "(%Hlt2 & [tb2 tbe2] & elt2 & muse2)".
iDestruct "muse2" as (room2) "[%Hroom2 Lbroom2]".
iDestruct (mono_list_lb_lookup era with "Lbroom1 Lbroom2") as "%Hr12".
{ apply lookup_lt_Some in Hroom1... }
{ apply lookup_lt_Some in Hroom2... }
rewrite Hroom1 Hroom2 in Hr12. injection Hr12 as [= <-].
iDestruct (mono_nat_persistent_lb_own_valid with "tbe1 tbe2") as "%Htb2".
apply top_bot_state_le in Htb2 as [Hlt21 Htb2].
fr. iIntros ([<- Hlt]). clear Hlt21.
assert (t2 < b1) as Hlt21...
iSplit...
iDestruct "elt1" as (elts1) "[lb1 [%NO|%Hget1]]"...
iDestruct "elt2" as (elts2) "[lb2 [%NO|%Hget2]]"...
rewrite Hget1 Hget2.
iApply (mono_list_lb_lookup with "lb2 lb1").
- rewrite -lookup_lt_is_Some -Hget2. apply mod_get_is_Some...
- rewrite -lookup_lt_is_Some -Hget1. apply mod_get_is_Some...
Qed.
Lemma dqst_auth_write_bot v γdqst era γhp l t b :
dqst_auth γdqst era γhp l t b -∗
dqst_auth γdqst era γhp (mod_set l b v) t b.
Proof.
desγ γdqst.
iIntros "Auth".
iDestruct "Auth" as (γtbeO) "(%HltO & tbO & eltO & museO)".
iDestruct "eltO" as (elts) "[Elts %Heltslen]".
unfold dqst_auth. rewrite mod_set_length. fr.
fr. case_bool_decide; auto. rewrite mod_set_get_ne; auto.
apply neq_symm, close_mod_neq; lia.
Qed.
Lemma dqst_auth_update γdqst era γhp l t b :
t < b →
dqst_auth γdqst era γhp l t b ==∗
dqst_auth γdqst era γhp l (S t) b.
Proof with extended_auto.
desγ γdqst.
iIntros (Hlt) "Auth".
iDestruct "Auth" as (γtbeO) "(%HltO & [tbO tbeO] & eltO & museO)".
iDestruct "eltO" as (elts) "[Elts %Heltslen]".
iMod (mono_nat_own_update (top_bot_state (S t) b)
with "tbO") as "[tbO _]".
{ unfold top_bot_state. do 2 case_bool_decide... }
iMod (mono_nat_own_update (top_bot_state (S t) b)
with "tbeO") as "[tbeO _]".
{ unfold top_bot_state. do 2 case_bool_decide... }
destruct (decide (S t = b)).
{ iModIntro. fr. fr. do 2 case_bool_decide... }
destruct (mod_get_is_Some l (S t)) as [v Hv]...
iMod (mono_list_auth_own_update_app [v] with "Elts") as "[Elts _]".
iModIntro. fr. fr. do 2 case_bool_decide...
rewrite length_app lookup_app_r; simpl...
replace (S t - length elts) with 0; simpl... fr.
Qed.
Lemma dqst_auth_push γdqst era γhp l t b :
S b < t + length l →
dqst_auth γdqst era γhp l t b ==∗
dqst_auth γdqst era γhp l t (S b).
Proof with extended_auto.
desγ γdqst.
iIntros (Hlt) "Auth".
iDestruct "Auth" as (γtbeO) "(%HltO & [tbO tbeO] & eltO & museO)".
iDestruct "eltO" as (elts) "[Elts %Heltslen]".
iMod (mono_nat_own_update (top_bot_state t (S b))
with "tbO") as "[tbO _]".
{ unfold top_bot_state. do 2 case_bool_decide... }
iMod (mono_nat_own_update (top_bot_state t (S b))
with "tbeO") as "[tbeO _]".
{ unfold top_bot_state. do 2 case_bool_decide... }
case_bool_decide; last first.
{ iModIntro. fr. fr. }
destruct (mod_get_is_Some l t) as [v Hv]...
iMod (mono_list_auth_own_update_app [v] with "Elts") as "[Elts _]".
iModIntro. fr. fr. case_bool_decide...
rewrite length_app lookup_app_r; simpl...
replace (t - length elts) with 0; simpl... fr.
Qed.
Lemma dqst_auth_pop γdqst era γhp l t b :
t < b - 1 →
dqst_auth γdqst era γhp l t b ==∗
dqst_auth γdqst era γhp l t (b - 1).
Proof with extended_auto.
desγ γdqst.
iIntros (Hlt) "Auth".
iDestruct "Auth" as (γtbeO) "(%HltO & [tbO tbeO] & eltO & museO)".
iDestruct "eltO" as (elts) "[Elts %Heltslen]".
replace (top_bot_state t b) with (top_bot_state t (b-1)).
2: unfold top_bot_state; repeat case_bool_decide...
iModIntro. fr. fr. case_bool_decide...
Qed.
Lemma dqst_auth_archive γhp' l' γdqst era γhp l t b :
length l ≤ length l' →
circ_slice l t b = circ_slice l' t b →
ghost_var γhp (1/2) l -∗
dqst_auth γdqst era γhp l t b ==∗
dqst_archived γdqst era γhp l t b ∗
dqst_auth γdqst (S era) γhp' l' t b.
Proof with extended_auto.
desγ γdqst.
iIntros (Hlong Heqs) "Own Auth".
iDestruct "Auth" as (γtbeO) "(%HltO & [tbO tbeO] & eltO & museO)".
iDestruct "eltO" as (elts) "[Elts %Heltslen]".
iDestruct "museO" as (proom museum) "museO".
iDestruct "museO" as "([%Hproomlen %Hmuslen] & museO)".
iDestruct "museO" as "(Room & Museum & Archives)".
(* archive *)
iMod (ghost_var_persist with "Own") as "#PC".
iDestruct (mono_nat_lb_own_get with "tbO") as "#tb".
iMod (mono_nat_own_persist with "tbeO") as "#tbe".
iDestruct (mono_list_lb_own_get with "Elts") as "#eltslb".
iDestruct (mono_list_lb_own_get with "Room") as "#roomlb".
iMod (mono_list_auth_own_update_app [(l, t, b)] with "Museum") as "[Museum #muslb]".
iSplitR.
{ iModIntro. fr. fr. all: fr.
- case_bool_decide... iRight. destruct Heltslen...
- rewrite lookup_app_r... replace (era - length proom) with 0...
- rewrite lookup_app_r... replace (era - length museum) with 0...
}
(* new era *)
iMod (mono_nat_own_alloc (top_bot_state t b)) as (γtbe') "[tbeO _]".
iMod (mono_list_auth_own_update_app [(γtbe', γhp', length l')]
with "Room") as "[Room #rlb]".
(* frame *)
iModIntro. fr. fr.
{ case_bool_decide... fr.
destruct Heltslen as [_ Hget].
apply (circ_slice_split_eq (S t)) in Heqs as [Heqs _]...
destruct (circ_slice_singleton l t) as [x [Hx Hsx]]...
destruct (circ_slice_singleton l' t) as [y [Hy Hsy]]...
rewrite Hsx Hsy in Heqs. injection Heqs as [= <-].
rewrite Hy -Hget Hx...
}
{ rewrite length_app -Hproomlen. simpl... }
{ rewrite length_app -Hmuslen. simpl... }
simpl. fr. all: fr.
- case_bool_decide... iRight. destruct Heltslen...
- rewrite lookup_app_l...
2: rewrite length_app; simpl...
rewrite lookup_app_r...
replace (length proom + 0 - length proom) with 0...
- rewrite lookup_app_r...
replace (length proom + 0 - length museum) with 0...
Qed.
End dqst.
Section proof.
Context `{!heapGS Σ, !cldequeG Σ} (dequeN hazptrN : namespace) (DISJ : hazptrN ## dequeN).
Variable (hazptr : hazard_pointer_spec Σ hazptrN).
Notation iProp := (iProp Σ).
Definition node (p : blk) lv γ_p : iProp :=
∃ (l : list val),
⌜lv = #(length l) :: l⌝ ∗ ghost_var γ_p (1/2) l.
Definition deque_inv (γq γera γsmr : gname) (γdqst : dqst_gnames) (q : blk) : iProp :=
∃ (era : nat) (C : blk) (l : list val) (t b : nat) (pop : bool) (γhp : gname),
⌜1 ≤ t ≤ b ∧ b < t + length l ∧ length l ≠ 0⌝ ∗
(* abstract *)
own γq (●E (circ_slice l t b)) ∗
ghost_var γera (1/2) (era, C, l, b, pop, γhp) ∗
dqst_auth γdqst era γhp l t b ∗
(* physical *)
(q +ₗ circle) ↦ #C ∗
( hazptr.(Managed) γsmr C (γhp) (S (length l)) node ∗
ghost_var γhp (1/2) l ) ∗
(q +ₗ qtop) ↦ #t ∗
(q +ₗ qbot) ↦{#1/2} #(if pop then b-1 else b).
Definition IsDeque (γ : gname) (q : blk) : iProp :=
∃ (γq γera γsmr : gname) (γdqst : dqst_gnames) (d : blk),
⌜γ = encode (γq, γera, γsmr, γdqst)⌝ ∗
(q +ₗ qdom) ↦□ #d ∗ hazptr.(IsHazardDomain) γsmr d ∗
inv dequeN (deque_inv γq γera γsmr γdqst q).
Global Instance IsDeque_persistent γ q :
Persistent (IsDeque γ q) := _.
Definition Deque (γ : gname) (frag : list val) : iProp :=
∃ (γq γera γsmr : gname) (γdqst : dqst_gnames),
⌜γ = encode (γq, γera, γsmr, γdqst)⌝ ∗
own γq (◯E frag).
Global Instance Deque_timeless γ frag :
Timeless (Deque γ frag) := _.
(* owner of the deque who can call push and pop *)
Definition OwnDeque (γ : gname) (q : blk) : iProp :=
∃ (γq γera γsmr : gname) (γdqst : dqst_gnames) (era : nat)
(l : list val) (C : blk) (b : nat) (γhp : gname),
⌜γ = encode (γq, γera, γsmr, γdqst)⌝ ∗
ghost_var γera (1/2) (era, C, l, b, false, γhp) ∗
(q +ₗ qbot) ↦{#1/2} #b.
Lemma own_ea_agree γ a b :
own γ (●E a) -∗ own γ (◯E b) -∗ ⌜a = b⌝.
Proof.
iIntros "● ◯".
by iCombine "● ◯" gives %?%excl_auth_agree_L.
Qed.
Lemma own_ea_update a' γ a b :
own γ (●E a) -∗ own γ (◯E b) ==∗ own γ (●E a') ∗ own γ (◯E a').
Proof.
iIntros "● ◯".
iMod (own_update_2 γ _ _ (●E a' ⋅ ◯E a') with "● ◯") as "[● ◯]".
- apply excl_auth_update.
- by iFrame.
Qed.
Lemma deque_new_spec :
deque_new_spec' dequeN hazptrN deque_new hazptr Deque IsDeque OwnDeque.
Proof with extended_auto.
iIntros (γsmr d n Hsz Φ) "!> #IHD HΦ". wp_lam.
(* allocate *)
wp_alloc q as "q↦" "†q". wp_pures.
do 4 rewrite array_cons. iDestruct "q↦" as "(C & T & B & D & _)".
wp_lam. wp_alloc C as "SzA" "†SzA"... wp_pures.
replace (Z.to_nat (1 + n)) with (1 + n)...
rewrite replicate_add array_cons. iDestruct "SzA" as "[Sz A]".
wp_store. wp_pures... wp_store. wp_pures. wp_store. wp_store. wp_store.
iDestruct "B" as "[B1 B2]".
(* make resources *)
iMod (pointsto_persist with "D") as "#D".
iMod (own_alloc (●E [] ⋅ ◯E [])) as (γq) "[γq● γq◯]". 1: apply excl_auth_valid.
iMod (ghost_var_alloc (replicate n #0)) as (γhp) "[ml1 ml2]".
iMod (ghost_var_alloc (0, C, (replicate n #0), 1, false, γhp)) as (γera) "[Era1 Era2]".
iMod (dqst_auth_alloc γhp (replicate n #0)) as (γdqst) "Auth"...
iCombine "Sz A" as "SzA". rewrite -array_cons.
iMod (hazptr.(hazard_domain_register) node with "IHD [$SzA †SzA ml2]") as "Man"; [solve_ndisj| |].
{ rewrite /= length_replicate. iFrame. fr. }
iMod (inv_alloc dequeN _ (deque_inv γq γera γsmr γdqst q)
with "[C T B1 Man γq● Auth Era1 ml1]") as "Inv".
{ fr. fr. }
(* apply Φ *)
iApply "HΦ". iModIntro. iSplitL "Inv"; first fr.
iSplitL "γq◯"; fr.
Qed.
Lemma managed_get_circle E γsmr d C γhp l :
↑(ptrN hazptrN C) ⊆ E →
IsHazardDomain hazptr γsmr d -∗
(Managed hazptr γsmr C γhp (S (length l)) node ∗ ghost_var γhp (1 / 2) l)
={E,E∖↑(ptrN hazptrN C)}=∗
(Managed hazptr γsmr C γhp (S (length l)) node ∗ ghost_var γhp (1 / 2) l) ∗
ghost_var γhp (1/2) l ∗
(C +ₗ csz) ↦ #(length l) ∗ (C +ₗ carr) ↦∗ l ∗
∀ l' : list val,
⌜length l = length l'⌝ ∗
(C +ₗ csz) ↦ #(length l) ∗ (C +ₗ carr) ↦∗ l' ∗
ghost_var γhp (1/2) l'
={E ∖ ↑ptrN hazptrN C,E}=∗ True.
Proof with extended_auto.
iIntros (HN) "#IHD [Man man]".
iInv "Man" as (l') "(_ & SzA & man' & Man)" "Ret".
unfold node. iDestruct "man'" as (larr) ">(%Hl' & man')".
iDestruct (ghost_var_agree with "man man'") as "%". subst larr.
rewrite Hl' array_cons. iDestruct "SzA" as "[Sz A]". fr.
iIntros "!>" (lp) "(%Hlenp & Szp & Ap & Rest)".
iMod ("Ret" with "[Szp Ap Rest]")...
iExists (#(length l) :: lp). fr...
1: simpl... fr. rewrite Hlenp...
Qed.
Lemma circle_grow_rec_spec (E : coPset) (γsmr : gname) (γhp : gname)
(d C : blk) (arr' : loc) (l l' : list val) (n m t b : nat) :
↑(ptrN hazptrN C) ⊆ E →
length l = n → length l' = m →
0 < n < m →
t ≤ b < t + n →
hazptr.(IsHazardDomain) γsmr d -∗
arr' ↦∗ l' -∗
<<{ ▷ hazptr.(Managed) γsmr C γhp (S (length l)) node ∗
ghost_var γhp (1 / 2) l }>>
circle_grow_rec #(C +ₗ carr) #n #arr' #m #t #b @ E,∅,↑(ptrN hazptrN C)
<<{ ∃∃ (l2' : list val),
⌜length l2' = m⌝ ∗
⌜circ_slice l t b = circ_slice l2' t b⌝ ∗
⌜∀ i, b ≤ i < t + length l → mod_get l' i = mod_get l2' i⌝ ∗
▷ hazptr.(Managed) γsmr C γhp (S (length l)) node ∗
ghost_var γhp (1 / 2) l |
RET #(); arr' ↦∗ l2'
}>>.
Proof with extended_auto.
iIntros "%HE %Hn %Hm %Hlen %Hlt #IHD A'" (Φ) "AU". wp_pures.
iRevert "A' AU". iRevert (b l' Hm Hlt).
iLöb as "IH". iIntros (b l') "%Hm %Hlt A' AU".
wp_pures. wp_lam. unfold circ_access. wp_pures.
remember (C +ₗ carr) as Carr.
case_bool_decide; last first; wp_pure credit:"£".
{ (* end loop *)
iMod "AU" as "[Cont [_ Commit]]".
iMod ("Commit" $! l' with "[Cont]") as "HΦ"; fr.
1: repeat rewrite circ_slice_nil...
iApply "HΦ"...
}
(* read b *)
wp_pures.
destruct b as [|b]...
replace (Z.of_nat (S b) - 1)%Z with (Z.of_nat b)...
rewrite rem_mod_eq...
wp_bind (! _)%E.
iMod "AU" as "[[A man] [Abort _]]".
iMod (lc_fupd_elim_later with "£ A") as "A".
iMod (managed_get_circle with "[] [A man]") as "(A & man & Sz' & Ap & Ret)"... 1: fr.
rewrite -HeqCarr.
destruct (mod_get_is_Some l b) as [v Hv]...
wp_apply (wp_load_offset with "Ap") as "Ap". 1: rewrite -Hn...
iMod ("Ret" with "[Sz' Ap man]") as "_". 1: fr.
iMod ("Abort" with "[A]") as "AU". 1: iDestruct "A" as "[Man man]"; fr.
iApply (fupd_mask_intro)... iIntros "Close". iMod "Close".
iModIntro. wp_pures.
(* write b *)
wp_bind (_ <- _)%E.
rewrite rem_mod_eq...
destruct (mod_get_is_Some l' b) as [v' Hv']...
iApply (wp_store_offset with "A'"). 1: rewrite -Hm...
iIntros "!> A'". wp_pures.
(* recurse *)
iApply ("IH" $! b (<[b `mod` m:=v]> l') with "[] [] [A']")...
1: rewrite length_insert...
iAuIntro.
rewrite /atomic_acc /=.
iMod "AU" as "[Cont AC]".
iModIntro. iFrame "Cont".
iSplit.
{ iIntros "Cont".
iDestruct "AC" as "[Abort _]".
iMod ("Abort" with "Cont") as "AU". fr. }
iIntros (l2') "(%Hm' & %Heqs & %Hlast & A)".
iDestruct "AC" as "[_ Commit]".
iMod ("Commit" $! l2' with "[A]") as "HΦ".
{ iFrame. iPureIntro. repeat split...
- rewrite (circ_slice_shrink_right _ _ _ v)...
2: replace (S b - 1) with b...
rewrite (circ_slice_shrink_right _ _ (S b) v)...
all: replace (S b - 1) with b...
+ rewrite Heqs...
+ rewrite -Hlast... unfold mod_get.
rewrite length_insert Hm list_lookup_insert...
rewrite Hm. apply Nat.mod_upper_bound...
- intros i Hi. rewrite -Hlast... unfold mod_get.
rewrite length_insert Hm list_lookup_insert_ne...
apply close_mod_neq...
}
iIntros "!> A'". iApply "HΦ"...
Qed.
Lemma circle_grow_spec (E : coPset) (γsmr : gname) (γhp : gname)
(d C : blk) (l : list val) (t b : nat) :
↑(ptrN hazptrN C) ⊆ E →
0 < length l →
t ≤ b < t + length l →
hazptr.(IsHazardDomain) γsmr d -∗
<<{ ▷ hazptr.(Managed) γsmr C γhp (S (length l)) node ∗
ghost_var γhp (1 / 2) l }>>
circle_grow #C #t #b #(length l) @ E,∅,↑(ptrN hazptrN C)
<<{ ∃∃ (C' : blk) (l' : list val),
⌜length l < length l'⌝ ∗
⌜circ_slice l t b = circ_slice l' t b⌝ ∗
▷ hazptr.(Managed) γsmr C γhp (S (length l)) node ∗
ghost_var γhp (1 / 2) l |
RET #C';
(C' +ₗ csz) ↦ #(length l') ∗ (C' +ₗ carr) ↦∗ l' ∗ † C' … Z.to_nat (S (length l')) }>>.
Proof with extended_auto.
iIntros "%HE %Hlen %Hlt #IHD" (Φ) "AU".
wp_lam. wp_pures. wp_lam. wp_pures.
wp_alloc SzA' as "SzA'" "†SzA'"... wp_pures.
replace (Z.to_nat (1 + 2 * length l)) with (1 + 2 * length l)...
rewrite replicate_add array_cons. iDestruct "SzA'" as "[Sz' A']".
wp_store. wp_pures.
replace (2 * Z.of_nat (length l))%Z with (Z.of_nat (2 * length l))...
(* make l' *)
awp_apply (circle_grow_rec_spec with "[] [A']")... unfold atomic_acc.
iMod "AU" as "[A AC]".
iModIntro. iFrame "A". iSplit.
{ iIntros "A". iDestruct "AC" as "[Abort _]". fr.
iApply ("Abort" with "A").
}
iIntros (l2') "(%Hlen' & %Heqs & %Hrest & A & A2)".
iCombine "A A2" as "A".
iDestruct "AC" as "[_ Commit]".
iMod ("Commit" $! SzA' l2' with "[A]") as "HΦ"; fr.
iIntros "!> A'".
wp_pures. iModIntro. iApply "HΦ". fr. rewrite Hlen'. fr.
Qed.
Lemma deque_push_spec :
deque_push_spec' dequeN hazptrN (deque_push hazptr) Deque IsDeque OwnDeque.
Proof with extended_auto using All.
iIntros (γ q v).
iIntros "#Is Own" (Φ) "AU".
iDestruct "Own" as (γq γera γsmr γdqst) "Own".
iDestruct "Own" as (era l C b γhp) "Own".
iDestruct "Own" as "(%Enc & eraOwn & bOwn)".
remember (C +ₗ Z.of_nat 1) as Carr.
iDestruct "Is" as (γq' γera' γsmr' γdqst') "Inv".
iDestruct "Inv" as (d) "(%Enc' & D & IHD & Inv)".
encode_agree Enc.
wp_lam. unfold circ_access. wp_pures.
wp_load. wp_pures.
(* 1. load top *)
wp_bind (! _)%E.
iInv "Inv" as (era1 C1 l1 t1 b1 pop1 γhp1) "Invs".
iDestruct "Invs" as "(>%Htb1 & ● & >Era & Dqst & C & A & >T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iDestruct (dqst_get_frag with "Dqst") as "#F1".
wp_load.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
wp_pures...
(* Q. get circle *)
wp_bind (! _)%E.
iInv "Inv" as (eraQ CQ lQ tQ bQ popQ γhpQ) "Invs"...
iDestruct "Invs" as "(>%HtbQ & ● & >Era & Dqst & >C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
wp_load.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
wp_pure credit:"£". wp_pures.
(* A. read size *)
wp_bind (! _)%E.
iInv "Inv" as (eraA CA lA tA bA popA γhpA) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%HtbA & ● & Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-]...
iMod (managed_get_circle with "[] [A]") as "(A & man & Sz' & A' & Ret)"... 1: solve_ndisj.
wp_load.
iMod ("Ret" $! l with "[man Sz' A']") as "_". 1: fr.
iModIntro. iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
wp_pure credit:"£". wp_pures.
case_bool_decide; last first; wp_pures...
- (* W. reload circle *)
wp_bind (! _)%E.
iInv "Inv" as (eraW CW lW tW bW popW γhpW) "Invs"...
iDestruct "Invs" as "(>%HtbW & ● & >Era & Dqst & >C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
wp_load.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
(* B. get size *)
wp_pures...
wp_bind (! _)%E.
iInv "Inv" as (eraB CB lB tB bB popB γhpB) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%HtbB & ● & Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-]...
iMod (managed_get_circle with "[] [A]") as "(A & man & Sz' & A' & Ret)"... 1: solve_ndisj.
wp_load.
iMod ("Ret" $! l with "[man Sz' A']") as "_". 1: fr.
iModIntro. iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
(* 2. write to circle *)
wp_pure credit:"£". wp_pures.
rewrite -HeqCarr rem_mod_eq...
wp_bind (_ <- _)%E.
iInv "Inv" as (era2 C2 l2 t2 b2 pop2 γhp2) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%Htb2 & ● & Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iMod (ghost_var_update_halves (era, C, (mod_set l b v), b, false, γhp)
with "eraOwn Era") as "[eraOwn Era]".
iDestruct (dqst_auth_write_bot v with "Dqst") as "Dqst".
iMod (managed_get_circle with "[] [A]") as "([Man man1] & man2 & Sz' & A' & Ret)"... 1: solve_ndisj.
iMod (ghost_var_update_halves (<[b `mod` length l:=v]> l)
with "man1 man2") as "[man1 man2]".
rewrite -HeqCarr.
iApply (wp_store_offset with "A'"). 1: apply mod_get_is_Some...
iIntros "!> A'".
iMod ("Ret" $! (<[b `mod` length l:=v]> l) with "[man2 Sz' A']") as "_".
1: rewrite length_insert; fr.
iCombine "Man man1" as "A".
iModIntro. iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,(mod_set l b v),t2,b.
rewrite mod_set_length circ_slice_update_right... fr. }
wp_pures.
(* 3. increment bot *)
iInv "Inv" as (era3 C3 l3 t3 b3 pop3 γhp3) "Invs".
iDestruct "Invs" as "(>%Htb3 & ● & >Era & >Dqst & C & A & T & >B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iMod (ghost_var_update_halves (era, C, (mod_set l b v), S b, false, γhp)
with "eraOwn Era") as "[eraOwn Era]".
iDestruct (dqst_get_lb with "Dqst F1") as "%Ht13".
iMod (dqst_auth_push with "Dqst") as "Dqst". 1: rewrite mod_set_length...
iCombine "bOwn B" as "B". wp_store.
replace (Z.of_nat b + 1)%Z with (Z.of_nat (S b))...
iDestruct "B" as "[bOwn B]".
iMod "AU" as (l') "[Cont [_ Commit]]".
iDestruct "Cont" as (γq' γera' γsmr' γbglob') "[%Enc' ◯]". encode_agree Enc.
iDestruct (own_ea_agree with "● ◯") as "%Hl'".
iMod (own_ea_update (l' ++ [v]) with "● ◯") as "[● ◯]".
iMod ("Commit" with "[◯]") as "HΦ". 1: fr.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists era, C, (mod_set l b v), t3, (S b). fr.
rewrite (circ_slice_extend_right _ _ _ v)... 2: rewrite mod_set_get...
subst l'. fr. rewrite mod_set_length... }
iApply "HΦ".
iExists γq, γera, γsmr, γdqst.
iExists era, (mod_set l b v), C, (S b), γhp. fr.
- (* X. grow *)
wp_load. wp_pures. wp_bind (circle_grow _ _ _ _)%E.
awp_apply circle_grow_spec...
iInv "Inv" as (eraX CX lX tX bX popX γhpX) "Invs".
iDestruct "Invs" as "(>%HtbX & ● & >Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iDestruct "A" as "[Man >man]". iCombine "Man man" as "A".
iAaccIntro with "A".
{ iIntros "A". iSplitL "● Era Dqst C A T B". 2: fr.
iExists _,_,l. fr. fr. }
iIntros (CX lX) "(%HlenX & %Heqs & A)".
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. fr. }
iIntros "(SzOwn & [AX †SzAX])". wp_pures...
replace (CX +ₗ 1) with (CX +ₗ Z.of_nat 1)...
remember (CX +ₗ Z.of_nat 1) as CXarr.
(* Y. replace array *)
wp_bind (_ <- _)%E.
iInv "Inv" as (eraY caY lY tY bY popY γhpY) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%HtbY & ● & Era & Dqst & C & [Man A] & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iMod (ghost_var_alloc lX) as (γhpY) "[man1 man2]".
iMod (ghost_var_alloc (length lX)) as (γnY) "mann".
iMod (ghost_var_persist with "mann") as "#mann".
iMod (ghost_var_update_halves (S era, CX, lX, b, false, γhpY)
with "eraOwn Era") as "[eraOwn Era]".
iDestruct (dqst_get_lb with "Dqst F1") as "%Ht1Y".
apply (circ_slice_split_eq tY) in Heqs as Heqsd... destruct Heqsd as [_ HeqsR]...
iCombine "SzOwn" "AX" as "AX". iEval (rewrite HeqCXarr -array_cons) in "AX".
iMod (hazptr.(hazard_domain_register) node with "IHD [$AX †SzAX man2]") as "AX"; [solve_ndisj| |]...
{ fr. }
iMod (dqst_auth_archive γhpY with "[A] [Dqst]") as "[#Arch Dqst]".
2: apply HeqsR. 1: lia. 1: fr. 1: fr.
wp_store.
iSplitL "● Era Dqst C AX man1 T B".
{ iModIntro; iNext. iExists _,_,lX.
fr. fr. rewrite -HeqsR. fr. }
iModIntro. wp_pures...
(* retire *)
replace (Z.of_nat (length l) + 1)%Z with (Z.of_nat (S (length l)))...
wp_apply (hazard_domain_retire_spec with "IHD Man") as "_"...
wp_pures.
(* W. reload circle *)
wp_bind (! _)%E.
iInv "Inv" as (eraW CW lW tW bW popW γhpW) "Invs"...
iDestruct "Invs" as "(>%HtbW & ● & >Era & Dqst & >C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
wp_load.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,lX. fr. }
wp_pure credit:"£". wp_pures.
(* B. get size *)
wp_bind (! _)%E.
iInv "Inv" as (eraB CB lB tB bB popB γhpB) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%HtbB & ● & Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-]...
iMod (managed_get_circle with "[] [A]") as "(A & man & Sz' & A' & Ret)"... 1: solve_ndisj.
wp_load.
iMod ("Ret" $! lX with "[man Sz' A']") as "_". 1: fr.
iModIntro. iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,lX. fr. }
(* 2. write to circle *)
wp_pure credit:"£". wp_pures.
rewrite -HeqCXarr rem_mod_eq...
wp_bind (_ <- _)%E.
iInv "Inv" as (era2 C2 l2 t2 b2 pop2 γhp2) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%Htb2 & ● & Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iMod (ghost_var_update_halves (S era, CX, (mod_set lX b v), b, false, γhpY)
with "eraOwn Era") as "[eraOwn Era]".
iDestruct (dqst_auth_write_bot v with "Dqst") as "Dqst".
iMod (managed_get_circle with "[] [A]") as "([Man man1] & man2 & Sz' & A' & Ret)"... 1: solve_ndisj.
iMod (ghost_var_update_halves (<[b `mod` length lX:=v]> lX)
with "man1 man2") as "[man1 man2]".
rewrite -HeqCXarr.
iApply (wp_store_offset with "A'"). 1: apply mod_get_is_Some...
iIntros "!> A'".
iMod ("Ret" $! (<[b `mod` length lX:=v]> lX) with "[man2 Sz' A']") as "_".
1: rewrite length_insert; fr.
iCombine "Man man1" as "A".
iModIntro. iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,(mod_set lX b v),t2,b.
rewrite mod_set_length circ_slice_update_right... fr. }
wp_pures.
(* 3. increment bot *)
iInv "Inv" as (era3 C3 l3 t3 b3 pop3 γhp3) "Invs".
iDestruct "Invs" as "(>%Htb3 & ● & >Era & >Dqst & C & A & T & >B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
iMod (ghost_var_update_halves (S era, CX, (mod_set lX b v), S b, false, γhpY)
with "eraOwn Era") as "[eraOwn Era]".
iDestruct (dqst_get_lb with "Dqst F1") as "%Ht13".
iMod (dqst_auth_push with "Dqst") as "Dqst". 1: rewrite mod_set_length...
iCombine "bOwn B" as "B". wp_store.
replace (Z.of_nat b + 1)%Z with (Z.of_nat (S b))...
iDestruct "B" as "[bOwn B]".
iMod "AU" as (l') "[Cont [_ Commit]]".
iDestruct "Cont" as (γq' γera' γsmr' γbglob') "[%Enc' ◯]". encode_agree Enc.
iDestruct (own_ea_agree with "● ◯") as "%Hl'".
iMod (own_ea_update (l' ++ [v]) with "● ◯") as "[● ◯]".
iMod ("Commit" with "[◯]") as "HΦ". 1: fr.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists (S era), CX, (mod_set lX b v), t3, (S b). fr.
rewrite (circ_slice_extend_right _ _ _ v)... 2: rewrite mod_set_get...
subst l'. fr. rewrite mod_set_length... }
iApply "HΦ".
iExists γq, γera, γsmr, γdqst.
iExists (S era), (mod_set lX b v), CX, (S b), γhpY. fr.
Qed.
Lemma deque_pop_spec :
deque_pop_spec' dequeN hazptrN deque_pop Deque IsDeque OwnDeque.
Proof with extended_auto using All.
iIntros (γ q).
iIntros "#Is Own" (Φ) "AU".
iDestruct "Own" as (γq γera γsmr γdqst) "Own".
iDestruct "Own" as (era l C b γhp) "Own".
iDestruct "Own" as "(%Enc & eraOwn & bOwn)".
remember (C +ₗ Z.of_nat 1) as Carr.
iDestruct "Is" as (γq' γera' γsmr' γdqst') "Inv".
iDestruct "Inv" as (d) "(%Enc' & D & IHD & Inv)".
encode_agree Enc.
wp_lam. unfold circ_access. wp_pures.
wp_load. wp_pures...
(* Q. get circle *)
wp_bind (! _)%E.
iInv "Inv" as (eraQ CQ lQ tQ bQ popQ γhpQ) "Invs"...
iDestruct "Invs" as "(>%HtbQ & ● & >Era & Dqst & >C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-].
wp_load.
iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
wp_pure credit:"£". wp_pures...
(* A. read size *)
wp_bind (! _)%E.
iInv "Inv" as (eraA CA lA tA bA popA γhpA) "Invs".
iMod (lc_fupd_elim_later with "£ Invs") as "Invs".
iDestruct "Invs" as "(%HtbA & ● & Era & Dqst & C & A & T & B)".
iDestruct (ghost_var_agree with "eraOwn Era") as "%Eq"; injection Eq as [= <- <- <- <- <- <-]...
iMod (managed_get_circle with "[] [A]") as "(A & man & Sz' & A' & Ret)"... 1: solve_ndisj.
wp_load.
iMod ("Ret" $! l with "[man Sz' A']") as "_". 1: fr.
iModIntro. iModIntro. iSplitL "● Era Dqst C A T B".
{ iExists _,_,l. fr. }
wp_pures.
(* 1. decrement bot *)
wp_bind (_ <- _)%E.
iInv "Inv" as (era1 C1 l1 t1 b1 pop1 γhp1) "Invs".