-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhierarchy.v
executable file
·2335 lines (1948 loc) · 75.2 KB
/
hierarchy.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 Bool.
From CoqCat Require Import util.
From CoqCat Require Import wmm.
From CoqCat Require Import basic.
Set Implicit Arguments.
Axiom excluded_middle : forall (A:Prop), A \/ ~A.
Definition bimpl (b1 b2:bool) : Prop:=
if (negb b1) || b2 then True else False.
(* Module Hierarchy. *)
(** * Memory models comparison
In this file, we define the notion of _comparison_ between memory models. In
particular, we define what it means for a model to be weaker than another model.
The module [Weaker] takes two architectures and a dependencies module as
parameters, and defines a predicate [weaker] that is true when the first
architecture is weaker than the second.
It then states different kind of variations of these architectures, and lemmas
about how they compare.
*)
Module Weaker (A1 A2 : Archi) (dp:Dp).
(** ** Definition of [weaker] *)
(** We define for both A1 and A2 a relation bot_ghb that corresponds to the
union of the write serialization, from-read and preserved program order
(according to A1 or A2 respectively). This relation corresponds to the
instanciation of [bot_ghb] for each architecture, if we consider the barrier
relation to be empty for both architectures *)
Definition bot_ghb1 (E:Event_struct) (X:Execution_witness) :=
(rel_union (rel_union (ws X) (fr E X)) (A1.ppo E)).
Definition bot_ghb2 (E:Event_struct) (X:Execution_witness) :=
(rel_union (rel_union (ws X) (fr E X)) (A2.ppo E)).
(* Definition rf_impl (rf1 rf2 : bool) :=
bimpl rf1 rf2. *)
(** The preserved program order of a first architecture is included in the one
of a second architecture if for any event structure, the preserved program order
relation produced by the first architecture is included in the preserved program
order relation produced by the second architecture *)
Definition ppo_incl (ppo1 ppo2 : Event_struct -> Rln Event) :=
forall E, rel_incl (ppo1 E) (ppo2 E).
(** A first architecture is weaker than a second one, if:
- The preserved program order of the first architecture is included in the
preserved program order of the second architecture
- Every subset of read-from considered non-global in the first architecture is
also considered non-global in the second architecture. In other words, the
global read-from of the first architecture is included in the global read-from
of the second architecture *)
Definition weaker :=
ppo_incl (A1.ppo) (A2.ppo) /\
bimpl (A1.intra) (A2.intra) /\
bimpl (A1.inter) (A2.inter) .
Ltac destruct_wk H :=
destruct H as [Hppoi [Hrfii Hrfei]].
Import A1. Import A2. Import dp.
(** We import the basic facts about these two architectures *)
Module A1Basic := Basic A1 dp.
Import A1Basic.
Module A2Basic := Basic A2 dp.
Import A2Basic.
(** We build the weak memory models corresponding to these two architectures *)
Module A1Wmm := Wmm A1 dp.
Import A1Wmm.
Module A2Wmm := Wmm A2 dp.
Import A2Wmm.
(** ** Architectures without barriers
A1n and A2n are two variants of respectively A1 and A2 where we consider that
there are no barriers on the architectures *)
Module A1n <: Archi.
(** The notion of preserved program order is identical to the one of A1 *)
Definition ppo := A1.ppo.
Lemma ppo_valid : forall E, rel_incl (ppo E) (po_iico E).
Proof.
apply A1.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 A1.ppo_fun.
Qed.
(** The part of read-from that are global are the same than in A1 *)
Definition inter := A1.inter.
Definition intra := A1.intra.
(** There are no events related by the barrier relation *)
Definition abc (E:Event_struct) (X:Execution_witness) : Rln Event :=
fun e1 => fun e2 => False.
(** The necessary property on the events related by the barrier relation is
trivial since no events are related by the relation *)
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.
(** Since the barrier relation is empty, it is trivially included in the transitive closure of the union of communication relation and program order for any event structure and any execution witness *)
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.
(* As in wmm, what this represents is not really clear, and it is used nowhere
so I comment it, but we should eventually clarify what it means *)
(*
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 ? ?; split.
intros [Hxy ?]; inversion Hxy.
intro Hxy; inversion Hxy.
Qed.
*)
Parameter stars : Event_struct -> set Event.
End A1n.
(** The A2n module is exactly the same as A1n, except A1 is replaced by A2 *)
Module A2n <: Archi.
(** The notion of preserved program order is identical to the one of A2 *)
Definition ppo := A2.ppo.
Lemma ppo_valid : forall E, rel_incl (ppo E) (po_iico E).
Proof.
apply A2.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 A2.ppo_fun.
Qed.
(** The part of read-from that are global are the same than in A2 *)
Definition inter := A2.inter.
Definition intra := A2.intra.
(** There are no events related by the barrier relation *)
Definition abc (E:Event_struct) (X:Execution_witness) : Rln Event :=
fun e1 => fun e2 => False.
(** The necessary property on the events related by the barrier relation is
trivial since no events are related by the relation *)
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.
(** Since the barrier relation is empty, it is trivially included in the transitive closure of the union of communication relation and program order for any event structure and any execution witness *)
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.
(* As in wmm, what this represents is not really clear, and it is used nowhere
so I comment it, but we should eventually clarify what it means *)
(* 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 init s x y; split.
intros [Hxy ?]; inversion Hxy.
intro Hxy; inversion Hxy.
Qed.
*)
Parameter stars : Event_struct -> set Event.
End A2n.
Import A1n. Import A2n. Import dp.
(** We import basic facts about A1n and A2n *)
Module A1nBasic := Basic A1n dp.
Import A1nBasic.
Module A2nBasic := Basic A2n dp.
Import A2nBasic.
(** We build the memory models corresponding to A1n and A2n *)
Module A1nWmm := Wmm A1n dp.
Import A1nWmm.
Module A2nWmm := Wmm A2n dp.
Import A2nWmm.
(** ** Characterisation
We characterise how validity is preserved or not preserved between two memory
models based on two architectures, such that one is weaker than the other *)
Section Char.
(** We define [check] as the acyclicity of the union of the global read-from
of the memory model based on A2n, and of [bot_ghb2].
This union corresponds to the global happens-before ([ghb]) of the memory model
based on A2n (as stated later by [ghb2_eq])
Thus, this acyclicity condition corresponds to the third part of the conditions
of [valid_execution] (the two others being out-of-thin-air and uniproc
conditions.
NOTE: In this definition, [mrf] corresponds to [A2nWmm.mrf]
*)
Definition check (E:Event_struct) (X:Execution_witness) :=
acyclic (rel_union (mrf X) (bot_ghb2 E X)).
(** If A1 is weaker than A2, [bot_ghb1] is included in [bot_ghb2]. *)
Lemma bot_ghb_incl :
forall E X,
weaker ->
rel_incl (bot_ghb1 E X) (bot_ghb2 E X).
Proof.
unfold bot_ghb1; unfold bot_ghb2;
intros E X H12 x y Hxy;
destruct_wk H12.
inversion Hxy as [Hws_fr | Hre].
left; auto.
right; apply (Hppoi E x y Hre).
Qed.
(**
The global happens-before of A2n is equal to the union of its [mhb] (its happens
before relation where only global read-froms are considered) and of its
preserved program order.
NOTE: In this lemma, [ghb] corresponds to [A2nWmm.ghb]
*)
Lemma ghb2_is_mhb_ppo2 :
forall E X,
ghb E X = rel_union (mhb E X) (A2.ppo E).
Proof.
case_eq inter; case_eq intra; intros Hinter Hintra;
unfold ghb; unfold mhb; rewrite Hinter; rewrite Hintra;
unfold abc; intros E X; apply ext_rel; split; intro Hxy; auto.
inversion Hxy as [Hrfe | Hr].
left; left; auto.
inversion Hr as [Hrfi | Hre].
left; right; left; auto.
inversion Hre as [Ht | Hres].
inversion Ht.
inversion Hres as [Hws_fr | Hppo].
left; right; right; auto.
right; auto.
inversion Hxy as [Hr | Hppo].
inversion Hr as [Hrfe | Hre].
left; auto.
inversion Hre as [Hrfi | Hws_fr].
right ; left; auto.
right; right; right; left; auto.
right; right; right; right; auto.
inversion Hxy as [Hrfi | Hr].
left; left; auto.
inversion Hr as [Ht | Hre].
inversion Ht.
inversion Hre as [Hws_fr | Hppo].
left; right; auto.
right; auto.
inversion Hxy as [Hr | Hppo].
inversion Hr as [Hrfi | Hre].
left; auto.
right; right; left; auto.
right; right; right; auto.
inversion Hxy as [Hrfi | Hr].
left; left; auto.
inversion Hr as [Ht | Hre].
inversion Ht.
inversion Hre as [Hws_fr | Hppo].
left; right; auto.
right;auto.
inversion Hxy as [Hr | Hppo].
inversion Hr as [Hrfi | Hre].
left; auto.
right; right; left; auto.
right; right; right; auto.
inversion Hxy as [Ht | Hre].
inversion Ht.
inversion Hre as [Hws_fr | Hppo].
left; auto.
right; auto.
inversion Hxy as [Hws_fr | Hppo].
right; left; auto.
right; right; auto.
Qed.
(**
The global happens-before of A2n corresponds to the union of its global
read-from and of [bot_ghb2].
NOTE: In this lemma, [mrf] corresponds to [A2nWmm.mrf]
*)
Lemma ghb2_eq :
forall E X,
ghb E X = rel_union (mrf X) (bot_ghb2 E X).
Proof.
case_eq inter; case_eq intra; intros Hinter Hintra;
unfold ghb; unfold mrf; unfold mrfe; unfold mrfi; rewrite Hinter; rewrite Hintra;
unfold bot_ghb2;
unfold abc; intros E X; apply ext_rel; split; intro Hxy; auto.
inversion Hxy as [Hrfe | Hr].
left; simpl; right; auto.
inversion Hr as [Hrfi | Hre].
left; simpl; left; auto.
inversion Hre as [Ht | Hres].
inversion Ht.
right; auto.
inversion Hxy as [Hrf | Hor].
inversion Hrf as [Hrfi | Hrfe].
right; simpl; left; auto.
left; auto.
right; right; right; auto.
inversion Hxy as [Hrfi | Hor].
left; right; auto.
inversion Hor as [Ht | Hbghb].
inversion Ht.
right; auto.
inversion Hxy as [Hrf | Hr].
inversion Hrf as [Hrfi | Hrfe].
inversion Hrfi.
left; auto.
right; right;auto.
inversion Hxy as [Hrfi | Hor].
left; left; auto.
inversion Hor as [Ht | Hbghb].
inversion Ht.
right; auto.
inversion Hxy as [Hrf | Hor].
inversion Hrf as [Hrfi | Hrfe].
left; auto.
inversion Hrfe.
right; right; auto.
inversion Hxy as [Ht | Hre].
inversion Ht.
right; auto.
inversion Hxy as [Hort | Hor].
inversion Hort; inversion H.
right; auto.
Qed.
(** If A1 is weaker than A2, the global happens-before of A1n is included in the
global happens-before of A2n. *)
Lemma ghb_incl :
forall E X,
weaker ->
rel_incl (A1nWmm.ghb E X) (A2nWmm.ghb E X).
Proof.
intros E X; rewrite (ghb2_eq E X).
unfold A1nWmm.ghb; unfold A1n.ppo; unfold mrf; unfold mrfe; unfold mrfi;
intros H12 x y Hxy; case_eq inter; case_eq intra;
intros Hintra2 Hinter2; case_eq A1n.inter; case_eq A1n.intra;
intros Hintra1 Hinter1; rewrite Hintra1 in *; rewrite Hinter1 in *.
(*A1 : true true ; A2 : true true*)
inversion Hxy as [Hrfi | Hr].
left; right; auto.
inversion Hr as [Hrfi | Hre].
left; left; auto.
inversion Hre as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb1 E X) in Hres.
apply bot_ghb_incl; auto.
(*A1 : false true ; A2 : true true*)
inversion Hxy as [Hrfe | Hr].
left; right; auto.
inversion Hr as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hr;
apply bot_ghb_incl; auto.
(*A1 : true false ; A2 : true true*)
inversion Hxy as [Hrfi | Hr].
left; left; auto.
inversion Hr as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hr;
apply bot_ghb_incl; auto.
(*A1 : false false ; A2 : true true*)
inversion Hxy as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hres;
apply bot_ghb_incl; auto.
(*A1 : true true ; A2 : false true*)
destruct H12 as (*[?*) [? [Himpl ?]](*]*).
unfold A1n.intra in Hintra1; unfold A2n.intra in Hintra2;
rewrite Hintra1 in Himpl; rewrite Hintra2 in Himpl; inversion Himpl.
(*A1 : false true ; A2 : false true*)
inversion Hxy as [Hrfe | Hr].
left; right; auto.
inversion Hr as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hres;
apply bot_ghb_incl; auto.
(*A1 : true false ; A2 : false true*)
destruct H12 as (*[?*) [? [Himpl ?]] (*]*).
unfold A1n.intra in Hintra1; unfold A2n.intra in Hintra2;
rewrite Hintra1 in Himpl; rewrite Hintra2 in Himpl; inversion Himpl.
(*A1 : false false ; A2 : false true*)
inversion Hxy as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hres;
apply bot_ghb_incl; auto.
(*A1 : true true ; A2 : true false *)
destruct_wk H12.
unfold A1n.inter in Hinter1; unfold A2n.inter in Hinter2;
rewrite Hinter1 in Hrfei; rewrite Hinter2 in Hrfei; inversion Hrfei.
(*A1 : false true ; A2 : true false *)
destruct_wk H12.
unfold A1n.inter in Hinter1; unfold A2n.inter in Hinter2;
rewrite Hinter1 in Hrfei; rewrite Hinter2 in Hrfei; inversion Hrfei.
(*A1 : true false ; A2 : true false *)
inversion Hxy as [Hrfi | Hr].
left; left; auto.
inversion Hr as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hres;
apply bot_ghb_incl; auto.
(*A1 : false false ; A2 : true false *)
inversion Hxy as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hres;
apply bot_ghb_incl; auto.
(*A1 : true true ; A2 : false false *)
destruct_wk H12.
unfold A1n.inter in Hinter1; unfold A2n.inter in Hinter2;
rewrite Hinter1 in Hrfei; rewrite Hinter2 in Hrfei; inversion Hrfei.
(*A1 : false true ; A2 : false false *)
destruct_wk H12.
unfold A1n.inter in Hinter1; unfold A2n.inter in Hinter2;
rewrite Hinter1 in Hrfei; rewrite Hinter2 in Hrfei; inversion Hrfei.
(*A1 : true false ; A2 : false false *)
destruct H12 as (*[?*) [? [Himpl ?]](*]*).
unfold A1n.intra in Hintra1; unfold A2n.intra in Hintra2;
rewrite Hintra1 in Himpl; rewrite Hintra2 in Himpl; inversion Himpl.
(*A1 : false false ; A2 : false false*)
inversion Hxy as [Ht | Hres].
inversion Ht.
right; fold (bot_ghb2 E X); fold (bot_ghb1 E X) in Hres;
apply bot_ghb_incl; auto.
Qed.
(** If A1 is weaker than A2, then a valid execution on A2n is also valid on
A1n *)
Lemma v2_implies_v1 :
forall E X,
weaker ->
A2nWmm.valid_execution E X ->
A1nWmm.valid_execution E X.
Proof.
intros E X H21 Hv1.
destruct_valid Hv1.
split; auto; [ |split; auto; split; auto].
split; auto; split; auto.
split; auto.
eapply incl_ac; [apply ghb_incl; auto | apply Hvalid].
Qed.
(** If A1 is weaker than A2, then a valid execution on A2n is also valid on
A1n, and the execution verifies the [check] condition *)
Lemma A2_impl_A1_check :
forall E X,
weaker ->
A2nWmm.valid_execution E X ->
A1nWmm.valid_execution E X /\ check E X.
Proof.
intros E X Hincl Hv2.
split; [apply v2_implies_v1; auto |].
destruct_valid Hv2; unfold check.
rewrite (ghb2_eq E X) in Hvalid; auto.
Qed.
(** If A1 is weaker than A2, then a valid execution on A1n that verifies the
[check] condition, is valid on A2n *)
Lemma A1_check_impl_A2 :
forall E X,
weaker ->
A1nWmm.valid_execution E X /\ check E X ->
A2nWmm.valid_execution E X.
Proof.
intros E X Hincl [Hv1 Hc2].
destruct_valid Hv1; split; auto; split; auto; split; auto.
split.
auto.
rewrite (ghb2_eq E X); unfold check in Hc2; auto.
Qed.
(** If A1 is weaker than A2, being a valid execution on A1n and verifying the
[check] condition is equivalent to being a valid execution on A2n *)
Lemma charac :
forall E X,
weaker ->
((A1nWmm.valid_execution E X /\ check E X) <->
(A2nWmm.valid_execution E X)).
Proof.
intros E X; split; [intros [Hv1 Hc2] | intro Hv2].
apply A1_check_impl_A2; auto.
apply A2_impl_A1_check; auto.
Qed.
End Char.
(** ** Barriered architecture
We define a version of A1 where the barriers relation is left as a parameter of
the module
*)
Module A1b <: Archi.
(** The preserved program order is the same as the one of A1 *)
Definition ppo := A1.ppo.
Lemma ppo_valid : forall E, rel_incl (ppo E) (po_iico E).
apply A1.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 A1.ppo_fun.
Qed.
(** The part of read-from that are global are the same than in A1 *)
Definition inter := A1.inter.
Definition intra := A1.intra.
(** The barrier relation is left as a parameter *)
Parameter abc : Event_struct -> Execution_witness -> Rln Event.
(** In a well-formed event structure with a well-formed read-from relation, two
events related by the barrier relation must belong to the set of events of the
event structure *)
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.
(** For every execution, the barrier relation must be included in the transtive closure of the union of communication relation and program order *)
Hypothesis ab_incl :
forall E X, rel_incl (abc E X) (tc (rel_union (com E X) (po_iico E))).
(* As in wmm, what this represents is not really clear, and it is used nowhere
so I comment it, but we should eventually clarify what it means *)
(*
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 A1b.
(** For a given event structure E, [ppo_sub E] is the part of the program order
of E that is preserved by A2 but not by A1 *)
Definition ppo_sub E :=
rel_sub (A1.ppo E) (A2.ppo E).
(** We define the notion of intra-thread, inter-thread and global read-froms
for A2 *)
Definition mrfi2 X :=
mrel (A2.intra) (rf_intra X).
Definition mrfe2 X :=
mrel (A2.inter) (rf_inter X).
Definition mrf2 X :=
rel_union (mrfi2 X) (mrfe2 X).
(** We define the notion of intra-thread, inter-thread and global read-froms
for A1 *)
Definition mrfi1 X :=
mrel (A1.intra) (rf_intra X).
Definition mrfe1 X :=
mrel (A1.inter) (rf_inter X).
Definition mrf1 X :=
rel_union (mrfi1 X) (mrfe1 X).
(** For a given execution, [rf_sub X] is the part of the read-froms that are
considered global on A2 but not on A1 *)
Definition rf_sub X :=
rel_sub (mrf1 X) (mrf2 X).
Import A1b.
(** We import basic facts about A1b *)
Module A1bBasic := Basic A1b dp.
Import A1bBasic.
(** We build a memory model on A1b *)
Module A1bWmm := Wmm A1b dp.
Import A1bWmm.
Import A2n. Import A2nBasic. Import A2nWmm.
Section Barriers.
(** We say that an execution is fully barriered when all the events that:
- are ordered by A2 but not by A1
- are ordered by a sequence of read-from and preserver program order on A2 but
not on A1
are ordered by the barriers on A1 *)
Definition fully_barriered (E:Event_struct) (X:Execution_witness) :=
rel_incl (rel_union (ppo_sub E) (rel_seq (rf_sub X) (A2.ppo E))) (A1b.abc E X).
(** The global happens-before of the memory model based on [A1b] is the union of
the write serialization, the from-read relation, the preserved program order of
A1, the global read-from of A1 and of the barrier relation of A1 *)
Lemma ghb1b_eq :
forall E X,
A1bWmm.ghb E X = rel_union (rel_union (ws X) (fr E X))
(rel_union (rel_union (mrf1 X) (A1.ppo E))
(A1b.abc E X)) .
Proof.
intros E X; unfold A1bWmm.ghb; unfold mrf1; unfold mrfi1; unfold mrfe1;
unfold A1b.ppo; unfold A1b.inter; unfold A1b.intra;
case_eq A1.inter; case_eq A1.intra; intros Hintra Hinter; simpl;
apply ext_rel; split; intro Hxy.
inversion Hxy as [Hrfe | Hr].
right; left; left; right; auto.
inversion Hr as [Hrfi | Hre].
right; left; left; left; auto.
inversion Hre as [Hab | Hres].
right; right; auto.
inversion Hres as [Hws_fr | Hppo].
left; auto.
right; left; right; auto.
inversion Hxy as [Hws_fr | Hr].
right; right; right; left; auto.
inversion Hr as [Hre | Hab].
inversion Hre as [Hrf | Hppo].
inversion Hrf as [Hrfi | Hrfe]; [right; left; auto | left; auto].
right; right; right; right; auto.
right; right; left; auto.
inversion Hxy as [Hrfe | Hr].
right; left; left; right; auto.
inversion Hr as [Hab | Hre].
right; right; auto.
inversion Hre as [Hws_fr | Hppo].
left; auto.
right; left; right; auto.
inversion Hxy as [Hws_fr | Hr].
right; right; left; auto.
inversion Hr as [Hre | Hab].
inversion Hre as [Hrf | Hppo].
inversion Hrf as [Ht | Hrfi].
inversion Ht.
left; auto.
right; right; right; auto.
right; left; auto.
inversion Hxy as [Hrfi | Hr].
right; left; left; left; auto.
inversion Hr as [Hab | Hre].
right; right; auto.
inversion Hre as [Hws_fr | Hppo].
left; auto.
right; left; right; auto.
inversion Hxy as [Hws_fr | Hr].
right; right; left; auto.
inversion Hr as [Hre | Hab].
inversion Hre as [Hrf | Hppo].
inversion Hrf as [Hrfi | Ht].
left; auto.
inversion Ht.
right; right; right; auto.
right; left; auto.
inversion Hxy as [Hab | Hr].
right; right; auto.
inversion Hr as [Hws_fr | Hppo].
left; auto.
right; left; right; auto.
inversion Hxy as [Hws_fr | Hr].
right; left; auto.
inversion Hr as [Hre | Hab].
inversion Hre as [Ht | Hppo].
inversion Ht as [Ht1 | Ht2]; [inversion Ht1 | inversion Ht2].
right; right; auto.
left; auto.
Qed.
(** If A1 is weaker than A2, in a well-formed event structure, the [mhb']
relation of A2n is the union of:
- the [mhb'] of A1b
- the read-froms that are global in A2 but not in A1
- the sequence of write serialization and the read-froms global in A2 but not in
A1
- the sequence of from-read and the read-froms global in A2 but not in A1 *)
Lemma mhb'2_is_mhb'1_u_rf_sub :
forall E X,
weaker ->
well_formed_event_structure E ->
(A2nWmm.mhb' E X) =
rel_union (rel_union (A1bWmm.mhb' E X) (rf_sub X))
(rel_union (rel_seq (ws X) (rf_sub X)) (rel_seq (fr E X) (rf_sub X))).
Proof.
case_eq A2.inter; case_eq A2.intra; intros Hinter2 Hintra2;
case_eq A1.inter; case_eq A1.intra; intros Hinter1 Hintra1;
unfold mhb'; unfold mhb; unfold rf_sub;
unfold A1bWmm.mhb'; unfold A1bWmm.mhb;
unfold A1bWmm.mrf; unfold mrf; unfold A1bWmm.mrfi; unfold mrfi;
unfold A1bWmm.mrfe; unfold mrfe; unfold inter; unfold intra;
unfold A1b.inter; unfold A1b.intra; unfold mrf1; unfold mrf2;
unfold mrfi1; unfold mrfi2; unfold mrfe1; unfold mrfe2;
rewrite Hinter1; rewrite Hintra1; rewrite Hinter2; rewrite Hintra2;
unfold abc; intros E X Hwk Hwf; apply ext_rel; split; intro Hxy; auto;
simpl in * |- *.
inversion Hxy as [Hr | Hsfr].
inversion Hr as [Hre | Hsws].
inversion Hre as [Hrfe | Hres].
left; left; left; left; auto.
inversion Hres as [Hrfi | Hws_rf].
left; left; left; left; auto.
left; left; left; left; right; auto.
left; left; left; right; auto.
left; left; right; auto.
inversion Hxy as [Hu | Hssub].
inversion Hu as [Hr | Hsub].
inversion Hr as [Hhbs | Hsfr].
inversion Hhbs as [Hhb | Hsws].
left; auto.
left; right; auto.
right; auto.
destruct Hsub as [Hrf ?]; inversion Hrf as [Hrfi | Hrfe].
left; left; right; left; auto.
left; left; left; auto.
inversion Hssub as [Hsws | Hsfr].
destruct Hsws as [? [? Ht]]; destruct Ht; contradiction.
destruct Hsfr as [? [? Ht]]; destruct Ht; contradiction.
inversion Hxy as [Hu | Hsfr].
inversion Hu as [Hhb | Hsws].
inversion Hhb as [Hrfe | Hr].
left; left; left; left; left; auto.
inversion Hr as [Hrfi | Hwsfr].
left; right; split.
left; auto.
intro Hor; inversion Hor as [| Hrfe]; auto.
destruct Hrfi; destruct Hrfe; contradiction.
left; left; left; left; right; auto.
destruct Hsws as [z [Hz Hurf]].
inversion Hurf as [Hrfi | Hrfe].
right; left.
exists z; split; auto.
split. left; auto.
intro Hor; inversion Hor as [| Hrfe]; auto.
destruct Hrfi; destruct Hrfe; contradiction.
left; left; left; right.
exists z; split; auto.
right; auto.
destruct Hsfr as [z [Hz Hurf]].
inversion Hurf as [Hrfi | Hrfe].
right; right.
exists z; split; auto.
split. left; auto.
intro Hor; inversion Hor as [| Hrfe]; auto.
destruct Hrfi; destruct Hrfe; contradiction.
left; left; right.
exists z; split; auto.
right; auto.
inversion Hxy as [Hu | Hssub].
inversion Hu as [Hr | Hsub].
inversion Hr as [Hhbs | Hsfr].
inversion Hhbs as [Hhb | Hsws].
inversion Hhb as [Hrfe | Hwsfr].
left; left; left; auto.
left; left; right; right; auto.
left; right; destruct Hsws as [z [Hxz Hzy]]; exists z; split; auto.
inversion Hzy as [Ht | Hrfe].
inversion Ht. right; auto.
right; destruct Hsfr as [z [Hxz Hzy]]; exists z; split; auto.
inversion Hzy as [Ht | Hrfe].
inversion Ht. right; auto.
destruct Hsub as [Hrf ?]; inversion Hrf as [Hrfi | Hrfe].
left; left; right; left; auto.
left; left; left; auto.
inversion Hssub as [Hsws | Hsfr].
destruct Hsws as [z [Hws [Hrf ?]]].
left; right; exists z; split; auto.
destruct Hsfr as [z [Hws [Hrf ?]]].
right; exists z; split; auto.
inversion Hxy as [Hu | Hsfr].
inversion Hu as [Hhb | Hsws].
inversion Hhb as [Hrfe | Hr].
left; right; split.
right; auto.
intro Hor; inversion Hor as [Hrfi | Ht].
destruct Hrfi; destruct Hrfe; contradiction.
inversion Ht.
inversion Hr as [Hrfi | Hwsfr].
left; left; left; left.
left; auto.
left; left; left; left; right; auto.
destruct Hsws as [z [Hz Hurf]].
inversion Hurf as [Hrfi | Hrfe].
left; left; left; right.
exists z; split; auto.
left; auto.
right; left; exists z; split; auto.
split. right; auto.
intro Hor; inversion Hor as [Hrfi | Ht].
destruct Hrfe; destruct Hrfi; contradiction.
inversion Ht; auto.
destruct Hsfr as [z [Hz Hurf]].
inversion Hurf as [Hrfi | Hrfe].
left; left; right.
exists z; split; auto.
left; auto.
right; right.
exists z; split; auto.
split. right; auto.
intro Hor; inversion Hor as [Hrfi | Ht]; auto.
destruct Hrfi; destruct Hrfe; contradiction.
inversion Hxy as [Hu | Hssub].
inversion Hu as [Hr | Hsub].
inversion Hr as [Hhbs | Hsfr].
inversion Hhbs as [Hhb | Hsws].
inversion Hhb as [Hrfe | Hwsfr].
left; left; right; auto.
left; left; right; right; auto.
left; right; destruct Hsws as [z [Hxz Hzy]]; exists z; split; auto.
inversion Hzy as [Hrfi | Ht].
left; auto. inversion Ht; auto.
right; destruct Hsfr as [z [Hxz Hzy]]; exists z; split; auto.
inversion Hzy as [Hrfi | Ht].
left; auto. inversion Ht.
destruct Hsub as [Hrf ?]; inversion Hrf as [Hrfi | Hrfe].
left; left; right; left; auto.
left; left; left; auto.
inversion Hssub as [Hsws | Hsfr].
destruct Hsws as [z [Hws [Hrf ?]]].
left; right; exists z; split; auto.
destruct Hsfr as [z [Hws [Hrf ?]]].
right; exists z; split; auto.
inversion Hxy as [Hu | Hsfr].
inversion Hu as [Hhb | Hsws].
inversion Hhb as [Hrfe | Hr].
left; right; split.
right; auto.
intro Hor; inversion Hor as [Ht | Hrfi].
inversion Ht.
destruct Hrfi; destruct Hrfe; contradiction.
inversion Hr as [Hrfi | Hwsfr].
left; right.
split.
left; auto.
intro Hor; inversion Hor; auto.
left; left; left; left; auto.
destruct Hsws as [z [Hz Hurf]].
right; left.
exists z; split; auto.
split; auto.
intro Hor; inversion Hor; auto.
destruct Hsfr as [z [Hz Hurf]].
right; right.
exists z; split; auto.