-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocks.v
1773 lines (1574 loc) · 61.3 KB
/
locks.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
(*********************************************************************)
(* Stability in Weak Memory Models *)
(* *)
(* Jade Alglave INRIA Paris-Rocquencourt, France *)
(* University of Oxford, UK *)
(* *)
(* Copyright 2010 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed *)
(* under the terms of the Lesser GNU General Public License. *)
(*********************************************************************)
Require Import Ensembles.
Require Import Arith.
Require Import Bool.
From CoqCat Require Import util.
From CoqCat Require Import wmm.
From CoqCat Require Import basic.
From CoqCat Require Import hierarchy.
From CoqCat Require Import sc.
From CoqCat Require Import valid.
From CoqCat Require Import covering.
From CoqCat Require Import drf.
Require Import Classical_Prop.
(*Require Import orders.*)
Import OEEvt.
Set Implicit Arguments.
Module Locks (A: Archi) (dp:Dp).
Module ARes <: Archi.
Parameter ppo : Event_struct -> Rln Event.
Hypothesis ppo_valid : forall E, rel_incl (ppo E) (po_iico E).
Hypothesis ppo_fun :
forall E s x y,
ppo E x y /\ s x /\ s y <->
ppo (mkes (Intersection Event (events E) s) (rrestrict (iico E) s)) x y.
Parameter inter : bool.
Parameter intra : bool.
Parameter abc : Event_struct -> Execution_witness -> Rln Event.
Hypothesis ab_evts : forall (E:Event_struct) (X:Execution_witness),
forall x y, well_formed_event_structure E ->
rfmaps_well_formed E (events E) (rf X) ->
abc E X x y -> In _ (events E) x /\ In _ (events E) y.
Hypothesis ab_incl :
forall E X, rel_incl (abc E X) (tc (rel_union (com E X) (po_iico E))).
Hypothesis ab_fun :
forall E X s x y,
well_formed_event_structure E ->
rfmaps_well_formed E (events E) (rf X) ->
(abc E X x y /\ s x /\ s y <->
abc (mkes (Intersection Event (events E) s) (rrestrict (iico E) s))
(mkew (rrestrict (ws X) s) (rrestrict (rf X) s)) x y).
Parameter stars : Event_struct -> set Event.
End ARes.
Import ARes.
(** locks *)
Module An <: Archi.
Definition ppo := A.ppo.
Lemma ppo_valid : forall E, rel_incl (ppo E) (po_iico E).
Proof.
apply A.ppo_valid.
Qed.
Lemma ppo_fun :
forall E s x y,
ppo E x y /\ s x /\ s y <->
ppo (mkes (Intersection Event (events E) s) (rrestrict (iico E) s)) x y.
Proof.
apply A.ppo_fun.
Qed.
Definition inter := A.inter.
Definition intra := A.intra.
Definition abc (E:Event_struct) (X:Execution_witness) : Rln Event :=
fun e1 => fun e2 => False.
Lemma ab_evts : forall (E:Event_struct) (X:Execution_witness),
forall x y, well_formed_event_structure E ->
rfmaps_well_formed E (events E) (rf X) ->
abc E X x y -> In _ (events E) x /\ In _ (events E) y.
Proof.
intros E X x y Hwf Hrf Hxy. inversion Hxy.
Qed.
Lemma ab_incl :
forall E X, rel_incl (abc E X) (tc (rel_union (com E X) (po_iico E))).
Proof.
intros E X x y Hxy. inversion Hxy.
Qed.
Lemma ab_fun :
forall E X s x y,
well_formed_event_structure E ->
rfmaps_well_formed E (events E) (rf X) ->
(abc E X x y /\ s x /\ s y <->
abc (mkes
(Intersection Event (events E) s) (rrestrict (iico E) s))
(mkew (rrestrict (ws X) s) (rrestrict (rf X) s)) x y).
Proof.
intros E X s x y Hwf Hrfwf; split; intro Hxy.
destruct Hxy as [Hxy ?]; inversion Hxy.
inversion Hxy.
Qed.
Parameter stars : Event_struct -> set Event.
End An.
Module AnWmm := Wmm An dp.
Module VA := Valid An dp.
Import VA. Import VA.ScAx.
Module Covering := Covering ARes An dp.
Import Covering.
Definition atom (E:Event_struct) (r w: Event) (l:Location): Prop :=
reads E r /\ stars E r /\ loc r = l /\
writes E w /\ stars E w /\ loc w = l /\ po_iico E r w /\
~(exists e, stars E e /\ po_iico E r e /\ po_iico E e w) /\
(forall X, ~(exists w', proc_of w' <> proc_of r /\
writes E w' /\ loc w' = l /\ fr E X r w' /\ ws X w' w)). (*w' pas sur le meme proc*)
Ltac destruct_atom H :=
destruct H as [Hr [Hatr [Hlr [Hw [Haw [Hlw [Hporw [Hnoc Hno]]]]]]]].
Definition taken (E:Event_struct) (l:Location) r : Prop :=
(exists w, atom E r w l (*/\ value_of r = Some 0 /\ value_of w = Some 1*)).
Definition free (E:Event_struct) (l:Location) r w : Prop :=
po_iico E r w /\ taken E l r /\ loc w = l (*/\ value_of w = Some 0*).
Definition ImportBarrier (E: Event_struct) (b: Event) : Prop :=
forall X,
(forall r e, reads E r -> stars E r -> po_iico E r b -> po_iico E b e -> abc E X r e) (*/\
(forall r w rw, reads E r -> po_iico E r b -> po_iico E b w -> rf X w rw -> abc E X r rw)*).
Definition ExportBarrier (E: Event_struct) (b: Event) : Prop :=
forall X,
(forall e w r, stars E r ->
po_iico E e b -> po_iico E b w -> rf X w r -> abc E X e r) (*/\
(forall e1 e2, po_iico E e1 b -> po_iico E b e2 -> ~(writes E e1 /\ reads E e2) -> abc E X e1 e2)*).
Definition Lock (E:Event_struct) (l:Location) (r c:Event) : Prop :=
taken E l r /\ ImportBarrier E c /\ po_iico E r c.
Definition Unlock (E:Event_struct) (l:Location) r (b w:Event) : Prop :=
free E l r w /\ ExportBarrier E b /\ po_iico E b w.
Record Cs' : Type := mkcs
{Read: Event ;
Ib: Event ;
Eb: Event;
Write: Event;
Evts: set Event}.
Definition Cs := Cs'.
Definition cs (E:Event_struct) (l:Location) crit :=
Lock E l crit.(Read) crit.(Ib) /\
(forall e, crit.(Evts) e <-> po_iico E crit.(Ib) e /\ po_iico E e crit.(Eb)) /\
Unlock E l crit.(Read) crit.(Eb) crit.(Write) /\
po_iico E crit.(Ib) crit.(Eb).
Definition evts (cs:Cs) := Evts cs.
Definition sc E l :=
fun s1 => fun s2 => cs E l s1 /\ cs E l s2 /\ s1 <> s2.
Definition s E (X:Execution_witness) :=
fun e1 => fun e2 => exists l, exists s1, exists s2, sc E l s1 s2 /\ evts s1 e1 /\ evts s2 e2.
Definition css E X l :=
fun s1 => fun s2 => sc E l s1 s2 /\
(rf X) s1.(Write) s2.(Read).
Ltac destruct_css H :=
destruct H as [[Hcs1 [Hcs2 Hdcs]] Hrf].
Definition css_lift E X l :=
fun e1 => fun e2 => exists s1, exists s2,
css E X l s1 s2 /\ (Evts s1) e1 /\ (Evts s2) e2.
Ltac destruct_csslift H :=
destruct H as [s1 [s2 [Hcss [Hev1 Hev2]]]].
Inductive lockc' E X l : Event -> Event -> Prop :=
| RF : forall e1 e2, css_lift E X l e1 e2 -> lockc' E X l e1 e2
| Trans :
forall e1 e e2,
lockc' E X l e1 e -> lockc' E X l e e2 -> lockc' E X l e1 e2.
Definition lockc E X l := lockc' E X l.
Definition lock E X := fun e1 => fun e2 => exists l, lockc E X l e1 e2.
Parameter inite : Location -> Event.
Axiom init_evt : forall E l, events E (inite l).
Axiom init_store : forall l, write_to (inite l) l.
Axiom init_ws : forall X l, ~(exists e, ws X e (inite l)).
Axiom init_cs : forall E l cr, cs E l cr /\ Write cr = inite l -> Evts cr (inite l).
Module DaRaFr := DataRaceFree ARes A dp.
Import DaRaFr.
Module HB : HappensBefore.
Module AResDrf := DataRaceFree ARes A dp.
Import AResDrf.
Module AResBasic := Basic ARes dp.
Import AResBasic.
Module AResWmm := Wmm ARes dp.
Import AResWmm.
Import ARes.
Definition sync := s.
Definition happens_before E X :=
tc (rel_union (po_iico E) (sync E X)).
Hypothesis happens_before_compat_com :
forall E X x y, com E X x y -> ~(happens_before E X y x).
Definition competing E (X:Execution_witness) :=
fun e1 => fun e2 => events E e1 /\ events E e2 /\
loc e1 = loc e2 /\ proc_of e1 <> proc_of e2 /\
(writes E e1 \/ writes E e2).
Definition cns E X :=
fun e1 => fun e2 => competing E X e1 e2 /\
~ (happens_before E X e1 e2 \/ happens_before E X e2 e1).
Definition convoluted_wf :=
forall E X Y x y,
competing E X x y ->
~ (happens_before E X x y \/ happens_before E X y x) ->
rf Y = so_rfm E
(LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E)) (pio_llh E)))) ->
ws Y = so_ws
(LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E)) (pio_llh E)))) ->
competing E Y x y /\ ~ (happens_before E Y x y \/ happens_before E Y y x).
Lemma compete_in_events :
forall E X x y,
well_formed_event_structure E ->
rfmaps_well_formed E (events E) (rf X) ->
competing E X x y ->
events E x /\ events E y.
Proof.
intros E X x y Hwf Hrfwf [Hex [Hey ?]]; split; auto.
Qed.
Lemma udr_xy_ppo2_in_events :
forall E X r x y,
well_formed_event_structure E ->
rfmaps_well_formed E (events E) (rf X) ->
competing E X x y ->
Included _ (Union _ (dom (tc (rel_union (rel_union (rel_inter r (pair x y)) (A.ppo E)) (pio_llh E))))
(ran (tc (rel_union (rel_union (rel_inter r (pair x y)) (A.ppo E)) (pio_llh E))))) (events E).
Proof.
intros E X r x y Hwf Hwfrf Hc e1 Hudr.
generalize (compete_in_events Hwf Hwfrf Hc); intros [Hex Hey].
inversion Hudr as [e Hd |e Hr].
generalize (dom_tc_in_dom Hd); intros [e2 Hi];
inversion Hi as [Hu | Hpio].
inversion Hu as [Hp | Hppo].
destruct Hp as [? [? ?]]; subst; auto.
apply ABasic.po_iico_domain_in_events with e2; auto.
apply A.ppo_valid; auto.
destruct Hpio as [? [Hpo ?]].
apply ABasic.po_iico_domain_in_events with e2; auto.
generalize (ran_tc_in_ran Hr); intros [e2 Hi];
inversion Hi as [Hu | Hpio].
inversion Hu as [Hp | Hppo].
destruct Hp as [? [? ?]]; subst; auto.
apply ABasic.po_iico_range_in_events with e2; auto.
apply A.ppo_valid; auto.
destruct Hpio as [? [Hpo ?]].
apply ABasic.po_iico_range_in_events with e2; auto.
Qed.
Ltac destruct_valid H :=
destruct H as [[Hws_tot Hws_cands] [[Hrf_init [Hrf_cands Hrf_uni]] [Hsp [Hth Hvalid]]]];
unfold write_serialization_well_formed in Hws_tot(*; unfold uniproc in Hsp*).
Lemma u_in_pair_po :
forall E X x y e1 e2,
tc (rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E))
(pio_llh E)) e1 e2 ->
tc (rel_union (rel_inter (cns E X) (pair x y)) (po_iico E)) e1 e2.
Proof.
intros E X x y e1 e2 H12.
induction H12 as [e1 e2 Hu |]; [apply trc_step|].
inversion Hu as [Hun | Hpio].
inversion Hun as [Hp | Hppo].
left; auto.
right; apply A.ppo_valid; auto.
right; destruct Hpio as [? [? ?]]; auto.
apply trc_ind with z; auto.
Qed.
Lemma competing_irr : forall E X,
well_formed_event_structure E ->
AWmm.valid_execution E X ->
~ (exists z, competing E X z z).
Proof.
intros E X Hwf Hv [z [? [? [? [Hdp ?]]]]].
apply Hdp; trivial.
Qed.
Lemma pair_irr :
forall E X x y,
well_formed_event_structure E ->
AWmm.valid_execution E X ->
~ (exists z, (rel_inter (cns E X) (pair x y) z z)).
Proof.
intros E X x y Hwf Hv1 [z [[Hx Hy] [Hc ?]]].
destruct Hc as [? [? [? [Hdp ?]]]].
assert (exists z, competing E X z z) as Hc.
exists z; auto.
apply (competing_irr Hwf Hv1 Hc).
Qed.
Lemma competing_not_po :
forall E X x y,
well_formed_event_structure E ->
AWmm.valid_execution E X ->
competing E X x y -> ~ (po_iico E y x).
Proof.
intros E X x y Hwf Hv [? [? [? [Hdp ?]]]] Hpo.
assert (In _ (events E) x) as Hx.
apply AResBasic.po_iico_range_in_events with y; auto.
assert (In _ (events E) y) as Hy.
apply AResBasic.po_iico_domain_in_events with x; auto.
generalize (AResBasic.po_implies_same_proc Hwf Hy Hx Hpo); intro Heq;
subst; auto.
Qed.
Lemma tc_pair_po_in_pair_po :
forall E X x y,
well_formed_event_structure E ->
AWmm.valid_execution E X ->
rel_incl (tc (rel_seq (rel_inter (cns E X) (pair x y)) (po_iico E)))
(rel_seq (rel_inter (cns E X) (pair x y)) (po_iico E)).
Proof.
intros E X x y Hwf Hv1 e1 e2 H12.
induction H12; auto.
destruct IHtc1 as [z1 [H1 Hz1]];
destruct IHtc2 as [z2 [H2 Hz2]].
assert (po_iico E y x) as Hpo.
destruct H1 as [? [? Hy]]; rewrite Hy in Hz1.
destruct H2 as [? [Hx ?]]; rewrite Hx in Hz1.
auto.
destruct H1 as [Hc [Hx Hy]];
rewrite Hx in Hc; rewrite Hy in Hc.
destruct Hc as [Hc ?].
generalize (competing_not_po Hwf Hv1 Hc); intro; contradiction.
Qed.
Lemma competing_ac_ppo2 :
forall E X x y,
well_formed_event_structure E ->
AWmm.valid_execution E X ->
competing E X x y ->
(forall z, ~ tc (rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E)) (pio_llh E)) z z).
Proof.
intros E X x y Hwf Hv Hc z Hz.
generalize (u_in_pair_po Hz); intro Hu.
rewrite union_triv in Hu.
assert (~ (exists x, po_iico E x x)) as Hi1.
intros [e He]; apply (A2Basic.po_ac Hwf He).
assert (~ (exists z, (rel_inter (cns E X) (pair x y)) z z)) as Hi2.
apply pair_irr; auto.
assert (~ (exists z, (rel_union (po_iico E) (rel_inter (cns E X) (pair x y)) z z))) as Hiu.
intros [e He]; inversion He.
apply (A2Basic.po_ac Hwf H).
assert (exists z, rel_inter (cns E X) (pair x y) z z) as Hco.
exists e; auto.
apply (pair_irr Hwf Hv Hco).
assert (trans (rel_inter (cns E X) (pair x y))) as Ht2.
unfold trans; intros e1 e2 e3 H12 H23.
destruct H12 as [? [? Hy]];
destruct H23 as [[Hco ?] [Hx Hy2]].
rewrite Hx in Hco; rewrite Hy2 in Hco.
rewrite <- Hx in Hco; rewrite <- Hy in Hco.
assert (exists z, competing E X z z) as Hcon.
exists e2; auto.
generalize (competing_irr Hwf Hv Hcon); intro Ht; inversion Ht.
assert (trans (po_iico E)) as Ht1.
intros e1 e2 e3 H12 H23; apply A2Basic.po_trans with e2; auto.
generalize (union_cycle_implies_seq_cycle2 Hi1 Hi2 Hiu Ht2 Ht1 Hu);
intros [e Htc].
generalize (tc_pair_po_in_pair_po Hwf Hv Htc); intro He.
destruct He as [e' [[[Hee' ?] ?] He'e]].
generalize (competing_not_po Hwf Hv Hee'); intro; contradiction.
Qed.
Lemma convoluted_wf_implies_wf :
convoluted_wf ->
(forall E X x y,
well_formed_event_structure E ->
AResWmm.valid_execution E X ->
competing E X x y ->
~ (happens_before E X x y \/ happens_before E X y x) ->
(exists Y, AnWmm.valid_execution E Y /\
competing E Y x y /\ ~ (happens_before E Y x y \/ happens_before E Y y x))).
Proof.
intros Hcwf E X x y Hwf Hv1 Hcxy Hns.
assert (exists so, vexec E so /\
so_rfm E so = (so_rfm E
(LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y))
(A.ppo E)) (pio_llh E))))) /\
so_ws so = (so_ws
(LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y))
(A.ppo E)) (pio_llh E)))))) as Hvexec.
exists (LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y))
(A.ppo E)) (pio_llh E)))).
split; [|split]; auto.
assert (partial_order (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E)) (pio_llh E))) (events E)) as Hp.
split.
apply udr_xy_ppo2_in_events with X; auto.
destruct_valid Hv1; split; auto.
split.
intros x1 x2 x3 [H12 H23]; apply trc_ind with x2; auto.
intro e; apply competing_ac_ppo2; auto.
assert (Included _ (events E) (events E)) as Htriv.
unfold Included; trivial.
generalize (OE Htriv Hp); intros [Hincl Hle].
split; auto.
apply lin_implies_part; auto.
generalize (le_lso Hle); intro Heq; rewrite Heq.
split.
apply incl_ac with (LE
(tc
(rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E))
(pio_llh E)))).
intros e1 e2 H12; inversion H12 as [Hppo|]; auto.
apply Hincl; apply trc_step; left; right; auto.
generalize (lso_is_tc Hle); intro Htc.
intros e He; rewrite Htc in He; destruct_lin Hle;
apply (Hac e He).
apply incl_ac with (LE
(tc
(rel_union (rel_union (rel_inter (cns E X) (pair x y)) (A.ppo E))
(pio_llh E)))).
intros e1 e2 H12; inversion H12 as [Hppo|]; auto.
apply Hincl; apply trc_step; right; auto.
generalize (lso_is_tc Hle); intro Htc.
intros e He; rewrite Htc in He; destruct_lin Hle;
apply (Hac e He).
generalize (ScModel.vexec_is_valid E
(so_rfm E (LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y))
(A.ppo E)) (pio_llh E)))))
(so_ws
(LE (tc (rel_union (rel_union (rel_inter (cns E X) (pair x y))
(A.ppo E)) (pio_llh E)))))
Hwf Hvexec); intros [Y [Hv2Y [? ?]]].
exists Y; split; auto.
Qed.
Lemma convoluted_wf_holds :
convoluted_wf.
Proof.
intros E X Y x y Hcxy Hnxy Hrf Hwf.
split; [apply Hcxy |apply Hnxy].
Qed.
Lemma hb_stable :
(* forall E X x y,
well_formed_event_structure E ->
A1Wmm.valid_execution E X ->
competing E X x y ->
~ (happens_before E X x y \/ happens_before E X y x) ->
(exists Y, A2nWmm.valid_execution E Y /\
competing E Y x y /\ ~ (happens_before E Y x y \/ happens_before E Y y x)).*)
forall E X x y,
well_formed_event_structure E ->
valid_execution E X ->
competing E X x y ->
~ (happens_before E X x y \/ happens_before E X y x) ->
(exists Y, AnWmm.valid_execution E Y /\
competing E Y x y /\ ~ (happens_before E Y x y \/ happens_before E Y y x)).
Proof.
intros E X x y Hwf HX Hcxy Hnxy.
apply convoluted_wf_implies_wf with X; auto.
unfold convoluted_wf; apply convoluted_wf_holds.
Qed.
(*Import OEEvt.*)
(** DRF progs have SC sem *)
Lemma in_lockc_rf_case_implies_in_ab :
forall E X l e1 e2,
well_formed_event_structure E ->
valid_execution E X ->
css_lift E X l e1 e2 ->
tc (abc E X) e1 e2.
Proof.
intros E X l e1 e2 Hwf Hv Hcsslift.
destruct_csslift Hcsslift.
destruct_css Hcss.
destruct Hcs1 as [HL1 [Hee1 [HUL1 Hib1]]].
destruct HUL1 as [Hur1 [Heb1 Hpobw1]].
destruct Hcs2 as [[Hres2 [Hib2 Hporc2]] [Hee2 HUL2]].
apply trc_ind with (Read s2); auto; apply trc_step; auto.
(*destruct (Heb1 X) as [Hcumul Hbase].*) generalize (Heb1 X); intro Hcumul.
apply (Hcumul e1 (Write s1) (Read s2)).
destruct Hres2 as [? (*[*)Hat2 (*?]*)]; destruct_atom Hat2; auto.
destruct (Hee1 e1) as [Hee1d Hee1b].
subst; destruct (Hee1d Hev1); auto.
auto.
auto.
(*destruct (Hib2 X) as [Hbase Hcumul]*)
generalize (Hib2 X); intro Hbase.
apply (Hbase (Read s2) e2); auto.
split; destruct_valid Hv;
[apply ran_rf_in_events with X (Write s1) |
apply ran_rf_is_read with E X (Write s1)]; auto; split; auto.
destruct Hres2 as [? (*[*)Hat2 (*?]*)]; destruct_atom Hat2; auto.
destruct (Hee2 e2) as [Hee2d Hee2b].
subst; destruct (Hee2d Hev2); auto.
Qed.
Lemma in_lockc_implies_in_ab :
forall E X l e1 e2,
well_formed_event_structure E ->
valid_execution E X ->
lockc E X l e1 e2 ->
tc (abc E X) e1 e2.
Proof.
intros E X l e1 e2 Hwf Hv H12.
induction H12.
apply (in_lockc_rf_case_implies_in_ab Hwf Hv H).
apply trc_ind with e; auto.
Qed.
Lemma lockc_u_ghb_in_ghb :
forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
rel_incl (tc (rel_union (lockc E X l) (ghb E X))) (tc (ghb E X)).
Proof.
intros E X l Hwf Hv x y H.
induction H as [x y Hxy |].
inversion Hxy.
assert (rel_incl (abc E X) (ghb E X)) as Hi.
apply ab_in_ghb; auto.
apply (tc_incl Hi).
apply in_lockc_implies_in_ab with l; auto.
apply trc_step; auto.
apply trc_ind with z; auto.
Qed.
Lemma lockc_ghb : forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
acyclic (rel_union (lockc E X l) (ghb E X)).
Proof.
intros E X l Hwf Hv x Hx.
generalize (lockc_u_ghb_in_ghb Hwf Hv Hx); intro Hcy.
destruct_valid Hv; apply (Hvalid x Hcy).
Qed.
Lemma lockc_irrefl :
forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
~(exists x, lockc E X l x x).
Proof.
intros E X l Hwf Hv [x Hx].
generalize (in_lockc_implies_in_ab Hwf Hv Hx); intro Hc.
destruct_valid Hv; unfold acyclic in Hvalid; apply (Hvalid x).
assert (rel_incl (abc E X) (ghb E X)) as Hi.
intros e1 e2; apply ab_in_ghb; auto.
apply (tc_incl Hi Hc).
Qed.
Lemma lock_irrefl :
forall E X,
well_formed_event_structure E ->
valid_execution E X ->
~(exists x, lock E X x x).
Proof.
intros E X Hwf Hv [x [l Hx]].
generalize (in_lockc_implies_in_ab Hwf Hv Hx); intro Hc.
destruct_valid Hv; unfold acyclic in Hvalid; apply (Hvalid x).
assert (rel_incl (abc E X) (ghb E X)) as Hi.
intros e1 e2; apply ab_in_ghb; auto.
apply (tc_incl Hi Hc).
Qed.
Lemma po_irrefl :
forall E, well_formed_event_structure E ->
~(exists x, po_iico E x x).
Proof.
intros E Hwf [x Hx]. apply (po_ac Hwf Hx).
Qed.
Lemma lockc_po_irrefl :
forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
~(exists x, (rel_union (po_iico E) (lockc E X l)) x x).
Proof.
intros E X l Hwf Hv [x Hx]; inversion Hx.
assert (exists x, po_iico E x x) as He.
exists x; auto.
apply (po_irrefl Hwf He); auto.
assert (exists x, lockc E X l x x) as He.
exists x; auto.
apply (lockc_irrefl Hwf Hv He).
Qed.
Lemma lock_po_irrefl :
forall E X,
well_formed_event_structure E ->
valid_execution E X ->
~(exists x, (rel_union (po_iico E) (lock E X)) x x).
Proof.
intros E X Hwf Hv [x Hx]; inversion Hx.
assert (exists x, po_iico E x x) as He.
exists x; auto.
apply (po_irrefl Hwf He); auto.
assert (exists x, lock E X x x) as He.
exists x; auto.
apply (lock_irrefl Hwf Hv He).
Qed.
Lemma lockc_trans :
forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
trans (lockc E X l).
Proof.
intros E X l Hwf Hv x y z Hxy Hyz.
unfold lockc in * |- *;
apply Trans with y; auto.
Qed.
Lemma po_trans :
forall E, well_formed_event_structure E ->
trans (po_iico E).
Proof.
intros E Hwf x y z Hxy Hyz. apply po_trans with y; auto.
Qed.
Lemma lockc_rf_implies_in_ab_with_lwarx :
forall E X l e1 s1 s2,
well_formed_event_structure E ->
valid_execution E X ->
Evts s1 e1 ->
css E X l s1 s2 ->
tc (abc E X) e1 (Read s2).
Proof.
intros E X l e1 s1 s2 Hwf Hv Hev1 Hcss.
destruct_css Hcss.
destruct Hcs1 as [HL1 [Hee1 [HUL1 Hib1]]].
destruct HUL1 as [Hur1 [Heb1 Hpobw1]].
destruct Hcs2 as [[Hres2 [Hib2 Hporc2]] [Hee2 HUL2]].
apply trc_step; auto.
(*destruct (Heb1 X) as [Hcumul Hbase].*) generalize (Heb1 X); intro Hcumul.
apply (Hcumul e1 (Write s1) (Read s2)).
destruct Hres2 as [? (*[*)Hat2 (*?]*)]; destruct_atom Hat2; auto.
destruct (Hee1 e1) as [Hee1d Hee1b].
subst;
destruct (Hee1d Hev1); auto.
auto.
auto.
Qed.
Lemma lockc_seq_po_in_ab :
forall E X l x y z,
well_formed_event_structure E ->
valid_execution E X ->
lockc E X l x y -> po_iico E y z -> tc (abc E X) x z.
Proof.
intros E X l x y z Hwf Hv Hxy Hyz.
induction Hxy.
destruct_csslift H.
destruct_css Hcss.
assert (po_iico E (Eb s2) z \/ po_iico E z (Eb s2)) as Hor.
apply same_proc_implies_po; auto.
assert (In _ (events E) e2) as Hee2.
apply po_iico_domain_in_events with z; auto.
assert (In _ (events E) z) as Hez.
apply po_iico_range_in_events with e2; auto.
rewrite <- (po_implies_same_proc Hwf Hee2 Hez Hyz).
destruct Hcs2 as [HL2 [Heve2 [HUL2 Hib2]]].
destruct HUL2 as [Hur2 [Heb2 Hpobw2]].
generalize (Heve2 e2); intros [Hd Hb].
subst; destruct (Hd Hev2) as [Hpoce2 Hpobe2].
assert (In _ (events E) (Eb s2)) as Heeb2.
apply po_iico_range_in_events with e2; auto.
rewrite <- (po_implies_same_proc Hwf Hee2 Heeb2 Hpobe2); trivial.
destruct Hcs2 as [HL2 [Heve2 [HUL2 Hib2]]].
destruct HUL2 as [Hur2 [Heb2 Hpobw2]].
generalize (Heve2 e2); intros [Hd Hb].
subst; destruct (Hd Hev2) as [Hpoce2 Hpobe2].
apply po_iico_range_in_events with e2; auto.
apply po_iico_range_in_events with e2; auto.
inversion Hor as [Haf | Hbef].
apply trc_ind with (Read s2).
apply lockc_rf_implies_in_ab_with_lwarx
with l s1; auto.
split; auto.
split; auto.
(* destruct Hcs2 as [HL2 [Hee2 [Hur2 [Heb2 Hpobw2]]]].
apply trc_step; destruct (Heb2 X) as [Hcumul Hbase];
apply (Hbase (Read s2) z); auto.
destruct (Hee2 e2) as [Hee2d Hee2b].
apply po_trans with (Ib s2); auto.
destruct HL2 as [? [? Hrc2]]; auto.
apply po_trans with e2; auto.
destruct (Hee2d Hev2); auto.
destruct (Hee2d Hev2); auto.
destruct_valid Hv; generalize (ran_rf_is_read E X (Write s1) (Read s2) Hrf_cands Hrf);
intros [lr [vr Har]] [[? [lr' [vr' Hwr]]] ?].
rewrite Hwr in Har; inversion Har. *)
destruct Hcs2 as [[Htk2 [Hib2 Hporb]] [? HUL2]].
destruct Htk2 as [? (*[*)Hat2 (*?]*)]; destruct_atom Hat2.
apply trc_step; apply (Hib2 X); auto.
apply po_trans with (Eb s2); auto.
destruct HUL2 as [? ?]; auto.
apply in_lockc_rf_case_implies_in_ab
with l; auto.
exists s1; exists s2.
split; auto.
split; auto.
split; auto.
split; auto.
destruct Hcs2 as [HL2 [Hee2 [HUL2 Hieb2]]].
destruct HUL2 as [Hur2 [Heb2 Hpobw2]].
destruct (Hee2 z) as [? Hee2b].
apply Hee2b; split; auto.
apply po_trans with e2; auto.
destruct (Hee2 e2) as [Hee2d ?].
destruct (Hee2d Hev2); auto.
apply trc_ind with e.
apply in_lockc_implies_in_ab with l; auto.
apply (IHHxy2 Hyz).
(*x in cs1 y in cs2 and y -po-> z
thus x -ab-> r2 by Bcumul of b1
and r2 -ab-> z by commit rule or lwsync base*)
Qed.
Lemma lockc_seq_po_ghb :
forall E X l x y,
well_formed_event_structure E ->
valid_execution E X ->
tc (rel_seq (lockc E X l) (po_iico E)) x y ->
tc (ghb E X) x y.
Proof.
intros E X l x y Hwf Hv Hxy.
induction Hxy as [x y Hs |].
destruct Hs as [z [Hxz Hzy]].
generalize (lockc_seq_po_in_ab Hwf Hv Hxz Hzy); apply tc_incl.
apply ab_in_ghb; auto.
apply trc_ind with z; auto.
Qed.
Lemma lockc_in_ghb :
forall E X l x y,
well_formed_event_structure E ->
valid_execution E X ->
lockc E X l x y ->
tc (ghb E X) x y.
Proof.
intros E X l x y Hwf Hv Hxy.
induction Hxy.
destruct_csslift H. destruct_css Hcss.
apply trc_ind with (Read s2).
assert (rel_incl (abc E X) (ghb E X)) as Hincl.
intros x y Hxy; apply ab_in_ghb; auto.
apply (tc_incl Hincl).
apply lockc_rf_implies_in_ab_with_lwarx
with l s1; auto.
split; auto. split; auto.
destruct Hcs2 as [[Hres2 [Hib2 Hporc2]] [Hee2 HUL2]].
assert (rel_incl (abc E X) (ghb E X)) as Hincl.
intros x y Hxy; apply ab_in_ghb; auto.
apply (tc_incl Hincl). apply trc_step.
(*destruct (Hib2 X) as [Hbase Hcumul].*)
generalize (Hib2 X); intro Hbase.
apply (Hbase (Read s2) e2); auto.
destruct_valid Hv; split.
apply (ran_rf_in_events X (Write s1) (Read s2) Hwf). split; auto. auto.
generalize (ran_rf_is_read E X (Write s1) (Read s2) Hrf_cands Hrf); intros [lr (*[vr*) Har(*]*)].
exists lr; (*exists vr;*) auto.
destruct Hres2 as [? (*[*)Hat2 (*?]*)]; destruct_atom Hat2; auto.
destruct (Hee2 e2) as [Hee2d Hee2b].
destruct (Hee2d Hev2); auto.
apply trc_ind with e; auto.
Qed.
Lemma lock_in_ghb :
forall E X x y,
well_formed_event_structure E ->
valid_execution E X ->
lock E X x y ->
tc (ghb E X) x y.
Proof.
intros E X x y Hwf Hv Hxy.
destruct Hxy as [l Hxy]; apply lockc_in_ghb with l; auto.
Qed.
Lemma tclock_in_ghb :
forall E X x y,
well_formed_event_structure E ->
valid_execution E X ->
tc (lock E X) x y ->
tc (ghb E X) x y.
Proof.
intros E X x y Hwf Hv Hxy.
induction Hxy.
apply lock_in_ghb; auto.
apply trc_ind with z; auto.
Qed.
Lemma lock_seq_po_ghb :
forall E X x y,
well_formed_event_structure E ->
valid_execution E X ->
tc (rel_seq (tc (lock E X)) (maybe (po_iico E))) x y ->
tc (ghb E X) x y.
Proof.
intros E X x y Hwf Hv Hxy.
induction Hxy as [x y Hs |].
destruct Hs as [z [Htc_xz Hor_zy]].
induction Htc_xz as [x z Hxz |].
destruct Hxz as [l Hxz].
inversion Hor_zy as [Hzy | Heq].
generalize (lockc_seq_po_in_ab Hwf Hv Hxz Hzy); apply tc_incl.
apply ab_in_ghb; auto.
subst; apply lockc_in_ghb with l; auto.
apply trc_ind with z.
apply tclock_in_ghb; auto.
apply (IHHtc_xz2 Hor_zy).
apply trc_ind with z; auto.
Qed.
Lemma lockc_po : forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
acyclic (rel_union (lockc E X l) (po_iico E)).
Proof.
intros E X l Hwf Hv x Hx.
rewrite union_triv in Hx.
generalize (lockc_irrefl); intro Hlir.
generalize (po_irrefl); intro Hpoir.
generalize (lockc_po_irrefl); intro Hlpoir.
generalize (lockc_trans); intro Hlt.
generalize (po_trans); intro Hpot.
generalize (union_cycle_implies_seq_cycle2 (Hpoir E Hwf) (Hlir E X l Hwf Hv) (Hlpoir E X l Hwf Hv) (Hlt E X l Hwf Hv) (Hpot E Hwf) Hx);
intros [y Hy].
generalize (lockc_seq_po_ghb Hwf Hv Hy); intro Hc.
destruct_valid Hv; unfold acyclic in Hvalid; unfold not in Hvalid; apply (Hvalid y Hc).
Qed.
Lemma lock_pop : forall E X,
well_formed_event_structure E ->
valid_execution E X ->
acyclic (rel_union (lock E X) (po_iico E)).
Proof.
intros E X Hwf Hv x Hx.
rewrite union_triv in Hx.
generalize (lock_irrefl); intro Hlir.
generalize (po_irrefl); intro Hpoir.
generalize (lock_po_irrefl); intro Hlpoir.
generalize (po_trans); intro Hpot.
generalize (union_cycle_implies_seq_cycle3 (Hpoir E Hwf) (Hlir E X Hwf Hv) (Hlpoir E X Hwf Hv) (Hpot E Hwf) Hx);
intros [y Hy].
generalize (lock_seq_po_ghb Hwf Hv Hy); intro Hc.
destruct_valid Hv; unfold acyclic in Hvalid; unfold not in Hvalid; apply (Hvalid y Hc).
Qed.
Lemma rf_irrefl :
forall E X,
well_formed_event_structure E ->
valid_execution E X ->
~(exists x, rf X x x).
Proof.
intros E X Hwf Hv [x Hx].
destruct_valid Hv.
generalize (dom_rf_is_write E X x x Hrf_cands Hx); intros [l [v Hwx]].
generalize (ran_rf_is_read E X x x Hrf_cands Hx); intros [l' [v' Hrx]].
rewrite Hrx in Hwx; inversion Hwx.
Qed.
Lemma lockc_rf_irrefl :
forall E X l,
well_formed_event_structure E ->
valid_execution E X ->
~(exists x, (rel_union (rf X) (lockc E X l)) x x).
Proof.
intros E X l Hwf Hv [x Hx]; inversion Hx.
assert (exists x, rf X x x) as He.
exists x; auto.
apply (rf_irrefl Hwf Hv He); auto.
assert (exists x, lockc E X l x x) as He.
exists x; auto.
apply (lockc_irrefl Hwf Hv He).
Qed.
Lemma rf_trans :
forall E X, well_formed_event_structure E ->
valid_execution E X ->
trans (rf X).
Proof.
intros E X Hwf Hv x y z Hxy Hyz.
destruct_valid Hv.
generalize (dom_rf_is_write E X y z Hrf_cands Hyz); intros [l [v Hwy]].
generalize (ran_rf_is_read E X x y Hrf_cands Hxy); intros [l' [v' Hry]].
rewrite Hry in Hwy; inversion Hwy.
Qed.
Axiom unic_css :
forall E l e,
forall cs1 cs2,
cs E l cs1 ->
cs E l cs2 ->
Evts cs1 e -> Evts cs2 e ->
cs1 = cs2.
Axiom cs_wf : forall E l c, cs E l c ->
(forall X, ~(exists w, fr E X (Read c) w /\ ws X w (Write c))).
Axiom cs_fr : (*provable from uniproc equivs*)
forall E X l c, cs E l c -> fr E X (Read c) (Write c).
Axiom diff_cs : forall E X l1 l2 c1 c2, cs E l1 c1 -> cs E l2 c2 ->
rf X (Write c1) (Read c2) -> c1 <> c2.
Axiom cs_diff : forall E cs1 cs2, cs1 <> cs2 ->
(forall e1 e2, Evts cs1 e1 -> Evts cs2 e2 -> e1 <> e2) /\
(forall l ws1 ws2, atom E (Read cs1) ws1 l -> atom E (Read cs2) ws2 l -> ws1 <> ws2).
Axiom no_other_stores : forall E l w, write_to w l -> (exists crit, cs E l crit /\ (Write crit) = w /\ exists e, Evts crit e).
Set Implicit Arguments.
Inductive nsteps (A:Set) (r:Rln A) : nat -> A -> A -> Prop :=
(* | rtriv : forall x y, x = y -> nsteps r 0 x y *)
| rintro : forall x y, r x y -> ~(exists z, r x z /\ r z y) -> nsteps r 1 x y
| rtrans : forall x y z n, r x y -> nsteps r n y z -> nsteps r (S n) x z.
Lemma n1_is_r : forall A r x y,
@nsteps A r 1 x y -> r x y.
Proof.
intros A r x y H1.
inversion H1; auto.
inversion H2.
Qed.
Definition discrete (A:Set) (r:Rln A) := forall x y, r x y -> exists n, nsteps r n x y. (*has a meaning only if r irrefl*)
Definition decr (A:Set) (r:Rln A) := forall x y n, nsteps r (S n) x y -> exists z, nsteps r 1 x z /\ nsteps r n z y.
Unset Implicit Arguments.
Axiom dis_ws : forall X, discrete (ws X).