-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimulationValid.v
1585 lines (1471 loc) · 60.5 KB
/
SimulationValid.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 syntax.
Require Import alist.
Require Import FMapWeakList.
Require Import Classical.
Require Import Coqlib.
Require Import infrastructure.
Require Import Metatheory.
Import LLVMsyntax.
Import LLVMinfra.
Require Import opsem.
Require Import sflib.
Require Import paco.
Import Opsem.
Require Import TODO.
Require Import Decs.
Require Import Hints.
Require Import Validator.
Require Import GenericValues.
Require Import TODOProof.
Require Import OpsemAux.
Require Import SimulationLocal.
Require Import Simulation.
Require Import Inject.
Require AssnMem.
Require AssnState.
Require Import ValidAux.
Require Import SoundBase.
Require Import SoundImplies.
Require Import SoundPostcondCmd.
Require Import SoundPostcondCall.
Require Import SoundPostcondPhinodes.
Require Import SoundInfrules.
Require Import SoundReduceMaydiff.
Require Import opsem_wf.
Set Implicit Arguments.
Inductive valid_state_sim
(conf_src conf_tgt:Config)
(stack0_src stack0_tgt:ECStack)
(assnmem:AssnMem.Rel.t)
(idx:nat)
(st_src st_tgt:State): Prop :=
| valid_state_sim_intro
m_src m_tgt
fdef_hint cmds_hint
inv
invst
(CONF: AssnState.valid_conf m_src m_tgt conf_src conf_tgt)
(ECS_SRC: st_src.(ECS) = stack0_src)
(ECS_TGT: st_tgt.(ECS) = stack0_tgt)
(FDEF: valid_fdef m_src m_tgt st_src.(EC).(CurFunction) st_tgt.(EC).(CurFunction) fdef_hint)
(LABEL: st_src.(EC).(CurBB).(fst) = st_tgt.(EC).(CurBB).(fst))
inv_term
(CMDS: valid_cmds m_src m_tgt st_src.(EC).(CurCmds) st_tgt.(EC).(CurCmds) cmds_hint inv = Some inv_term)
(TERM: exists infrules,
valid_terminator fdef_hint (Infrules.apply_infrules m_src m_tgt infrules inv_term) m_src m_tgt
(st_src.(EC).(CurFunction).(get_blocks))
(st_tgt.(EC).(CurFunction).(get_blocks))
(st_src.(EC).(CurBB).(fst))
(st_src.(EC).(Terminator))
(st_tgt.(EC).(Terminator)))
(STATE: AssnState.Rel.sem conf_src conf_tgt st_src st_tgt invst assnmem inv)
(MEM: AssnMem.Rel.sem conf_src conf_tgt st_src.(Mem) st_tgt.(Mem) assnmem)
(WF_SRC: wf_ConfigI conf_src /\ wf_StateI conf_src st_src)
(WF_TGT: wf_ConfigI conf_tgt /\ wf_StateI conf_tgt st_tgt)
.
Lemma decide_nonzero_inject
TD conds_src conds_tgt decision meminj
(NONZERO: decide_nonzero TD conds_src decision)
(INJECT: genericvalues_inject.gv_inject meminj conds_src conds_tgt)
:
<<NONZERO: decide_nonzero TD conds_tgt decision>>
.
Proof.
inv NONZERO.
red. econs; eauto.
eapply genericvalues_inject.simulation__GV2int; eauto.
Qed.
Lemma valid_sim_term
conf_src conf_tgt inv0 idx0
CurFunction0 CurBB0 Terminator0 Locals0 Allocas0
ECS0 Mem0 CurFunction1 CurBB1 Terminator1 Locals1 Allocas1 ECS1 Mem1
(ERROR_SRC : ~ error_state conf_src
(mkState (mkEC CurFunction0 CurBB0 [] Terminator0 Locals0 Allocas0) ECS0 Mem0))
(m_src m_tgt : module)
fdef_hint inv_term invst
(CONF : AssnState.valid_conf m_src m_tgt conf_src conf_tgt)
(FDEF : valid_fdef m_src m_tgt CurFunction0 CurFunction1 fdef_hint)
(LABEL : fst CurBB0 = fst CurBB1)
(TERM: exists infrules,
valid_terminator fdef_hint (Infrules.apply_infrules m_src m_tgt infrules inv_term)
m_src m_tgt (get_blocks CurFunction0)
(get_blocks CurFunction1) (fst CurBB0) Terminator0 Terminator1)
(MEM : AssnMem.Rel.sem conf_src conf_tgt Mem0 Mem1 inv0)
(STATE : AssnState.Rel.sem conf_src conf_tgt
(mkState (mkEC CurFunction0 CurBB0 [] Terminator0 Locals0 Allocas0) ECS0 Mem0)
(mkState (mkEC CurFunction1 CurBB1 [] Terminator1 Locals1 Allocas1) ECS1 Mem1)
invst inv0 inv_term)
(WF_SRC: wf_ConfigI conf_src /\
wf_StateI conf_src (mkState (mkEC CurFunction0 CurBB0 [] Terminator0 Locals0 Allocas0)
ECS0 Mem0))
(WF_TGT: wf_ConfigI conf_tgt /\
wf_StateI conf_tgt (mkState (mkEC CurFunction1 CurBB1 [] Terminator1 Locals1 Allocas1)
ECS1 Mem1))
:
<<SIM_TERM: _sim_local conf_src conf_tgt
(valid_state_sim conf_src conf_tgt)
ECS0 ECS1 inv0 idx0
(mkState (mkEC CurFunction0 CurBB0 [] Terminator0 Locals0 Allocas0) ECS0 Mem0)
(mkState (mkEC CurFunction1 CurBB1 [] Terminator1 Locals1 Allocas1) ECS1 Mem1)
>>
.
Proof.
des.
unfold valid_terminator in TERM.
expl apply_infrules_sound. cbn in *.
simtac;
(try by exfalso; eapply has_false_False; eauto).
destruct Terminator0, Terminator1; simtac.
+ (* return *)
move inv0 at bottom.
move assnmem1 at bottom.
eapply _sim_local_return; eauto; ss.
{ apply STATE0. }
{ eapply Forall_harder; [apply STATE0|].
s. i.
rpapply H. symmetry. apply MEM0. }
{ eapply Forall_harder; [apply STATE0|].
s. i.
rpapply H. symmetry. apply MEM0. }
{ apply STATE0. }
{ apply STATE0. }
i.
exploit AssnState.Rel.inject_value_spec; try exact COND0; eauto.
{ rewrite AssnState.Unary.sem_valueT_physical. eauto. }
i. des. rewrite AssnState.Unary.sem_valueT_physical in VAL_TGT. ss.
esplits; eauto.
econs; eauto.
* eapply get_operand_valid_ptr; eauto; try apply STATE0; try apply MEM0.
* eapply get_operand_valid_ptr; eauto; try apply STATE0; try apply MEM0.
+ (* return_void *)
eapply _sim_local_return_void; eauto; ss.
{ apply STATE. }
{ eapply Forall_harder; [apply STATE|].
s. i.
rpapply H. symmetry. apply MEM. }
{ eapply Forall_harder; [apply STATE|].
s. i.
rpapply H. symmetry. apply MEM. }
{ apply STATE. }
{ apply STATE. }
+ (* br *)
clears invst.
rename STATE0 into STATE1.
exploit nerror_nfinal_nstuck; eauto. i. des. inv x0.
rewrite <- (ite_spec decision l0 l3) in *. simtac.
exploit AssnState.Rel.inject_value_spec; eauto.
{ rewrite AssnState.Unary.sem_valueT_physical. eauto. }
rewrite AssnState.Unary.sem_valueT_physical. s. i. des.
eapply _sim_local_step; swap 2 4. (* move 2 to the end *)
{
expl progress.
- ss.
- unfold OpsemPP.undefined_state in *.
des_ifs_safe; ss.
des; ss.
{ des_ifs; ss. }
des_ifs.
exfalso.
inv H13.
inv CONF. inv INJECT0. ss. clarify.
clear - Heq0 INT INJECT.
unfold GV2int in *.
des_ifs_safe.
inv INJECT. inv H4. inv H3.
des_ifs.
- ii. ss.
}
{ splits; ss. }
{ splits; ss. }
i.
expl preservation (try exact WF_TGT0; eauto). rename preservation into WF_TGT_NEXT.
clear ERROR_SRC.
inv STEP. unfold valid_phinodes in *.
do 12 simtac0. rewrite <- (ite_spec decision0 l0 l3) in *.
{
inv CONF. inv INJECT0. ss. clarify.
expl decide_nonzero_inject_aux. clarify.
expl valid_fdef_valid_stmts (try exact COND3; eauto).
expl valid_fdef_valid_stmts (try exact COND7; eauto).
move COND1 at bottom.
move COND2 at bottom.
rename s0 into __s0__.
rename s into __s__.
Ltac abstr_gen_infrules HYP NAME :=
match goal with
| [H: context[(gen_infrules_next_inv false ?x ?y)] |- _ ] =>
check_equal H HYP;
abstr (gen_infrules_next_inv false x y) NAME
end.
Ltac abstr_gen_infrules_first HYP NAME :=
match goal with
| [H: context[(gen_infrules_next_inv true ?x ?y) ++ ?z] |- _ ] =>
check_equal H HYP;
abstr ((gen_infrules_next_inv true x y) ++ z) NAME
end.
abstr_gen_infrules COND1 infrulesA0.
abstr_gen_infrules COND2 infrulesB0.
unfold l in *.
abstr_gen_infrules_first COND1 infrulesA2.
abstr (ValidationHint.assertion_after_phinodes __s0__) inv_afterA.
assert(exists infrulesA1,
(Assertion.implies
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesA1
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesA2 t0)))) inv_afterA)).
{ des_ifsH COND1; des_bool.
- esplits; ss. eassumption.
- exists nil. ss. etransitivity; eauto.
eapply implies_reduce_maydiff; eauto. }
clear COND1.
abstr_gen_infrules_first COND2 infrulesB2.
abstr (ValidationHint.assertion_after_phinodes __s__) inv_afterB.
abstr (ValidationHint.cmds __s__) cmdsB.
assert(exists infrulesB1,
(Assertion.implies
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesB1
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesB2 t)))) inv_afterB)).
{ des_ifsH COND2; des_bool.
- esplits; ss. eassumption.
- exists nil. ss. etransitivity; eauto.
eapply implies_reduce_maydiff; eauto. }
clear COND2.
des. clarify.
(* expl add_terminator_cond_br. *)
rewrite lookupBlockViaLabelFromFdef_spec in *.
(* expl (lookupAL_ite fdef_hint decision0 l0 l3). *) (* TODO: Fix expl to pass thi *)
exploit (lookupAL_ite fdef_hint decision0 l0 l3); eauto. clear COND7 COND3. i.
exploit (lookupAL_ite CurFunction0.(get_blocks) decision0 l0 l3); eauto. clear COND8 COND4. i.
exploit (lookupAL_ite CurFunction1.(get_blocks) decision0 l0 l3); eauto. clear COND9 COND5. i.
(* TODO: apply & clear ? *)
rewrite x1 in *. clarify.
rewrite x2 in *. clarify.
expl add_terminator_cond_br.
destruct decision0; ss; clarify.
-
exploit postcond_phinodes_sound;
try exact add_terminator_cond_br; try exact COND10; try eassumption; eauto; ss; []; intro STATE2.
destruct STATE2 as [invst2 STATE2].
clears add_terminator_cond_br invst1.
exploit apply_infrules_sound; eauto; ss; []; intro STATE3.
destruct STATE3 as [invst3 [assnmem3 [STATE3 [MEM3 MEMLE3]]]]; des.
clears invst2.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE4.
destruct STATE4 as [invst4 STATE4]; des.
clears invst3.
exploit apply_infrules_sound; eauto; ss; []; intro STATE5.
destruct STATE5 as [invst5 [assnmem5 [STATE5 [MEM5 MEMLE5]]]]; des.
clears invst4.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE6.
destruct STATE6 as [invst6 STATE6]; des.
clears invst5.
assert(AssnMem.Rel.le inv0 assnmem5).
{ etransitivity; eauto. etransitivity; eauto. }
esplits; eauto.
{ econs 1. econs; eauto. rewrite lookupBlockViaLabelFromFdef_spec. ss. }
{
econs; eauto; ss.
- eapply implies_sound; eauto.
{ ss. }
- split; ss.
eapply preservation; eauto.
rpapply sBranch; eauto. ss.
rewrite lookupBlockViaLabelFromFdef_spec. ss.
(* Are we lucky? Will there be no siuation that forces us to get wf_src before esplits? *)
(* Will we always be able to (easy to) re-construct sInsn like this? *)
}
-
exploit postcond_phinodes_sound;
try exact add_terminator_cond_br; try exact COND6; try eassumption; eauto; ss; []; intro STATE2.
destruct STATE2 as [invst2 STATE2].
clears add_terminator_cond_br invst1.
exploit apply_infrules_sound; eauto; ss; []; intro STATE3.
destruct STATE3 as [invst3 [assnmem3 [STATE3 [MEM3 MEMLE3]]]]; des.
clears invst2.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE4.
destruct STATE4 as [invst4 STATE4]; des.
clears invst3.
exploit apply_infrules_sound; eauto; ss; []; intro STATE5.
destruct STATE5 as [invst5 [assnmem5 [STATE5 [MEM5 MEMLE5]]]]; des.
clears invst4.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE6.
destruct STATE6 as [invst6 STATE6]; des.
clears invst5.
assert(AssnMem.Rel.le inv0 assnmem5).
{ etransitivity; eauto. etransitivity; eauto. }
esplits; eauto.
{ econs 1. econs; eauto. rewrite lookupBlockViaLabelFromFdef_spec. ss. }
{
econs; eauto; ss.
(* - eapply inject_allocas_inj_incr; eauto. *)
- eapply implies_sound; eauto.
{ ss. }
- split; ss.
eapply preservation; eauto.
rpapply sBranch; eauto. ss.
rewrite lookupBlockViaLabelFromFdef_spec. ss.
}
}
+ (* br_uncond *)
clears invst.
rename STATE0 into STATE1.
exploit nerror_nfinal_nstuck; eauto. i. des. inv x0.
eapply _sim_local_step; swap 2 4. (* move 2 to the end *)
{
expl progress.
- ss.
- unfold OpsemPP.undefined_state in *.
des_ifs; des; ss.
- ii. ss.
}
{ split; ss. }
{ split; ss. }
i.
expl preservation. rename preservation into WF_TGT_NEXT.
clear ERROR_SRC.
inv STEP. unfold valid_phinodes in *.
{
inv CONF. inv INJECT. ss. clarify.
repeat (simtac0; []).
expl valid_fdef_valid_stmts.
hide_goal.
abstr_gen_infrules COND0 infrulesA0.
unfold l in *.
abstr_gen_infrules_first COND0 infrulesA2.
abstr (ValidationHint.assertion_after_phinodes s) inv_afterA.
assert(exists infrulesA1,
(Assertion.implies
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesA1
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesA2 t)))) inv_afterA)).
{ des_ifsH COND0; des_bool.
- esplits; ss. eassumption.
- exists nil. ss. etransitivity; eauto.
eapply implies_reduce_maydiff; eauto. }
clear COND0.
des. clarify.
rewrite lookupBlockViaLabelFromFdef_spec in *.
rewrite COND2 in *. rewrite COND3 in *. clarify.
rewrite add_terminator_cond_br_uncond in *.
-
exploit postcond_phinodes_sound;
try eassumption; eauto; ss; []; intro STATE2.
destruct STATE2 as [invst2 STATE2].
clears invst1.
exploit apply_infrules_sound; eauto; ss; []; intro STATE3.
destruct STATE3 as [invst3 [assnmem3 [STATE3 [MEM3 MEMLE3]]]]; des.
clears invst2.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE4.
destruct STATE4 as [invst4 STATE4]; des.
clears invst3.
exploit apply_infrules_sound; eauto; ss; []; intro STATE5.
destruct STATE5 as [invst5 [assnmem5 [STATE5 [MEM5 MEMLE5]]]]; des.
clears invst4.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE6.
destruct STATE6 as [invst6 STATE6]; des.
clears invst5.
assert(AssnMem.Rel.le inv0 assnmem5).
{ etransitivity; eauto. etransitivity; eauto. }
unfold HIDDEN_GOAL.
esplits; eauto.
{ econs 1. econs; eauto. rewrite lookupBlockViaLabelFromFdef_spec. ss. }
{
econs; eauto; ss.
(* - eapply inject_allocas_inj_incr; eauto. *)
- eapply implies_sound; eauto.
{ ss. }
- split; ss.
eapply preservation; eauto.
econs; eauto.
rewrite lookupBlockViaLabelFromFdef_spec. ss.
}
}
+ (* switch *)
clears invst.
rename STATE0 into STATE1.
exploit nerror_nfinal_nstuck; eauto. i. des. inv x0.
eapply _sim_local_step; swap 2 4. (* move 2 to the end *)
{
expl progress.
- ss.
- unfold OpsemPP.undefined_state in *.
des_ifs_safe; ss.
des; ss.
{ des_ifs. }
des_ifs.
exfalso.
inv CONF. inv INJECT. ss. clarify.
exploit AssnState.Rel.inject_value_spec; eauto.
{ ss. }
{ rewrite AssnState.Unary.sem_valueT_physical. ss. eauto. }
i; des. rewrite AssnState.Unary.sem_valueT_physical in *. ss. clarify.
clear - INJECT Heq1 Heq0.
unfold GV2int in *.
des_ifs_safe.
inv INJECT. inv H4. inv H3.
des_ifs.
- ii. ss.
}
{ split; ss. }
{ split; ss. }
i.
expl preservation. rename preservation into WF_TGT_NEXT.
clear ERROR_SRC.
inv STEP. unfold valid_phinodes in *.
{
inv CONF. inv INJECT. ss. clarify.
des_sumbool. subst. (* list_const_l_dec *)
rename l_0 into dflt.
rename l1 into cases.
rename COND3 into COND_DFLT.
rename COND2 into COND_CASES.
repeat (simtac0; []).
rename COND4 into PCOND_DFLT.
hexploit AssnState.Rel.inject_value_spec; try exact STATE1; ss; eauto.
{ rewrite AssnState.Unary.sem_valueT_physical. eauto. }
i; des.
rewrite AssnState.Unary.sem_valueT_physical in *. ss. clarify.
expl get_switch_branch_inject. clarify.
hide_goal.
expl add_terminator_cond_switch.
expl get_switch_branch_in_successors.
unfold successors_terminator in *.
apply nodup_In in get_switch_branch_in_successors0. ss. des.
{ (* default *)
expl valid_fdef_valid_stmts.
clear COND_CASES.
subst dflt.
rewrite lookupBlockViaLabelFromFdef_spec in *.
move H19 at bottom.
move COND3 at bottom.
move get_switch_branch_inject at bottom.
eq_closure_tac. clarify.
abstr_gen_infrules COND_DFLT infrulesA0.
unfold l in *.
abstr_gen_infrules_first COND_DFLT infrulesA2.
abstr (ValidationHint.assertion_after_phinodes s) inv_afterA.
assert(exists infrulesA1,
(Assertion.implies
(Postcond.reduce_maydiff
(Infrules.apply_infrules
m_src m_tgt infrulesA1
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesA2 t)))) inv_afterA)).
{ des_ifsH COND_DFLT; des_bool.
- esplits; ss. eassumption.
- exists nil. ss. etransitivity; eauto.
eapply implies_reduce_maydiff; eauto. }
clear COND_DFLT.
des.
exploit postcond_phinodes_sound; try exact PCOND_DFLT; try exact add_terminator_cond_switch;
ss; eauto; []; intro STATE2. destruct STATE2 as [invst2 STATE2].
clears invst1.
exploit apply_infrules_sound; eauto; ss; []; intro STATE3.
destruct STATE3 as [invst3 [assnmem3 [STATE3 [MEM3 MEMLE3]]]]; des.
clears invst2.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE4.
destruct STATE4 as [invst4 STATE4]; des.
clears invst3.
exploit apply_infrules_sound; eauto; ss; []; intro STATE5.
destruct STATE5 as [invst5 [assnmem5 [STATE5 [MEM5 MEMLE5]]]]; des.
clears invst4.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE6.
destruct STATE6 as [invst6 STATE6]; des.
clears invst5.
assert(AssnMem.Rel.le inv0 assnmem5).
{ etransitivity; eauto. etransitivity; eauto. }
unfold HIDDEN_GOAL.
esplits; eauto.
{ econs 1. econs; eauto. rewrite lookupBlockViaLabelFromFdef_spec. ss. }
{
econs; eauto; ss.
- eapply implies_sound; eauto.
{ ss. }
- split; ss.
eapply preservation; eauto.
econs; eauto.
rewrite lookupBlockViaLabelFromFdef_spec. ss.
}
}
{ (* cases *)
(* clears dflt. *)
clear COND_DFLT PCOND_DFLT COND1 COND2 COND3.
apply list_prj2_inv in get_switch_branch_in_successors0. des.
rewrite forallb_forall in COND_CASES.
specialize (COND_CASES (x, tgt0) get_switch_branch_in_successors0).
clear get_switch_branch_in_successors0.
des_bool. des_ifs_safe. des_bool.
clear_tac. rename Heq into COND_CASES. rename Heq3 into PCOND_CASES.
rewrite lookupBlockViaLabelFromFdef_spec in *.
ss. eq_closure_tac. clarify.
expl valid_fdef_valid_stmts. ss.
abstr_gen_infrules COND_CASES infrulesA0.
unfold l in *.
abstr_gen_infrules_first COND_CASES infrulesA2.
abstr (ValidationHint.assertion_after_phinodes s0) inv_afterA.
assert(exists infrulesA1,
(Assertion.implies
(Postcond.reduce_maydiff
(Infrules.apply_infrules
m_src m_tgt infrulesA1
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt infrulesA2 t0)))) inv_afterA)).
{ des_ifsH COND_CASES; des_bool.
- esplits; ss. eassumption.
- exists nil. ss. etransitivity; eauto.
eapply implies_reduce_maydiff; eauto. }
clear COND_CASES.
des.
exploit postcond_phinodes_sound; try exact PCOND_CASES; try exact add_terminator_cond_switch;
ss; eauto; []; intro STATE2. destruct STATE2 as [invst2 STATE2].
clears invst1.
exploit apply_infrules_sound; eauto; ss; []; intro STATE3.
destruct STATE3 as [invst3 [assnmem3 [STATE3 [MEM3 MEMLE3]]]]; des.
clears invst2.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE4.
destruct STATE4 as [invst4 STATE4]; des.
clears invst3.
exploit apply_infrules_sound; eauto; ss; []; intro STATE5.
destruct STATE5 as [invst5 [assnmem5 [STATE5 [MEM5 MEMLE5]]]]; des.
clears invst4.
exploit reduce_maydiff_sound; eauto; ss; []; intro STATE6.
destruct STATE6 as [invst6 STATE6]; des.
clears invst5.
assert(AssnMem.Rel.le inv0 assnmem5).
{ etransitivity; eauto. etransitivity; eauto. }
unfold HIDDEN_GOAL.
esplits; eauto.
{ econs 1. econs; eauto. rewrite lookupBlockViaLabelFromFdef_spec. ss. }
{
econs; eauto; ss.
(* - eapply inject_allocas_inj_incr; eauto. *)
- eapply implies_sound; eauto.
{ ss. }
- split; ss.
eapply preservation; eauto.
econs; eauto.
rewrite lookupBlockViaLabelFromFdef_spec. ss.
}
}
}
+ (* unreachable *)
exploit nerror_nfinal_nstuck; eauto. i. des. inv x0.
Unshelve.
all: try destruct CONF; subst; ss.
Qed.
(* TODO: Pull out same pattern as lemma or tac *)
(* TODO: move to postcond.v? SoundBase? Maybe this is proper position.. *)
Lemma postcond_cmd_implies_inject_event
c0 c1 inv t
(POSTCOND: Postcond.postcond_cmd c0 c1 inv = Some t)
:
<<INJECT_EVENT: Postcond.postcond_cmd_inject_event
c0 c1
(if Instruction.isCallInst c0
then
Postcond.ForgetStackCall.t (AtomSetImpl_from_list (Postcond.Cmd.get_def c0))
(AtomSetImpl_from_list (Postcond.Cmd.get_def c1))
(Postcond.ForgetMemoryCall.t inv)
else
Postcond.ForgetStack.t
(AtomSetImpl_from_list (Postcond.Cmd.get_def c0))
(AtomSetImpl_from_list (Postcond.Cmd.get_def c1))
(AtomSetImpl_from_list (Postcond.Cmd.get_leaked_ids c0))
(AtomSetImpl_from_list (Postcond.Cmd.get_leaked_ids c1))
(Postcond.ForgetMemory.t (Postcond.Cmd.get_def_memory c0)
(Postcond.Cmd.get_def_memory c1)
(Postcond.Cmd.get_leaked_ids_to_memory c0)
(Postcond.Cmd.get_leaked_ids_to_memory c1) inv))
= true>>
.
Proof.
unfold Postcond.postcond_cmd in *.
unfold Postcond.postcond_cmd_check in *.
des_ifs; ss; des_bool; ss.
Qed.
Lemma valid_progress
conf_src conf_tgt stack0_src stack0_tgt inv0 idx0 st_src st_tgt
(VALID: valid_state_sim conf_src conf_tgt stack0_src stack0_tgt inv0 idx0 st_src st_tgt)
(ERROR_SRC: ~ error_state conf_src st_src)
c_src cs_src
(CMDSRC: st_src.(EC).(CurCmds) = c_src :: cs_src)
(NOTCALL: Instruction.isCallInst c_src = false)
c_tgt cs_tgt
(CMDTGT: st_tgt.(EC).(CurCmds) = c_tgt :: cs_tgt)
(NOTFINAL: s_isFinalState conf_tgt st_tgt = None)
:
<<PROGRESS: ~stuck_state conf_tgt st_tgt>>
.
Proof.
inv VALID.
des.
expl progress; ss. clear WF_TGT WF_TGT0.
destruct st_src, st_tgt; ss.
destruct EC0, EC1; ss.
destruct CurCmds0, CurCmds1; ss. clarify; clear_tac.
des_ifs_safe.
unfold OpsemPP.undefined_state in *.
des_ifs_safe.
des; ss.
- des_ifs; ss.
- des_ifsH IS_UNDEFINED; ss.
unfold Debug.debug_print_auto in *.
unfold Debug.failwith_None in *.
des_ifs_safe.
Abort.
Hint Unfold Debug.debug_print_auto. (* TODO: Put all debugs into this *)
Hint Unfold Debug.debug_print_validation_process.
Lemma apply_is_true
x
:
is_true x <-> x = true (* using << >> here will unable rewrite *)
.
Proof. ss. Qed.
Lemma valid_sim
conf_src conf_tgt
:
(valid_state_sim conf_src conf_tgt) <6= (sim_local conf_src conf_tgt).
Proof.
pcofix CIH.
intros stack0_src stack0_tgt inv0 idx0 st_src st_tgt SIM. pfold.
apply _sim_local_src_error; try apply SIM; []. i.
destruct st_src, st_tgt. destruct EC0, EC1.
inv SIM. ss.
destruct CurCmds0.
- (* term *)
des.
simtac.
expl valid_sim_term.
eapply _sim_local_mon; eauto.
- (* cmd *)
ss. des_ifs_safe. Fail progress repeat (simtac0; []).
destruct (Assertion.has_false inv) eqn:T.
{ exfalso; eapply has_false_False; eauto. }
autounfold in *. ss.
destruct (match Postcond.postcond_cmd c c0 inv with
| Some inv1 => Some inv1
| None =>
Postcond.postcond_cmd
c c0
(Infrules.apply_infrules m_src m_tgt
(gen_infrules_from_insns (insn_cmd c) (insn_cmd c0) inv) inv)
end) eqn: PCND; try by ss.
abstr (gen_infrules_next_inv true t0 inv ++ l1) l2.
clear l1. rename l2 into l1. (* to minimize proof break *)
rename t into __t__.
assert(PCND0: exists infrulesA,
Postcond.postcond_cmd
c c0
(Infrules.apply_infrules m_src m_tgt infrulesA inv) = Some t0).
{ clear CMDS.
des_ifs.
- exists nil. esplits; ss.
- esplits; eassumption.
} clear PCND. des.
des_ifs_safe ss.
assert(IMPLIES: exists infrulesB,
Assertion.implies
(Postcond.reduce_maydiff
(Infrules.apply_infrules
m_src m_tgt infrulesB
(Postcond.reduce_maydiff
(Infrules.apply_infrules m_src m_tgt l1 t0)))) __t__ = true).
{ des_ifs.
- exists nil. ss.
rewrite <- apply_is_true.
rewrite <- apply_is_true in Heq0.
etransitivity; eauto.
eapply implies_reduce_maydiff.
- esplits; eassumption.
} clear Heq. des.
exploit apply_infrules_sound; try apply STATE; eauto; []; intro PCND;
destruct PCND as [invst_pcnd [assnmem_pcnd [STATE_PCND [MEM_PCND MEMLE_PCND]]]]. des.
clears invst.
(* clears inv0. *)
(* MEMLE should survive. *)
(* TODO: if we can make a lemma, sim_local inv0 && inv0 <= inv1 => sim_local inv1, we can *)
(* do "clears inv0". *)
(* The lemma is not true for now, (AssnMem.Rel.le not relaxed in all cases) but it seems ok *)
clear MEM.
instantiate (1:= infrulesA) in STATE_PCND.
abstr (Infrules.apply_infrules m_src m_tgt infrulesA inv) inv_pcnd.
clears inv.
rename MEM_PCND into MEM1.
rename MEMLE_PCND into MEMLE1.
rename STATE_PCND into STATE1.
rename invst_pcnd into invst1.
rename assnmem_pcnd into assnmem1.
rename inv_pcnd into inv1.
destruct (Instruction.isCallInst c) eqn:CALL; cycle 1.
+ ss.
simtac. des.
eapply _sim_local_step; swap 2 4. (* move 2 to the end *)
{
expl progress.
- ss.
- move ERROR_SRC at bottom.
apply error_state_neg in ERROR_SRC. des; ss. apply NNPP in ERROR_SRC. des.
rename ERROR_SRC into SRC_STEP.
rename PCND0 into POSTCOND.
(* rename inv into inv0. *)
move POSTCOND at bottom.
destruct conf_src; ss.
inv CONF. inv INJECT. ss. clarify.
eapply postcond_cmd_implies_inject_event in POSTCOND; des. rewrite CALL in *.
unfold OpsemPP.undefined_state in *.
des_ifs_safe. des; ss; des_ifs_safe; ss.
+ des_ifs; ss.
+ exfalso.
destruct c; des_ifs. ss. repeat (des_bool; des; des_sumbool). clarify.
inv SRC_STEP.
unfold alloca in *. des_ifs.
assert(INJECT : genericvalues_inject.gv_inject (AssnMem.Rel.inject assnmem1) gn g).
{
eapply AssnState.Subset.inject_value_Subset in POSTCOND1; cycle 1.
{ instantiate (1:= inv1).
etransitivity; eauto.
{ eapply SoundForgetStack.forget_stack_Subset; eauto. }
etransitivity; eauto.
{ eapply SoundForgetMemory.forget_memory_Subset; eauto. }
reflexivity.
}
exploit AssnState.Rel.inject_value_spec; try exact POSTCOND1; eauto.
{ ss. }
{ rewrite AssnState.Unary.sem_valueT_physical. ss. eauto. }
i; des.
rewrite AssnState.Unary.sem_valueT_physical in *. ss. rewrite Heq in *. clarify.
}
expl genericvalues_inject.simulation__GV2int. rewrite simulation__GV2int in *. ss.
+ exfalso.
destruct c; des_ifs. ss. des_bool; des. des_sumbool. clarify.
inv SRC_STEP.
assert(INJECT : genericvalues_inject.gv_inject (AssnMem.Rel.inject assnmem1) mptr0 g).
{
eapply AssnState.Subset.inject_value_Subset in POSTCOND0; cycle 1.
{ instantiate (1:= inv1).
etransitivity; eauto.
{ eapply SoundForgetStack.forget_stack_Subset; eauto. }
etransitivity; eauto.
{ eapply SoundForgetMemory.forget_memory_Subset; eauto. }
reflexivity.
}
exploit AssnState.Rel.inject_value_spec; try exact POSTCOND0; eauto.
{ ss. }
{ rewrite AssnState.Unary.sem_valueT_physical. ss. rewrite <- H17. ss. }
i; des.
rewrite AssnState.Unary.sem_valueT_physical in *. ss. rewrite Heq in *. clarify.
}
{
(* free inject. easy *)
unfold free in *. des_ifs_safe.
unfold GV2ptr in *. des_ifs_safe.
repeat all_with_term ltac:(fun H => inv H) genericvalues_inject.gv_inject.
repeat all_with_term ltac:(fun H => inv H) memory_sim.MoreMem.val_inject.
exploit genericvalues_inject.mem_inj__free; eauto; try apply MEM1; i; des.
assert(delta = 0).
{ inv MEM1. ss. inv WF. expl mi_bounds. }
clarify.
repeat rewrite Z.add_0_r in *.
rewrite <- int_add_0 in *. clarify.
des_ifs.
exploit genericvalues_inject.mi_bounds.
{ apply MEM1. }
{ eauto. }
i; des.
eq_closure_tac.
clarify.
}
+
destruct c; des_ifs; ss; repeat (des_bool; des; des_sumbool; clarify).
(* * (* nop case *) *)
(* exfalso. *)
(* rewrite SoundSnapshot.ExprPairSet_exists_filter in POSTCOND. *)
(* apply Exprs.ExprPairSetFacts.exists_iff in POSTCOND; [|solve_compat_bool]. *)
(* unfold Exprs.ExprPairSet.Exists in *. des. *)
(* des_ifs. des_bool. des. unfold compose in *. des_bool. *)
(* apply Exprs.ExprPairSetFacts.mem_iff in POSTCOND. *)
(* { *)
(* des. des_sumbool. clarify. *)
(* assert(NOT_IN_MD: Assertion.not_in_maydiff inv1 *)
(* (Exprs.ValueT.lift Exprs.Tag.physical value1)). *)
(* { *)
(* expl SoundForgetStack.forget_stack_Subset. *)
(* eapply AssnState.Subset.not_in_maydiff_Subset; eauto. *)
(* } clear POSTCOND0. *)
(* assert(DEFINED: exists val, const2GV CurTargetData0 Globals0 (const_undef typ5) = *)
(* Some val). *)
(* { AD-MIT " *)
(* Issue on encoding definedness with undef. *)
(* More explanation on: https://github.com/snu-sf/crellvm/issues/426". } *)
(* des. *)
(* exploit AssnState.Rel.lessdef_expr_spec; eauto. *)
(* { apply STATE1. } *)
(* { unfold AssnState.Unary.sem_expr. ss. eauto. } *)
(* i; des. ss. rewrite AssnState.Unary.sem_valueT_physical in *. ss. des_ifs. *)
(* exploit AssnState.Rel.not_in_maydiff_value_spec; try apply STATE1; eauto. *)
(* { ss. } *)
(* { rewrite AssnState.Unary.sem_valueT_physical. ss. eauto. } *)
(* i; des. *)
(* rewrite AssnState.Unary.sem_valueT_physical in *. ss. *)
(* { *)
(* (* load inject. easy *) *)
(* unfold mload in *. des_ifs_safe. *)
(* unfold GV2ptr in *. des_ifs_safe. *)
(* rename g into __g__. *)
(* repeat all_with_term ltac:(fun H => inv H) genericvalues_inject.gv_inject. *)
(* repeat all_with_term ltac:(fun H => inv H) memory_sim.MoreMem.val_inject. *)
(* exploit genericvalues_inject.simulation_mload_aux; eauto; try apply MEM1; i; des. *)
(* assert(delta = 0). *)
(* { inv MEM1. ss. inv WF. expl mi_bounds. } *)
(* clarify. *)
(* rewrite Z.add_0_r in *. *)
(* rewrite <- int_add_0 in *. clarify. *)
(* } *)
(* } *)
* exfalso.
inv SRC_STEP.
assert(INJECT : genericvalues_inject.gv_inject (AssnMem.Rel.inject assnmem1) mp g).
{
eapply AssnState.Subset.inject_value_Subset in POSTCOND0; cycle 1.
{ instantiate (1:= inv1).
etransitivity; eauto.
{ eapply SoundForgetStack.forget_stack_Subset; eauto. }
etransitivity; eauto.
{ eapply SoundForgetMemory.forget_memory_Subset; eauto. }
reflexivity.
}
exploit AssnState.Rel.inject_value_spec; try exact POSTCOND0; eauto.
{ ss. }
{ rewrite AssnState.Unary.sem_valueT_physical. ss. rewrite <- H18. ss. }
i; des.
rewrite AssnState.Unary.sem_valueT_physical in *. ss. rewrite Heq in *. clarify.
}
{
(* load inject. easy *)
unfold mload in *. des_ifs_safe.
unfold GV2ptr in *. des_ifs_safe.
repeat all_with_term ltac:(fun H => inv H) genericvalues_inject.gv_inject.
repeat all_with_term ltac:(fun H => inv H) memory_sim.MoreMem.val_inject.
exploit genericvalues_inject.simulation_mload_aux; eauto; try apply MEM1; i; des.
assert(delta = 0).
{ inv MEM1. ss. inv WF. expl mi_bounds. }
clarify.
rewrite Z.add_0_r in *.
rewrite <- int_add_0 in *. clarify.
}
+ exfalso.
destruct c; des_ifs; ss; repeat (des_bool; des; des_sumbool; clarify).
inv SRC_STEP.
assert(INJECT1 : genericvalues_inject.gv_inject (AssnMem.Rel.inject assnmem1) gv1 g).
{
eapply AssnState.Subset.inject_value_Subset in POSTCOND1; cycle 1.
{ instantiate (1:= inv1).
etransitivity; eauto.
{ eapply SoundForgetStack.forget_stack_Subset; eauto. }
etransitivity; eauto.
{ eapply SoundForgetMemory.forget_memory_Subset; eauto. }
reflexivity.
}
exploit AssnState.Rel.inject_value_spec; try exact POSTCOND1; eauto.
{ ss. }
{ rewrite AssnState.Unary.sem_valueT_physical. ss. rewrite <- H19. ss. }
i; des.
rewrite AssnState.Unary.sem_valueT_physical in *. ss. rewrite Heq in *. clarify.
}
assert(INJECT2 : genericvalues_inject.gv_inject (AssnMem.Rel.inject assnmem1) mp2 g0).
{
eapply AssnState.Subset.inject_value_Subset in POSTCOND0; cycle 1.
{ instantiate (1:= inv1).
etransitivity; eauto.
{ eapply SoundForgetStack.forget_stack_Subset; eauto. }
etransitivity; eauto.
{ eapply SoundForgetMemory.forget_memory_Subset; eauto. }
reflexivity.
}
exploit AssnState.Rel.inject_value_spec; try exact POSTCOND0; eauto.
{ ss. }
{ rewrite AssnState.Unary.sem_valueT_physical. ss. rewrite <- H20. ss. }
i; des.
rewrite AssnState.Unary.sem_valueT_physical in *. ss. rewrite Heq0 in *. clarify.
}
{
(* mstore inject. easy *)
unfold mstore in *. des_ifs_safe.
unfold GV2ptr in *. des_ifs_safe.
inv INJECT2. inv H4.
repeat all_with_term ltac:(fun H => inv H) memory_sim.MoreMem.val_inject.
exploit genericvalues_inject.mem_inj_mstore_aux; eauto; try apply MEM1; i; des.
assert(delta = 0).
{ inv MEM1. ss. inv WF. expl mi_bounds. }
clarify.
rewrite Z.add_0_r in *.
rewrite <- int_add_0 in *. clarify.
}
+ destruct c; ss.
- i; ss.
}
{ split; ss. }
{ split; ss. }
i.
expl preservation. rename preservation into WF_TGT_NEXT.
exploit postcond_cmd_is_call; eauto. i. rewrite CALL in x0.