-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPlusProperties.v
9613 lines (8949 loc) · 370 KB
/
PPlusProperties.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 Import Kami.Syntax.
Require Import Kami.Properties Kami.PProperties.
Import ListNotations.
Require Import Coq.Sorting.Permutation.
Require Import Coq.Sorting.PermutEq.
Require Import Psatz.
Require Import RelationClasses Setoid Morphisms.
Require Import ZArith Kami.Lib.EclecticLib.
Local Notation PPT_execs := (fun x => fst (snd x)).
Local Notation PPT_calls := (fun x => snd (snd x)).
Local Open Scope Z_scope.
(*TODO move somewhere else*)
Lemma existsb_nexists_str str l :
existsb (String.eqb str) l = false <->
~ In str l.
Proof.
split; repeat intro.
- assert (exists x, In x l /\ (String.eqb str) x = true) as P0.
{ exists str; split; auto. apply String.eqb_refl. }
rewrite <- existsb_exists in P0; rewrite P0 in *; discriminate.
- remember (existsb _ _) as exb; symmetry in Heqexb; destruct exb; auto.
exfalso; rewrite existsb_exists in Heqexb; dest.
rewrite String.eqb_eq in *; subst; auto.
Qed.
Section NeverCallAction.
Variable ty : Kind -> Type.
Inductive NeverCallActionT: forall k, ActionT ty k -> Prop :=
| NeverCallMCall meth s e lretT c: False -> @NeverCallActionT lretT (MCall meth s e c)
| NeverCallLetExpr k (e: Expr ty k) lretT c: (forall v, NeverCallActionT (c v)) -> @NeverCallActionT lretT (LetExpr e c)
| NeverCallLetAction k (a: ActionT ty k) lretT c: NeverCallActionT a -> (forall v, NeverCallActionT (c v)) -> @NeverCallActionT lretT (LetAction a c)
| NeverCallReadNondet k lretT c: (forall v, NeverCallActionT (c v)) -> @NeverCallActionT lretT (ReadNondet k c)
| NeverCallReadReg r k lretT c: (forall v, NeverCallActionT (c v)) -> @NeverCallActionT lretT (ReadReg r k c)
| NeverCallWriteReg r k (e: Expr ty k) lretT c: NeverCallActionT c -> @NeverCallActionT lretT (WriteReg r e c)
| NeverCallIfElse p k (atrue: ActionT ty k) afalse lretT c: (forall v, NeverCallActionT (c v)) -> NeverCallActionT atrue -> NeverCallActionT afalse -> @NeverCallActionT lretT (IfElse p atrue afalse c)
| NeverCallSys ls lretT c: NeverCallActionT c -> @NeverCallActionT lretT (Sys ls c)
| NeverCallReturn lretT e: @NeverCallActionT lretT (Return e).
End NeverCallAction.
Section NeverCallBaseModule.
Variable m : BaseModule.
Definition NeverCallBaseModule :=
(forall rule ty, In rule (getRules m) -> NeverCallActionT (snd rule ty)) /\
(forall meth ty, In meth (getMethods m) ->
forall v, NeverCallActionT (projT2 (snd meth) ty v)).
End NeverCallBaseModule.
Inductive NeverCallMod: Mod -> Prop :=
| BaseNeverCall m (HNCBaseModule: NeverCallBaseModule m): NeverCallMod (Base m)
| HideMethNeverCall m s (HNCModule: NeverCallMod m): NeverCallMod (HideMeth m s)
| ConcatModNeverCall m1 m2 (HNCModule1: NeverCallMod m1) (HNCModule2: NeverCallMod m2)
: NeverCallMod (ConcatMod m1 m2).
(*
Proves that the number of method calls returned
by [getNumCalls] is always greater than or
equal to 0.
*)
Lemma num_method_calls_positive
: forall (method : MethT) (labels : list FullLabel),
0 <= getNumCalls method labels.
Proof
fun method
=> list_ind _
(ltac:(discriminate) : 0 <= getNumCalls method [])
(fun (label : FullLabel) (labels : list FullLabel)
(H : 0 <= getNumFromCalls method (concat (map PPT_calls labels)))
=> list_ind _ H
(fun (method0 : MethT) (methods : MethsT)
(H0 : 0 <= getNumFromCalls method (methods ++ concat (map PPT_calls labels)))
=> sumbool_ind
(fun methods_eq
=> 0 <=
if methods_eq
then 1 + getNumFromCalls method (methods ++ concat (map PPT_calls labels))
else getNumFromCalls method (methods ++ concat (map PPT_calls labels)))
(fun _ => Z.add_nonneg_nonneg 1 _ (Zle_0_pos 1) H0)
(fun _ => H0)
(MethT_dec method method0))
(snd (snd label))).
(*
Proves that the number of method executions
counted by [getNumExecs] is always greater
than or equal to 0.
*)
Lemma num_method_execs_positive
: forall (method : MethT) (labels : list FullLabel),
0 <= getNumExecs method labels.
Proof.
induction labels; unfold getNumExecs in *; simpl; try lia.
destruct a; simpl; auto.
destruct p; simpl; auto.
destruct r0; simpl; auto.
destruct (MethT_dec method f); simpl; auto; subst.
destruct (getNumFromExecs f (map PPT_execs labels)); simpl; auto; try lia.
Defined.
Local Close Scope Z_scope.
Section PPlusTraceInclusion.
Definition getListFullLabel_diff_flat f (t : (RegsT *((list RuleOrMeth)*MethsT))) : Z:=
(getNumFromExecs f (PPT_execs t) - getNumFromCalls f (PPT_calls t))%Z.
Definition WeakInclusion_flat (t1 t2 : (RegsT *((list RuleOrMeth) * MethsT))) :=
(forall (f : MethT), (getListFullLabel_diff_flat f t1 = getListFullLabel_diff_flat f t2)%Z) /\
((exists rle, In (Rle rle) (PPT_execs t2)) ->
(exists rle, In (Rle rle) (PPT_execs t1))).
Inductive WeakInclusions_flat : list (RegsT * ((list RuleOrMeth) * MethsT)) -> list (RegsT *((list RuleOrMeth) * MethsT)) -> Prop :=
|WIf_Nil : WeakInclusions_flat nil nil
|WIf_Cons : forall (lt1 lt2 : list (RegsT *((list RuleOrMeth) * MethsT))) (t1 t2 : RegsT *((list RuleOrMeth) * MethsT)),
WeakInclusions_flat lt1 lt2 -> WeakInclusion_flat t1 t2 -> WeakInclusions_flat (t1::lt1) (t2::lt2).
Definition PPlusTraceList (m : BaseModule)(lt : list (RegsT * ((list RuleOrMeth) * MethsT))) :=
(exists (o : RegsT), PPlusTrace m o lt).
Definition PPlusTraceInclusion (m m' : BaseModule) :=
forall (o : RegsT)(tl : list (RegsT *((list RuleOrMeth) * MethsT))),
PPlusTrace m o tl -> exists (tl' : list (RegsT * ((list RuleOrMeth) * MethsT))), PPlusTraceList m' tl' /\ WeakInclusions_flat tl tl'.
Definition StrongPPlusTraceInclusion (m m' : BaseModule) :=
forall (o : RegsT)(tl : list (RegsT *((list RuleOrMeth) * MethsT))),
PPlusTrace m o tl -> exists (tl' : list (RegsT * ((list RuleOrMeth) * MethsT))), PPlusTrace m' o tl' /\ WeakInclusions_flat tl tl'.
End PPlusTraceInclusion.
Section BaseModule.
Variable m: BaseModule.
Variable o: RegsT.
Definition getLabelUpds (ls: list FullLabel) :=
concat (map (fun x => fst x) ls).
Definition getLabelExecs (ls: list FullLabel) :=
map (fun x => fst (snd x)) ls.
Definition getLabelCalls (ls: list FullLabel) :=
concat (map (fun x => (snd (snd x))) ls).
Lemma getLabelCalls_perm_rewrite l l' :
l [=] l' ->
getLabelCalls l [=] getLabelCalls l'.
Proof.
induction 1.
- reflexivity.
- unfold getLabelCalls; simpl; fold (getLabelCalls l); fold (getLabelCalls l').
rewrite IHPermutation; reflexivity.
- unfold getLabelCalls; simpl; fold (getLabelCalls l).
repeat rewrite app_assoc.
apply Permutation_app_tail, Permutation_app_comm.
- rewrite IHPermutation1, IHPermutation2.
reflexivity.
Qed.
Global Instance getLabelCalls_perm_rewrite' :
Proper (@Permutation (FullLabel) ==> @Permutation (MethT)) (@getLabelCalls) | 10.
Proof.
repeat red; intro; eauto using getLabelCalls_perm_rewrite.
Qed.
Lemma getLabelExecs_perm_rewrite l l' :
l [=] l' ->
getLabelExecs l [=] getLabelExecs l'.
Proof.
induction 1; auto.
- unfold getLabelExecs in *; simpl.
apply perm_skip; assumption.
- unfold getLabelExecs in *; simpl.
apply perm_swap.
- rewrite IHPermutation1, IHPermutation2; reflexivity.
Qed.
Lemma getLabelUpds_perm_rewrite l l' :
l [=] l' ->
getLabelUpds l [=] getLabelUpds l'.
Proof.
induction 1; auto; unfold getLabelUpds in *; simpl in *.
- apply Permutation_app_head; assumption.
- repeat rewrite app_assoc; apply Permutation_app_tail, Permutation_app_comm.
- rewrite IHPermutation1, IHPermutation2; reflexivity.
Qed.
Global Instance getLabelExecs_perm_rewrite' :
Proper (@Permutation (FullLabel) ==> @Permutation (RuleOrMeth)) (@getLabelExecs) | 10.
Proof.
repeat red; intro; eauto using getLabelExecs_perm_rewrite.
Qed.
Global Instance getLabelUpds_perm_rewrite' :
Proper (@Permutation (FullLabel) ==> @Permutation (string * {x : FullKind & fullType type x})) (@getLabelUpds) | 10.
Proof.
repeat red; intro; eauto using getLabelUpds_perm_rewrite.
Qed.
Lemma InCall_getLabelCalls f l:
InCall f l ->
In f (getLabelCalls l).
Proof.
induction l; unfold InCall,getLabelCalls in *; intros; simpl; dest; auto.
destruct H; subst;apply in_app_iff; [left; assumption|right; apply IHl].
exists x; auto.
Qed.
Lemma getLabelCalls_InCall f l:
In f (getLabelCalls l) ->
InCall f l.
Proof.
induction l; unfold InCall, getLabelCalls in *; intros; simpl in *;[contradiction|].
rewrite in_app_iff in H; destruct H;[exists a; auto|specialize (IHl H);dest].
exists x; auto.
Qed.
Corollary InCall_getLabelCalls_iff f l:
InCall f l <->
In f (getLabelCalls l).
Proof.
split; intro; eauto using InCall_getLabelCalls, getLabelCalls_InCall.
Qed.
Lemma PPlusSubsteps_PSubsteps:
forall upds execs calls,
PPlusSubsteps m o upds execs calls ->
exists l,
PSubsteps m o l /\
upds [=] getLabelUpds l /\
execs [=] getLabelExecs l /\
calls [=] getLabelCalls l.
Proof.
unfold getLabelUpds, getLabelExecs, getLabelCalls.
induction 1; dest.
- exists nil.
repeat split; auto; constructor; auto.
- exists ((u, (Rle rn, cs)) :: x).
repeat split; auto; try constructor; auto; simpl.
+ econstructor; eauto; intros.
* clear - H1 H4 HUpds HExecs HCalls HDisjRegs.
intro.
destruct (HDisjRegs k); auto.
left; intro.
clear - H1 H4 H H0.
rewrite H1 in H.
rewrite <- flat_map_concat_map in H.
rewrite in_map_iff in H.
setoid_rewrite in_flat_map in H.
rewrite in_map_iff in *; dest; subst.
firstorder fail.
* clear - H2 H4 HExecs HNoRle.
apply HNoRle.
rewrite H2.
rewrite in_map_iff.
firstorder fail.
+ rewrite H1 in HUpds; auto.
+ rewrite HExecs.
constructor; auto.
+ rewrite H3 in HCalls; auto.
- exists ((u, (Meth (fn, existT SignT (projT1 fb) (argV, retV)), cs)) :: x).
repeat split; auto; try constructor; auto; simpl.
+ econstructor 3; eauto; intros.
* clear - H1 H4 HUpds HExecs HCalls HDisjRegs.
intro.
destruct (HDisjRegs k); auto.
left; intro.
clear - H1 H4 H H0.
rewrite H1 in H.
rewrite <- flat_map_concat_map in H.
rewrite in_map_iff in H.
setoid_rewrite in_flat_map in H.
rewrite in_map_iff in *; dest; subst.
firstorder fail.
+ rewrite H1 in HUpds; auto.
+ rewrite HExecs.
constructor; auto.
+ rewrite H3 in HCalls; auto.
Qed.
End BaseModule.
Section PPlusSubsteps_rewrite.
Lemma PPlusSubsteps_rewrite_regs m o1 o2 upds execs calls:
(o1 [=] o2) ->
PPlusSubsteps m o1 upds execs calls ->
PPlusSubsteps m o2 upds execs calls.
Proof.
induction 2.
- econstructor 1.
rewrite <- H; assumption.
- econstructor 2;(rewrite <- H || apply (PSemAction_rewrite_state H) in HPAction); eauto.
- econstructor 3;(rewrite <- H || apply (PSemAction_rewrite_state H) in HPAction); eauto.
Qed.
Lemma PPlusSubsteps_rewrite_upds m o execs calls upds1 upds2:
(upds1 [=] upds2) ->
PPlusSubsteps m o upds1 execs calls ->
PPlusSubsteps m o upds2 execs calls.
Proof.
induction 2.
- apply Permutation_nil in H; rewrite H.
econstructor 1; assumption.
- econstructor 2; eauto.
rewrite H in HUpds.
assumption.
- econstructor 3; eauto.
rewrite H in HUpds.
assumption.
Qed.
Lemma PPlusSubsteps_rewrite_execs m o upds calls execs1 execs2:
(execs1 [=] execs2) ->
PPlusSubsteps m o upds execs1 calls ->
PPlusSubsteps m o upds execs2 calls.
Proof.
induction 2.
- apply Permutation_nil in H; rewrite H.
econstructor 1; assumption.
- econstructor 2; eauto.
rewrite H in HExecs.
assumption.
- econstructor 3; eauto.
rewrite H in HExecs.
assumption.
Qed.
Lemma PPlusSubsteps_rewrite_calls m o upds execs calls1 calls2:
(calls1 [=] calls2) ->
PPlusSubsteps m o upds execs calls1 ->
PPlusSubsteps m o upds execs calls2.
Proof.
induction 2.
- apply Permutation_nil in H; rewrite H.
econstructor 1; assumption.
- econstructor 2; eauto.
rewrite H in HCalls.
assumption.
- econstructor 3; eauto.
rewrite H in HCalls.
assumption.
Qed.
Lemma PPlusSubsteps_rewrite_all m o1 o2 upds1 execs1 calls1 upds2 execs2 calls2 :
o1 [=] o2 ->
upds1 [=] upds2 ->
execs1 [=] execs2 ->
calls1 [=] calls2 ->
PPlusSubsteps m o1 upds1 execs1 calls1 ->
PPlusSubsteps m o2 upds2 execs2 calls2.
Proof.
intros.
apply (PPlusSubsteps_rewrite_regs H) in H3;
apply (PPlusSubsteps_rewrite_upds H0) in H3;
apply (PPlusSubsteps_rewrite_execs H1) in H3;
apply (PPlusSubsteps_rewrite_calls H2) in H3;
assumption.
Qed.
Global Instance PPlusSubsteps_rewrite' :
Proper (Logic.eq ==>
@Permutation (string * {x : FullKind & fullType type x}) ==>
@Permutation (string * {x : FullKind & fullType type x}) ==>
@Permutation RuleOrMeth ==>
@Permutation MethT ==>
iff) (@PPlusSubsteps)| 10.
Proof.
repeat red; intros; split; intros; subst; eauto using Permutation_sym, PPlusSubsteps_rewrite_all.
symmetry in H0.
symmetry in H1.
symmetry in H2.
symmetry in H3.
eapply PPlusSubsteps_rewrite_all; eauto.
Qed.
End PPlusSubsteps_rewrite.
Lemma Permutation_flat_map_rewrite (A B : Type) (l1 l2 : list A) (f : A -> list B) :
l1 [=] l2 ->
flat_map f l1 [=] flat_map f l2.
Proof.
induction 1; simpl in *; auto.
- apply Permutation_app_head; assumption.
- repeat rewrite app_assoc; apply Permutation_app_tail.
rewrite Permutation_app_comm; reflexivity.
- rewrite IHPermutation1, IHPermutation2; reflexivity.
Qed.
Global Instance Permutation_flat_map_rewrite' (A B : Type)(f : A -> list B):
Proper (@Permutation A ==> @Permutation B) (@flat_map A B f) | 10.
repeat red; intros; intros; eauto using Permutation_flat_map_rewrite.
Qed.
Lemma PSubsteps_PPlusSubsteps:
forall m o l,
PSubsteps m o l ->
PPlusSubsteps m o (getLabelUpds l) (getLabelExecs l) (getLabelCalls l).
Proof.
induction 1; unfold getLabelUpds, getLabelExecs, getLabelCalls in *; try setoid_rewrite <- flat_map_concat_map.
- econstructor; eauto.
- rewrite HLabel; simpl; setoid_rewrite <-flat_map_concat_map in IHPSubsteps.
econstructor 2; intros; eauto.
+ clear - HDisjRegs.
induction ls.
* firstorder.
* intro; simpl in *; rewrite map_app, in_app_iff, DeM1.
assert (DisjKey (flat_map (fun x : FullLabel => fst x) ls) u);[eapply IHls; eauto|].
specialize (HDisjRegs a (or_introl _ eq_refl) k); specialize (H k).
firstorder fail.
+ rewrite in_map_iff in H0; dest; rewrite <- H0.
eapply HNoRle; eauto.
- rewrite HLabel; simpl; setoid_rewrite <- flat_map_concat_map in IHPSubsteps.
econstructor 3; intros; eauto.
+ clear - HDisjRegs.
induction ls.
* firstorder.
* intro; simpl in *; rewrite map_app, in_app_iff, DeM1.
assert (DisjKey (flat_map (fun x : FullLabel => fst x) ls) u);[eapply IHls; eauto|].
specialize (HDisjRegs a (or_introl _ eq_refl) k); specialize (H k).
firstorder fail.
Qed.
Section PPlusStep.
Variable m: BaseModule.
Variable o: RegsT.
Lemma PPlusStep_PStep:
forall upds execs calls,
PPlusStep m o upds execs calls ->
exists l,
PStep (Base m) o l /\
upds [=] getLabelUpds l /\
execs [=] getLabelExecs l /\
calls [=] getLabelCalls l.
Proof.
induction 1.
apply PPlusSubsteps_PSubsteps in H; dest.
exists x; repeat split; eauto.
econstructor 1; eauto.
intros f HInDef; specialize (H0 f HInDef).
unfold getNumCalls, getNumExecs, getLabelExecs, getLabelCalls in *.
rewrite <-H3, <-H2; assumption.
Qed.
Lemma PStep_PPlusStep :
forall l,
PStep (Base m) o l ->
PPlusStep m o (getLabelUpds l) (getLabelExecs l) (getLabelCalls l).
Proof.
intros; inv H; econstructor.
- apply PSubsteps_PPlusSubsteps in HPSubsteps; assumption.
- intros f HInDef; specialize (HMatching f).
apply HMatching; auto.
Qed.
End PPlusStep.
Section PPlusTrace.
Variable m: BaseModule.
Lemma PPlusTrace_PTrace o ls :
PPlusTrace m o ls ->
exists ls',
PTrace (Base m) o ls' /\
PermutationEquivLists (map fst ls) (map getLabelUpds ls') /\
PermutationEquivLists (map PPT_execs ls) (map getLabelExecs ls') /\
PermutationEquivLists (map PPT_calls ls) (map getLabelCalls ls').
Proof.
induction 1; subst; dest.
- exists nil; repeat split; econstructor; eauto.
- apply PPlusStep_PStep in HPPlusStep; dest.
exists (x0::x); repeat split; eauto; simpl in *; econstructor 2; eauto.
+ unfold PPlusUpdRegs in HUpdRegs; dest.
repeat split; eauto.
intros; destruct (H9 _ _ H10).
* rewrite H5 in H11; unfold getLabelUpds in H11.
rewrite <- flat_map_concat_map, in_flat_map in *; dest.
left; exists (fst x1); split; auto.
apply (in_map fst) in H11; assumption.
* destruct H11; right; split; auto.
intro; apply H11; dest.
unfold getLabelUpds in *.
rewrite H5, <- flat_map_concat_map, in_map_iff.
setoid_rewrite in_flat_map.
rewrite in_map_iff in H13,H14; dest.
exists x2; split; auto.
exists x3; subst; auto.
Qed.
Definition extractTriple (lfl : list FullLabel) : (RegsT * ((list RuleOrMeth) * MethsT)) :=
(getLabelUpds lfl, (getLabelExecs lfl, getLabelCalls lfl)).
Fixpoint extractTriples (llfl : list (list FullLabel)) : list (RegsT * ((list RuleOrMeth) * MethsT)) :=
match llfl with
|lfl::llfl' => (extractTriple lfl)::(extractTriples llfl')
|nil => nil
end.
Lemma extractTriples_nil l :
extractTriples l = nil -> l = nil.
Proof.
destruct l; intros; auto.
inv H.
Qed.
Lemma PTrace_PPlusTrace o ls:
PTrace (Base m) o ls ->
PPlusTrace m o (extractTriples ls).
Proof.
induction 1; subst; intros.
- econstructor; eauto.
- simpl; econstructor 2; eauto.
+ apply PStep_PPlusStep; apply HPStep.
+ unfold PUpdRegs,PPlusUpdRegs in *; dest; repeat split; eauto.
intros; destruct (H1 _ _ H2);[left|right]; unfold getLabelUpds; dest.
* rewrite <- flat_map_concat_map, in_flat_map.
rewrite (in_map_iff fst) in H3; dest; rewrite <- H3 in H4.
firstorder.
* split; auto; intro; apply H3.
rewrite <- flat_map_concat_map, in_map_iff in H5; dest.
rewrite in_flat_map in H6; dest.
exists (fst x0); split.
-- rewrite in_map_iff; exists x0; firstorder.
-- rewrite <- H5, in_map_iff; exists x; firstorder.
+ unfold extractTriple; reflexivity.
Qed.
End PPlusTrace.
Section PPlusTraceInclusion.
Lemma InExec_rewrite f l:
In (Meth f) (getLabelExecs l) <-> InExec f l.
Proof.
split; unfold InExec; induction l; simpl in *; intros; auto.
Qed.
Lemma InCall_rewrite f l :
In f (getLabelCalls l) <-> InCall f l.
Proof.
split; unfold InCall; induction l; simpl in *; intros; dest; try contradiction.
- unfold getLabelCalls in H. rewrite <- flat_map_concat_map, in_flat_map in H.
assumption.
- unfold getLabelCalls; rewrite <- flat_map_concat_map, in_flat_map.
firstorder fail.
Qed.
Lemma WeakInclusion_flat_WeakInclusion (l1 l2 : list FullLabel) :
WeakInclusion_flat (extractTriple l1) (extractTriple l2) <->
WeakInclusion l1 l2.
Proof.
split; auto.
Qed.
Lemma WeakInclusions_flat_WeakInclusions (ls1 ls2 : list (list FullLabel)) :
WeakInclusions_flat (extractTriples ls1) (extractTriples ls2) ->
WeakInclusions ls1 ls2.
Proof.
revert ls2; induction ls1; intros; simpl in *; inv H.
- symmetry in H0; apply extractTriples_nil in H0; subst; econstructor.
- destruct ls2; inv H2.
econstructor 2.
+ eapply IHls1; eauto.
+ apply WeakInclusion_flat_WeakInclusion; assumption.
Qed.
Lemma StrongPPlusTraceInclusion_PPlusTraceInclusion m m' :
StrongPPlusTraceInclusion m m' ->
PPlusTraceInclusion m m'.
Proof.
unfold StrongPPlusTraceInclusion, PPlusTraceInclusion, PPlusTraceList; intros.
specialize (H _ _ H0); dest.
exists x; split; auto.
exists o; auto.
Qed.
Lemma WeakInclusions_flat_PermutationEquivLists_r ls1:
forall l ls2,
WeakInclusions_flat (extractTriples ls1) l ->
PermutationEquivLists (map fst l) (map getLabelUpds ls2) ->
PermutationEquivLists (map PPT_execs l) (map getLabelExecs ls2) ->
PermutationEquivLists (map PPT_calls l) (map getLabelCalls ls2) ->
WeakInclusions_flat (extractTriples ls1) (extractTriples ls2).
Proof.
induction ls1; intros; inv H; simpl in *.
- destruct ls2; simpl in *.
+ econstructor.
+ inv H2.
- destruct ls2; inv H2; inv H1; inv H0; simpl in *.
econstructor.
+ eapply IHls1; eauto.
+ unfold WeakInclusion_flat in *; dest; simpl in *.
split; intros;
[unfold getListFullLabel_diff_flat in *; simpl in *; rewrite <-H9, <-H10; apply H|].
apply H0; setoid_rewrite H10; assumption.
Qed.
Lemma PPlusTraceInclusion_PTraceInclusion (m m' : BaseModule) :
PPlusTraceInclusion m m' ->
PTraceInclusion (Base m) (Base m').
Proof.
repeat intro.
apply (PTrace_PPlusTrace) in H0.
specialize (H o _ H0); dest.
destruct H.
apply (PPlusTrace_PTrace) in H; dest.
exists x1; split.
- exists x0; assumption.
- apply WeakInclusions_flat_WeakInclusions.
apply (WeakInclusions_flat_PermutationEquivLists_r _ _ H1 H2 H3 H4).
Qed.
Lemma PPlusTraceInclusion_TraceInclusion (m m' : BaseModule) (Wfm: WfMod type (Base m)) (Wfm': WfMod type (Base m')):
PPlusTraceInclusion m m' ->
TraceInclusion (Base m) (Base m').
Proof.
intros; apply PTraceInclusion_TraceInclusion, PPlusTraceInclusion_PTraceInclusion; auto.
Qed.
End PPlusTraceInclusion.
Lemma NoDup_app_iff (A : Type) (l1 l2 : list A) :
NoDup (l1++l2) <->
NoDup l1 /\
NoDup l2 /\
(forall a, In a l1 -> ~In a l2) /\
(forall a, In a l2 -> ~In a l1).
Proof.
repeat split; intros; dest.
- induction l1; econstructor; inv H; firstorder.
- induction l2; econstructor; apply NoDup_remove in H; dest; firstorder.
- induction l1; auto.
simpl in H; rewrite NoDup_cons_iff in H; dest; firstorder.
subst; firstorder.
- induction l2; auto.
apply NoDup_remove in H; dest; firstorder.
subst; firstorder.
- induction l1; simpl; eauto.
constructor.
+ rewrite in_app_iff, DeM1; split; firstorder.
inv H; assumption.
+ inv H; eapply IHl1; eauto; firstorder.
Qed.
Lemma NoDup_app_Disj (A : Type) (dec : forall (a1 a2 : A), {a1 = a2}+{a1 <> a2}) :
forall (l1 l2 : list A),
NoDup (l1++l2) ->
(forall a, ~In a l1 \/ ~In a l2).
Proof.
intros.
rewrite NoDup_app_iff in H; dest.
destruct (in_dec dec a l1); auto.
Qed.
Notation remove_calls := (fun x y => negb (getBool (string_dec (fst x) (fst y)))).
Notation keep_calls := (fun x y => (getBool (string_dec (fst x) (fst y)))).
Definition methcmp (m1 m2 : MethT) : bool := getBool (MethT_dec m1 m2).
Definition remove_execs (calls : MethsT) (exec : RuleOrMeth) : bool :=
match exec with
| Rle _ => false
| Meth f => existsb (methcmp f) calls
end.
Lemma key_not_In_filter (f : DefMethT) (calls : MethsT) :
key_not_In (fst f) calls ->
filter (remove_calls f) calls = calls.
Proof.
induction calls; unfold key_not_In in *; simpl in *; intros; auto.
destruct string_dec; pose proof (H (snd a)); simpl in *.
- apply False_ind; apply H0; left.
destruct a; simpl in *; rewrite e; reflexivity.
- rewrite IHcalls; auto.
repeat intro; specialize (H v); apply H; right; assumption.
Qed.
Lemma PSemAction_inline_notIn (f : DefMethT) o k (a : ActionT type k)
readRegs newRegs calls (fret : type k) :
PSemAction o a readRegs newRegs calls fret ->
~In (fst f) (map fst calls) ->
PSemAction o (inlineSingle a f) readRegs newRegs calls fret.
Proof.
induction 1; simpl; intros.
- destruct (fst f =? meth)%string eqn:G. rewrite <- (proj1 (String.eqb_eq _ _) G) in *.
+ apply False_ind; apply H0; rewrite HAcalls; simpl; left; reflexivity.
+ econstructor 1; eauto.
apply IHPSemAction; intro; apply H0; rewrite HAcalls; simpl; right; assumption.
- econstructor 2; eauto.
- econstructor 3; eauto;[eapply IHPSemAction1|eapply IHPSemAction2];
intro; apply H1; rewrite HUCalls, map_app, in_app_iff;[left|right]; assumption.
- econstructor 4; eauto.
- econstructor 5; eauto.
- econstructor 6; eauto.
- econstructor 7; eauto; [eapply IHPSemAction1|eapply IHPSemAction2];
intro; apply H1; rewrite HUCalls, map_app, in_app_iff;[left|right]; assumption.
- econstructor 8; eauto; [eapply IHPSemAction1|eapply IHPSemAction2];
intro; apply H1; rewrite HUCalls, map_app, in_app_iff;[left|right]; assumption.
- econstructor 9; eauto.
- econstructor 10; eauto.
Qed.
Inductive PSemAction_meth_collector (f : DefMethT) (o : RegsT) : RegsT -> RegsT -> MethsT -> MethsT -> Prop :=
|NilCalls : PSemAction_meth_collector f o nil nil nil nil
|ConsCalls reads1 reads2 reads upds1 upds2
upds calls1 calls2 calls calls'
calls'' argV retV:
PSemAction_meth_collector f o reads1 upds1 calls1 calls' ->
DisjKey upds1 upds2 ->
reads [=] reads1 ++ reads2 ->
upds [=] upds1 ++ upds2 ->
calls [=] calls1 ++ calls2 ->
calls'' [=] ((fst f, (existT _ (projT1 (snd f)) (argV, retV)))::calls') ->
PSemAction o (projT2 (snd f) type argV) reads2 upds2 calls2 retV ->
PSemAction_meth_collector f o reads upds calls calls''.
Lemma Produce_action_from_collector (f : DefMethT) (o : RegsT) reads upds calls calls' call:
In call calls' ->
PSemAction_meth_collector f o reads upds calls calls' ->
exists reads1 reads2 upds1 upds2 calls1 calls2 calls'' argV retV,
DisjKey upds1 upds2 /\
upds [=] upds2++upds1 /\
calls [=] calls2++calls1 /\
reads [=] reads2 ++ reads1 /\
call = (fst f, (existT _ (projT1 (snd f)) (argV, retV))) /\
calls' [=] call::calls'' /\
PSemAction o (projT2 (snd f) type argV) reads2 upds2 calls2 retV /\
PSemAction_meth_collector f o reads1 upds1 calls1 calls''.
Proof.
induction 2.
- contradiction.
- rewrite H5 in H.
destruct H.
+ exists reads1, reads2, upds1, upds2, calls1, calls2, calls', argV, retV; subst.
repeat split; auto; (rewrite H2 || rewrite H3 || rewrite H4 || rewrite H5); subst; auto; apply Permutation_app_comm.
+ specialize (IHPSemAction_meth_collector H); dest.
rewrite H8, H9, H10, H12 in *.
exists (reads2++x), x0, (upds2++x1), x2, (calls2++x3), x4, ((fst f, existT _ (projT1 (snd f)) (argV, retV))::x5), x6, x7.
repeat split; auto.
* intro; destruct (H7 k), (H1 k); rewrite map_app,in_app_iff in *; dest; firstorder fail.
* rewrite H3, <-app_assoc; apply Permutation_app_head, Permutation_app_comm.
* rewrite H4, <-app_assoc; apply Permutation_app_head, Permutation_app_comm.
* rewrite H2, <-app_assoc; apply Permutation_app_head, Permutation_app_comm.
* rewrite H5; apply perm_swap.
* econstructor.
-- apply H14.
-- assert (DisjKey x1 upds2).
++ intro; destruct (H1 k);[rewrite map_app,in_app_iff,DeM1 in *; dest; left; assumption|right; assumption].
++ apply H15.
-- apply Permutation_app_comm.
-- apply Permutation_app_comm.
-- apply Permutation_app_comm.
-- reflexivity.
-- assumption.
Qed.
Lemma collector_perm_rewrite f o reads upds calls calls1':
PSemAction_meth_collector f o reads upds calls calls1' ->
forall calls2',
calls1' [=] calls2' ->
PSemAction_meth_collector f o reads upds calls calls2'.
Proof.
induction 1; intros.
- apply Permutation_nil in H; subst.
constructor.
- rewrite H6 in H4.
econstructor; eauto.
Qed.
Global Instance collector_perm_rewrite' :
Proper (eq ==> eq ==> eq ==> eq ==> eq ==> (@Permutation MethT) ==> iff) (@PSemAction_meth_collector) | 10.
Proof.
repeat red; intro; split; intros; subst; eauto using collector_perm_rewrite, Permutation_sym.
Qed.
Lemma collector_split (f : DefMethT) o calls1' calls2' :
forall reads upds calls,
PSemAction_meth_collector f o reads upds calls (calls1'++calls2') ->
exists reads1 reads2 upds1 upds2 calls1 calls2,
reads [=] reads1 ++ reads2 /\
upds [=] upds1 ++ upds2 /\
calls [=] calls1 ++ calls2 /\
DisjKey upds1 upds2 /\
PSemAction_meth_collector f o reads1 upds1 calls1 calls1' /\
PSemAction_meth_collector f o reads2 upds2 calls2 calls2'.
Proof.
induction calls1'; simpl; intros.
- exists nil, reads, nil, upds, nil, calls.
repeat split; auto.
+ intro; auto.
+ constructor.
- specialize (Produce_action_from_collector _ (in_eq _ _) H) as TMP; dest.
apply Permutation_cons_inv in H5.
rewrite <- H5 in H7.
specialize (IHcalls1' _ _ _ H7) as TMP; dest.
exists (x0++x8), x9, (x2++x10), x11, (x4++x12), x13.
repeat split.
+ rewrite H8, app_assoc in H3; assumption.
+ rewrite H9, app_assoc in H1; assumption.
+ rewrite H10, app_assoc in H2; assumption.
+ intro; specialize (H11 k); specialize (H0 k); clear - H0 H11 H9; rewrite H9,map_app, in_app_iff in *; firstorder fail.
+ econstructor.
* apply H12.
* rewrite H9 in H0; assert (DisjKey x10 x2);[intro; specialize (H0 k);
rewrite map_app, in_app_iff in *;clear - H0; firstorder fail| apply H14].
* apply Permutation_app_comm.
* apply Permutation_app_comm.
* apply Permutation_app_comm.
* rewrite H4; reflexivity.
* assumption.
+ assumption.
Qed.
Lemma collector_correct_fst f o reads upds calls calls' call :
In call calls' ->
PSemAction_meth_collector f o reads upds calls calls' ->
fst call = fst f.
Proof.
intros.
specialize (Produce_action_from_collector _ H H0) as TMP; dest.
destruct call; inv H5; simpl; reflexivity.
Qed.
Lemma collector_correct_pair f o reads upds calls calls' call :
In call calls' ->
PSemAction_meth_collector f o reads upds calls calls' ->
(fst call, projT1 (snd call)) = (fst f, projT1 (snd f)).
Proof.
intros.
specialize (Produce_action_from_collector _ H H0) as TMP; dest.
destruct call; inv H5; simpl; reflexivity.
Qed.
Definition called_by (f : DefMethT) (call :MethT) : bool :=
(getBool (prod_dec string_dec Signature_dec (fst f, projT1 (snd f)) (fst call, projT1 (snd call)))).
Local Notation complement f := (fun x => negb (f x)).
Definition called_execs (calls : MethsT) (exec : RuleOrMeth) : bool :=
match exec with
| Rle _ => false
| Meth f => existsb (methcmp f) calls
end.
Lemma separate_calls_by_filter (A : Type) (l : list A) (f : A -> bool):
l [=] (filter f l) ++ (filter (complement f) l).
Proof.
induction l; auto; simpl.
destruct (f a); simpl; rewrite IHl at 1;[reflexivity|apply Permutation_middle].
Qed.
Lemma reduce_called_execs_list execs c :
~In (Meth c) execs ->
forall calls,
(filter (called_execs (c::calls)) execs) = (filter (called_execs calls) execs).
Proof.
induction execs; intros; auto.
unfold called_execs, methcmp in *; destruct a; simpl in *.
- eapply IHexecs.
intro; apply H.
right; assumption.
- destruct MethT_dec; simpl.
+ apply False_ind; apply H.
rewrite e; left; reflexivity.
+ rewrite IHexecs;[reflexivity|].
intro; apply H; right; assumption.
Qed.
Corollary collector_called_by_filter_irrel f o calls' :
forall reads upds calls,
PSemAction_meth_collector f o reads upds calls calls' ->
(filter (called_by f) calls') = calls'.
Proof.
induction calls'; intros; auto.
specialize (collector_correct_pair _ (in_eq _ _) H); intro.
Opaque prod_dec.
unfold called_by; simpl; destruct prod_dec;[simpl;fold (called_by f)|symmetry in H0; contradiction].
specialize (Produce_action_from_collector _ (in_eq _ _ ) H) as TMP; dest.
apply Permutation_cons_inv in H6.
rewrite <- H6 in H8.
erewrite IHcalls'; eauto.
Transparent prod_dec.
Qed.
Corollary collector_complement_called_by_filter_nil f o calls' :
forall reads upds calls,
PSemAction_meth_collector f o reads upds calls calls' ->
(filter (complement (called_by f)) calls') = nil.
Proof.
intros.
specialize (separate_calls_by_filter calls' (called_by f)) as parti.
rewrite (collector_called_by_filter_irrel H) in parti.
rewrite <- app_nil_r in parti at 1.
apply Permutation_app_inv_l in parti.
apply Permutation_nil in parti; assumption.
Qed.
Lemma collector_correct_snd f o reads upds calls calls' call :
In call calls' ->
PSemAction_meth_collector f o reads upds calls calls' ->
exists argV retV,
snd call = (existT _ (projT1 (snd f)) (argV, retV)).
Proof.
intros.
specialize (Produce_action_from_collector _ H H0) as TMP; dest.
destruct call; inv H5; simpl; exists x6, x7; reflexivity.
Qed.
Lemma notIn_filter_nil (f : DefMethT) (calls : MethsT) :
~In (fst f, projT1 (snd f)) (getKindAttr calls) ->
filter (called_by f) calls = nil.
Proof.
induction calls; auto; simpl.
intro; dest.
unfold called_by; destruct prod_dec; simpl; auto.
apply False_ind, H; auto.
Qed.
Lemma notIn_complement_filter_irrel (f : DefMethT) (calls : MethsT) :
~In (fst f, projT1 (snd f)) (getKindAttr calls) ->
filter (complement (called_by f)) calls = calls.
Proof.
induction calls; auto; simpl; intros.
unfold called_by in *; destruct prod_dec; simpl in *;
[apply False_ind, H|rewrite IHcalls];auto.
Qed.
Lemma filter_complement_disj (A : Type) (dec : forall (a1 a2 : A), {a1=a2}+{a1<>a2}) (f : A -> bool) (l : list A) :
forall x, ~In x (filter f l) \/ ~In x (filter (complement f) l).
Proof.
intros.
destruct (in_dec dec x (filter f l)).
- rewrite filter_In in i; dest.
right; intro.
rewrite filter_In in H1; dest.
rewrite H0 in H2; discriminate.
- left; assumption.
Qed.
Lemma PSemAction_NoDup_Key_Writes k o (a : ActionT type k) readRegs newRegs calls (fret : type k) :
PSemAction o a readRegs newRegs calls fret ->
NoDup (map fst newRegs).
Proof.
induction 1;
eauto;[|
rewrite HANewRegs; simpl; econstructor; eauto; intro;
specialize (fst_produce_snd _ _ H0) as TMP; dest; specialize (HDisjRegs x);
contradiction| | |subst; econstructor];
rewrite HUNewRegs; rewrite map_app,NoDup_app_iff; repeat split; eauto;
repeat intro; specialize (HDisjRegs a0); tauto.
Qed.
Corollary PSemAction_NoDup_Writes k o (a : ActionT type k) readRegs newRegs calls (fret : type k) :
PSemAction o a readRegs newRegs calls fret ->
NoDup newRegs.
Proof.
intros; apply PSemAction_NoDup_Key_Writes in H; apply NoDup_map_inv in H; assumption.
Qed.
Lemma collector_NoDupRegs1 (f : DefMethT) o reads upds calls calls' :
PSemAction_meth_collector f o reads upds calls calls' ->
NoDup (map fst upds).
Proof.
induction 1.
- constructor.
- rewrite H2, map_app, NoDup_app_iff.
specialize (PSemAction_NoDup_Key_Writes H5) as ND2.
repeat split; auto; repeat intro; specialize (H0 a); firstorder.
Qed.
Lemma PSemAction_inline_In (f : DefMethT) o:
forall {retK2} a calls1 calls2 readRegs newRegs (retV2 : type retK2),
PSemAction o a readRegs newRegs (calls1++calls2) retV2 ->
~In (fst f, projT1 (snd f)) (getKindAttr calls2) ->
forall readRegs' newRegs' calls',
DisjKey newRegs' newRegs ->
PSemAction_meth_collector f o readRegs' newRegs' calls' calls1 ->
PSemAction o (inlineSingle a f) (readRegs' ++ readRegs) (newRegs' ++ newRegs) (calls'++calls2) retV2.
Proof.
induction a; intros.
- simpl; destruct (fst f =? meth)%string eqn:G; [rewrite String.eqb_eq in G|rewrite eqb_neq in G]; [destruct Signature_dec | ]; subst.
+ inv H0; EqDep_subst.
assert (In (fst f, existT SignT (projT1 (snd f)) (evalExpr e, mret)) calls1).
{ case (in_app_or _ _ _ (Permutation_in _ (Permutation_sym (HAcalls)) (in_eq _ _)));
auto; intros TMP;apply (in_map (fun x => (fst x, projT1 (snd x)))) in TMP; contradiction. }
specialize (Produce_action_from_collector _ H0 H3) as TMP; destruct TMP as [creads1 [creads2 [cupds1 [cupds2 [ccalls1 [ccalls2 [ccalls'' [cargV [cretV decomp]]]]]]]]].
destruct decomp as [HDisju12 [HNr21 [HC21 [HRr21 [Hceq [HC1 [HSa HSac]]]]]]].
inv Hceq; EqDep_subst.
econstructor.
* rewrite HNr21 in H2.
assert (DisjKey cupds2 (cupds1++newRegs)) as HDjk21n;[|apply HDjk21n].
intro; specialize (H2 k); specialize (HDisju12 k); rewrite map_app,in_app_iff, DeM1 in *.
clear - H2 HDisju12; firstorder fail.
* econstructor; eauto.
* rewrite HRr21, <-app_assoc.
apply Permutation_app_head.
reflexivity.
* rewrite HNr21, <-app_assoc; reflexivity.
* rewrite HC21, <-app_assoc; reflexivity.