-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAccessHistory.v
3184 lines (2949 loc) · 83.4 KB
/
AccessHistory.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
Require Tid.
Require Trace.
Require Node.
Require CG.
Require SJ_CG.
Require Import Coq.Lists.List.
Require Import Coq.Relations.Relation_Definitions.
Require Import Coq.Structures.OrderedTypeEx.
Require Import Coq.Relations.Relation_Operators.
Require Import Aniceto.Graphs.DAG.
Require Import Aniceto.Graphs.Graph.
Require Import Aniceto.Graphs.FGraph.
Require Import HJ.Mid.
(* ----- end of boiler-plate code ---- *)
Set Implicit Arguments.
Section Defs.
(**
Access history records for each memory id: all the accesses to memory.
An access consists of the causality event that performed the access
and the kind of address, which can be either a read or a write,
and in the case of a write, the written data.
Let [A] be the type of the data. *)
Variable A:Type.
(** And [E] be the type of the causality event. *)
Variable E:Type.
(** As usual, an event [E] is ordered by a causality relation [Lt]
that is a pre-order, thus transitive and irreflexive. *)
Variable Lt: E -> E -> Prop.
Variable lt_trans:
forall x y z,
Lt x y ->
Lt y z ->
Lt x z.
Variable lt_irrefl:
forall x,
~ Lt x x.
(** An [access] pairs an event of type [E] with a payload
which is either [None] for a read or [Some d] for a store
*)
Notation payload := (option A).
Definition access := (E * payload) % type.
(** Rename fst and snd to more understandable terms. *)
Definition a_when := @fst E payload.
Definition a_what := @snd E payload.
(** Some notation to operate over accesses. *)
Notation HB a b := (Lt (a_when a) (a_when b)).
Notation MHP a b := (~ HB a b /\ ~ HB b a).
Notation HBE a b := (HB a b \/ a_when a = a_when b).
(** Again, a [Write] holds some data. *)
Inductive Write: access -> Prop :=
| write_some:
forall n x,
Write (n, Some x).
(** Otherwise, we have a read. *)
Definition Read a := ~ Write a.
(** An access history records all the saccesses for each
memory id. *)
Definition access_history := MM.t (list access).
(** An empty access history. *)
Definition empty : access_history := MM.empty (list access).
(** The standard definition of a race: the events are concurrent
and there is at least one write. *)
Inductive RacyAccess : access -> access -> Prop :=
| racy_access_def:
forall a b,
a_when a <> a_when b ->
(Write a \/ Write b) ->
MHP a b ->
RacyAccess a b.
(** Race-free accesses are trivially defined. *)
Definition RaceFreeAccess a b := ~ RacyAccess a b.
(** Finally a race-free history is such that two accesses
in the same memory location are race free. *)
Definition RaceFreeHistory ah :=
forall r l a b,
MM.MapsTo r l ah ->
List.In a l ->
List.In b l ->
RaceFreeAccess a b.
Ltac expand H := inversion H; subst; clear H.
(* begin hide *)
Lemma racy_access_irrefl_when:
forall (a b:access),
a_when a = a_when b ->
~ RacyAccess a b.
Proof.
unfold not; intros.
inversion H0.
contradiction.
Qed.
Lemma racy_access_irrefl:
forall (a:access),
~ RacyAccess a a.
Proof.
intros.
assert (a_when a = a_when a) by trivial; eauto using racy_access_irrefl_when.
Qed.
(* end hide *)
(** If the same event performs multiple reads or multiple writes,
these are race-free (as there is no concurrency in this case).
The rest are usual properties of race-free accesses (reflexivity,
symmetry, reads do not race with each order, and
ordered accesses do not race with each other. These properties
are necessary since we defined a race-free access by negating
a racy access. *)
Lemma race_free_access_refl_when:
forall (a b:access),
a_when a = a_when b ->
RaceFreeAccess a b.
Proof.
unfold RaceFreeAccess.
auto using racy_access_irrefl_when.
Qed.
Lemma race_free_access_refl:
forall (a:access),
RaceFreeAccess a a.
Proof.
unfold RaceFreeAccess.
auto using racy_access_irrefl.
Qed.
(* begin hide *)
(* Notation Ordered a b := (HB a b \/ HB b a). *)
(* end hide *)
Lemma race_free_access_read:
forall (a:access) b,
Read a ->
Read b ->
RaceFreeAccess a b.
Proof.
intros.
unfold RaceFreeAccess, not; intros.
inversion H1.
destruct H3; auto.
Qed.
Lemma race_free_access_hb:
forall a b,
HB a b ->
RaceFreeAccess a b.
Proof.
unfold RaceFreeAccess, not; intros.
inversion H0; subst; clear H0.
destruct H3.
contradiction.
Qed.
Lemma race_free_access_hbe:
forall a b,
HBE a b ->
RaceFreeAccess a b.
Proof.
intros.
destruct H.
- auto using race_free_access_hb.
- subst.
auto using race_free_access_refl_when.
Qed.
(* begin hide *)
Let mhp_symm:
forall a b,
MHP a b ->
MHP b a.
Proof.
intros.
destruct H.
auto.
Qed.
(* end hide *)
Lemma racy_access_symm:
forall a b,
RacyAccess a b ->
RacyAccess b a.
Proof.
intros.
inversion H; subst.
destruct H1;
apply racy_access_def; auto.
Qed.
Lemma race_free_access_symm:
forall a b,
RaceFreeAccess a b ->
RaceFreeAccess b a.
Proof.
unfold RaceFreeAccess, not in *; intros.
apply racy_access_symm in H0; contradiction.
Qed.
Lemma read_none:
forall n,
Read (n, None).
Proof.
intros.
unfold Read, not; intros.
inversion H.
Qed.
Lemma write_dec:
forall a,
{ Write a } + { Read a }.
Proof.
intros.
destruct a as (?,[]).
- auto using write_some.
- right; unfold Read, not; intros.
inversion H.
Defined.
End Defs.
(* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)
Section LastWrites.
(**
The theory of race-free-adds defines sufficient conditions to
maintain a data race-free access-history.
*)
Variable A:Type.
Variable E:Type.
Variable Lt: E -> E -> Prop.
Variable lt_trans:
forall (x y z:E),
Lt x y ->
Lt y z ->
Lt x z.
Variable lt_irrefl:
forall (x:E),
~ Lt x x.
Notation HB a b := (Lt (@a_when A E a) (@a_when A E b)).
Notation MHP a b := (~ HB a b /\ ~ HB b a).
Notation HBE a b := (HB a b \/ @a_when A E a = @a_when A E b).
(** As we need to state definition in terms of the reads and the writes,
let us define a predicate for all reads/writes. *)
Definition ForallWrites (P : access A E -> Prop) l : Prop :=
forall a,
List.In a l ->
Write a ->
P a.
Definition ForallReads (P: access A E -> Prop) l : Prop :=
forall a,
List.In a l ->
Read a ->
P a.
(** The last write *)
Inductive LastWrite (a:access A E) (l:list (access A E)) : Prop :=
| last_write_def:
Write a ->
List.In a l->
ForallWrites (fun b => HBE b a) l ->
LastWrite a l.
Inductive MapsTo r (x:A) ah : Prop :=
| maps_to_def:
forall a l,
MM.MapsTo r l ah ->
LastWrite a l ->
a_what a = Some x ->
MapsTo r x ah.
(** A write-safe access happens before all writes *)
(*
Inductive WriteSafe (a:access A E) l : Prop :=
| write_safe_def:
forall w,
(* take the last-write *)
LastWrite w l ->
(* the access must succeed the last-write *)
HBE w a ->
WriteSafe a l.
*)
(** A read-safe happens before all reads. *)
Definition WriteSafe (a:access A E) l := ForallWrites (fun b => HBE b a) l.
Definition ReadSafe (a:access A E) l := ForallReads (fun b => HBE b a) l.
(**
We distinguish between createion, reading and writing.
*)
Inductive op_type := READ | WRITE.
Definition op := (op_type * A) % type.
(*
W_x \subseteq n
----------------------
(R, W) ==>rd(n, x) (R{x += n}, W)
W_x \subseteq n
R_x \subseteq n
----------------------
(R, W) ==>wr(n, x) (R, W{x += n})
*)
Definition unsafe_add r a (ah:access_history A E) :=
let h := (match MM.find r ah with
| None => nil
| Some h => h
end) in
MM.add r (a::h) ah.
Inductive Add: access_history A E -> (mid * E * op) -> access_history A E -> Prop :=
| add_alloc:
forall g r d n,
~ MM.In r g ->
(* update the shared memory to record the allocation *)
Add g (r, n, (WRITE, d)) (MM.add r ((n, Some d)::nil) g)
| add_read:
forall g l (n n':E) r d,
MM.MapsTo r l g ->
(* The read is ordered wrt the reads *)
WriteSafe (n, None) l ->
(* Get the value of the last write *)
LastWrite (n', Some d) l ->
(* update the shared memory to record the read *)
Add g (r, n, (READ, d)) (MM.add r ((n, None)::l) g)
| add_write:
forall g r d n l,
(* update the shared memory to record the read *)
MM.MapsTo r l g ->
WriteSafe (n, Some d) l ->
ReadSafe (n, Some d) l ->
Add g (r, n, (WRITE, d)) (MM.add r ((n, Some d)::l) g).
Lemma hbe_trans:
forall x y z,
HBE x y ->
HBE y z ->
HBE x z.
Proof.
intros.
destruct H, H0, x, y, z; simpl in *; subst;
eauto.
Qed.
Let last_write_to_forall_writes:
forall c a l,
LastWrite c l ->
HBE c a ->
ForallWrites (fun b : access A E => HBE b a) l.
Proof.
intros.
inversion H; subst; clear H.
unfold ForallWrites; intros.
apply H3 in H4; auto.
eapply hbe_trans; eauto.
Qed.
Theorem add_read_alt:
forall g l (n n':E) r d,
MM.MapsTo r l g ->
(* same as [WriteSafe] *)
LastWrite (n', Some d) l ->
Lt n' n ->
(* update the shared memory to record the read *)
Add g (r, n, (READ, d)) (MM.add r ((n, None)::l) g).
Proof.
intros.
apply add_read with (n':=n'); auto.
eapply last_write_to_forall_writes; eauto.
Qed.
(*
Lemma write_safe_alt:
forall n d l n',
ForallWrites (fun b : access A E => HBE b (n, None)) l ->
LastWrite (n', Some d) l ->
WriteSafe (n, None) l.
Proof.
intros.
apply write_safe_def with (w:=(n', Some d)); auto.
inversion H0; subst; clear H0.
apply H in H1; auto.
Qed.
*)
Theorem add_write_alt:
forall g r d n w l,
(* update the shared memory to record the read *)
MM.MapsTo r l g ->
(* take the last-write *)
LastWrite w l ->
(* the access must succeed the last-write *)
HBE w (n, Some d) ->
(* the write must also be safe wrt all reads *)
ReadSafe (n, Some d) l ->
Add g (r, n, (WRITE, d)) (MM.add r ((n, Some d)::l) g).
Proof.
intros.
apply add_write; auto.
inversion H0.
eapply last_write_to_forall_writes; eauto.
Qed.
(* begin hide *)
(*
Inductive RaceFreeAdd: access_history A E -> (mid * E * op) -> access_history A E -> Prop :=
| race_free_add_alloc:
forall g r d n,
~ MM.In r g ->
(* update the shared memory to record the allocation *)
RaceFreeAdd g (r, n, (WRITE, d)) (MM.add r ((n, Some d)::nil) g)
| race_free_read:
forall g l (n n':E) r d,
MM.MapsTo r l g ->
(* same as [WriteSafe] *)
LastWrite (n', Some d) l ->
Lt n' n ->
(* update the shared memory to record the read *)
RaceFreeAdd g (r, n, (READ, d)) (MM.add r ((n, None)::l) g)
| race_free_write:
forall g r d n l,
(* update the shared memory to record the read *)
MM.MapsTo r l g ->
(* make sure the write is safe with other writes in l *)
WriteSafe (n, Some d) l ->
(* the write must also be safe wrt all reads *)
ReadSafe (n, Some d) l ->
RaceFreeAdd g (r, n, (WRITE, d)) (MM.add r ((n, Some d)::l) g).
*)
Let last_write:
forall (a:access A E) b l,
LastWrite b l ->
Write a ->
List.In a l ->
HBE a b.
Proof.
intros.
inversion H.
eauto.
Qed.
Let last_write_absurd_nil:
forall (a:access A E),
~ LastWrite a nil.
Proof.
unfold not; intros.
inversion H.
inversion H1.
Qed.
Let in_last_write:
forall l a b,
List.In a l ->
LastWrite b l ->
Read (A:=A) a \/ (Write a /\ HBE a b).
Proof.
intros.
inversion H0; clear H0.
unfold ForallWrites in *; simpl in *.
destruct (write_dec a); auto.
Qed.
Lemma forall_writes_inv:
forall P l (a:access A E),
ForallWrites P (a :: l) ->
ForallWrites P l /\ (Write a -> P a).
Proof.
intros.
unfold ForallWrites in *.
rewrite <- Forall_forall in *.
inversion H; subst; auto.
Qed.
Lemma forall_writes_inv_cons:
forall P l (a:access A E),
ForallWrites P (a :: l) ->
ForallWrites P l.
Proof.
intros.
apply forall_writes_inv in H; destruct H.
auto.
Qed.
Lemma forall_writes_cons_read:
forall P l (a:access A E),
Read a ->
ForallWrites P l ->
ForallWrites P (a :: l).
Proof.
intros.
unfold ForallWrites; intros b; intros.
inversion H1; subst; clear H1. {
contradiction.
}
auto.
Qed.
Lemma forall_writes_cons_write:
forall (P:access A E -> Prop) l (a:access A E),
Write a ->
P a ->
ForallWrites P l ->
ForallWrites P (a :: l).
Proof.
intros.
unfold ForallWrites; intros b; intros.
inversion H2; subst; clear H2. {
assumption.
}
auto.
Qed.
Lemma forall_reads_inv:
forall P l (a:access A E),
ForallReads P (a :: l) ->
ForallReads P l /\ (Read a -> P a).
Proof.
intros.
unfold ForallReads in *.
rewrite <- Forall_forall in *.
inversion H; subst; auto.
Qed.
Lemma forall_reads_inv_cons:
forall P l (a:access A E),
ForallReads P (a :: l) ->
ForallReads P l.
Proof.
intros.
apply forall_reads_inv in H; destruct H.
auto.
Qed.
Let last_write_inv_read:
forall l (a:access A E) b,
Read a ->
LastWrite b (a :: l) ->
LastWrite b l.
Proof.
induction l; intros. {
inversion H0.
inversion H2; subst; clear H2. {
contradiction.
}
inversion H4.
}
inversion H0; subst; clear H0.
inversion H2; subst; clear H2. {
contradiction.
}
inversion H0; subst; clear H0. {
eauto using last_write_def, in_eq, forall_writes_inv_cons.
}
apply forall_writes_inv_cons in H3.
auto using last_write_def, in_cons.
Qed.
Let last_write_hbe:
forall (x:access A E) y l,
LastWrite x l ->
LastWrite y l ->
HBE x y.
Proof.
intros.
inversion H0.
inversion H.
apply last_write with (l:=l); auto.
Qed.
Let last_write_inv:
forall a (b:access A E) l,
LastWrite a (b :: l) ->
(b = a /\ ForallWrites (fun c => HBE c a) l) \/
(LastWrite a l /\ (Write b -> HBE b a)).
Proof.
intros.
inversion H; subst; clear H.
destruct H1. {
apply forall_writes_inv_cons in H2.
auto.
}
right.
apply forall_writes_inv in H2.
destruct H2 as (Hf, Hi).
eauto using last_write_def.
Qed.
Let in_last_write_write:
forall l (a:access A E) b,
List.In a l ->
Write a ->
LastWrite b l ->
HBE a b.
Proof.
intros.
eapply in_last_write in H1; eauto.
destruct H1; try contradiction.
destruct H1.
assumption.
Qed.
(* end hide *)
(** EXPORTED *)
Theorem last_write_inv_cons_nil:
forall (a b:access A E),
LastWrite a (b::nil) ->
a = b.
Proof.
intros.
inversion H.
destruct H1. {
auto.
}
inversion H1.
Qed.
Lemma last_write_inv_cons_read:
forall (a:access A E) n l,
LastWrite a ((n,None)::l) ->
LastWrite a l.
Proof.
intros.
inversion H; subst; clear H.
destruct H1; subst. {
inversion H0.
}
assert (ForallWrites (fun b : access A E => HBE b a) l). {
unfold ForallWrites in *; eauto using in_cons.
}
eauto using last_write_def.
Qed.
(* begin hide *)
Let hb_neq:
forall (a:access A E) b,
HB a b ->
a <> b.
Proof.
unfold not; intros.
subst.
apply lt_irrefl in H.
assumption.
Qed.
Let hbe_eq_when_left:
forall (x y z:access A E),
HBE x z ->
a_when y = a_when x ->
HBE y z.
Proof.
intros.
rewrite H0.
assumption.
Qed.
Let hb_eq_when_left:
forall (x y z:access A E),
HB x z ->
a_when y = a_when x ->
HB y z.
Proof.
intros.
rewrite H0.
assumption.
Qed.
Let hbe_hb_hb_trans:
forall (a b c:access A E),
HBE a b ->
HB b c ->
HB a c.
Proof.
intros.
destruct H; subst; eauto.
Qed.
Let write_safe:
forall (a:access A E) b l,
LastWrite a l ->
WriteSafe b l ->
HBE a b.
Proof.
intros.
inversion H; subst.
apply hbe_trans with (y:=a); eauto.
Qed.
Let write_safe_hbe:
forall (a b:access A E) l,
List.In a l ->
Write a ->
WriteSafe b l ->
HBE a b.
Proof.
intros.
auto.
Qed.
Let read_write_safe:
forall (a b:access A E) l,
List.In b l ->
WriteSafe a l ->
ReadSafe a l ->
HBE b a.
Proof.
intros.
destruct (write_dec b); eauto.
Qed.
Let read_in_write_safe_race_free:
forall (a b:access A E) l,
List.In a l ->
Read b ->
WriteSafe b l ->
RaceFreeAccess Lt a b.
Proof.
intros.
destruct (write_dec a). {
eauto using race_free_access_hbe, race_free_access_symm.
}
eauto using race_free_access_read.
Qed.
(* end hide *)
Lemma last_write_inv_cons_write:
forall (a:access A E) n l d,
WriteSafe (n,Some d) l ->
LastWrite a ((n,Some d)::l) ->
n = a_when a.
Proof.
intros.
inversion H0; subst; clear H0.
destruct H2. {
subst.
auto.
}
apply forall_writes_inv in H3.
destruct H3 as (_,Hi).
assert (Hx : Write (n, Some d)) by auto using write_some.
apply Hi in Hx.
destruct Hx. {
assert (HBE a (n, Some d)) by eauto using write_safe_hbe.
assert (HB a a) by eauto.
apply lt_irrefl in H4.
contradiction.
}
auto.
Qed.
Lemma last_write_inv_cons:
forall l (a b:access A E),
LastWrite a (b::l) ->
a = b \/ ((Write b -> HBE b a) /\ LastWrite a l).
Proof.
induction l; intros. {
auto using last_write_inv_cons_nil.
}
apply last_write_inv in H.
destruct H as [(?,?)|(?,?)]; auto.
Qed.
Lemma last_write_cons_read:
forall (a:access A E) n l,
LastWrite a l ->
LastWrite a ((n,None)::l).
Proof.
intros.
inversion H; subst.
apply last_write_def; auto using in_cons.
unfold ForallWrites in *.
intros.
destruct H3. {
subst.
inversion H4.
}
auto.
Qed.
(* begin hide *)
Let last_write_trans:
forall (x y z:access A E) l,
LastWrite x l ->
LastWrite y l ->
HB x z ->
HB y z.
Proof.
intros.
assert (Hx: HBE y x) by eauto.
destruct Hx. {
eauto.
}
subst.
eauto.
Qed.
(* end hide *)
Lemma last_write_to_write:
forall (a:access A E) h,
LastWrite a h ->
Write a.
Proof.
intros.
inversion H; auto.
Qed.
(** *EXPORTED* *)
Theorem last_write_to_in:
forall (a:access A E) h,
LastWrite a h ->
List.In a h.
Proof.
intros; inversion H; auto.
Qed.
Lemma last_write_cons_write:
forall e d h,
WriteSafe (e, Some d) h ->
LastWrite (e, Some d) ((e, Some d) :: h).
Proof.
auto using last_write_def, write_some, in_eq, forall_writes_cons_write.
Qed.
Lemma last_write_cons_write_2:
forall a h,
Write a ->
WriteSafe a h ->
LastWrite a (a :: h).
Proof.
intros.
inversion H; subst.
auto using last_write_cons_write.
Qed.
Lemma forall_writes_reads_to_last_write:
forall h n d,
ForallWrites (fun b => HBE b (n, Some d)) h ->
ForallReads (fun b => HBE b (n, Some d)) h ->
LastWrite (n, Some d) ((n, Some d)::h).
Proof.
intros.
apply last_write_def; auto using in_eq, write_some.
unfold ForallWrites; intros.
inversion H1; subst; clear H1. {
auto.
}
apply H in H2; auto.
Qed.
Lemma write_safe_inv_in:
forall (a b:access A E) l,
WriteSafe a l ->
List.In b l ->
Read b \/ HBE b a.
Proof.
intros.
apply H in H0.
destruct (write_dec b); auto.
Qed.
Lemma read_safe_inv_in:
forall (a b:access A E) l,
ReadSafe a l ->
List.In b l ->
Write b \/ HBE b a.
Proof.
intros.
unfold ReadSafe in H.
apply H in H0.
destruct (write_dec b). {
auto.
}
auto.
Qed.
Lemma read_write_safe_inv_in:
forall (a b:access A E) l,
ReadSafe a l ->
WriteSafe a l ->
List.In b l ->
HBE b a.
Proof.
intros.
assert (Hx := H1).
apply read_safe_inv_in with (a:=a) in H1; auto.
apply write_safe_inv_in with (a:=a) in Hx; auto.
destruct H1, Hx; try contradiction; auto.
Qed.
Lemma write_safe_read_to_race_free:
forall (a b:access A E) l,
List.In b l ->
Read a ->
WriteSafe a l ->
RaceFreeAccess Lt a b.
Proof.
intros.
eapply write_safe_inv_in in H; eauto.
destruct H.
+ auto using race_free_access_read.
+ auto using race_free_access_hbe, race_free_access_symm.
Qed.
Lemma add_fun:
forall ah o ah1 ah2,
Add ah o ah1 ->
Add ah o ah2 ->
ah1 = ah2.
Proof.
intros.
inversion H; subst; clear H;
inversion H0; subst; clear H0.
+ auto.
+ contradiction H1.
eauto using MM_Extra.mapsto_to_in.
+ assert (l0 = l) by eauto using MM_Facts.MapsTo_fun; subst.
trivial.
+ contradiction H8.
eauto using MM_Extra.mapsto_to_in.
+ assert (l0 = l) by eauto using MM_Facts.MapsTo_fun; subst.
trivial.
Qed.
End LastWrites.
(* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)
Section OrderedAdds.
Variable A:Type.
Variable E:Type.
Variable Lt: E -> E -> Prop.
Variable lt_irrefl:
forall x,
~ Lt x x.
Variable lt_trans:
forall x y z,
Lt x y ->
Lt y z ->
Lt x z.
Inductive OrderedAdds : list (access A E) -> Prop :=
| ordered_adds_nil:
forall a,
Write a ->
OrderedAdds (a :: nil)
| ordered_adds_read:
forall a l,
Read a ->
OrderedAdds l ->
WriteSafe Lt a l ->
OrderedAdds (a :: l)
| ordered_adds_write:
forall a l,
Write a ->