-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmilExecutableIOScript.sml
2517 lines (2353 loc) · 133 KB
/
milExecutableIOScript.sml
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
open HolKernel boolLib Parse bossLib wordsLib optionTheory wordsTheory finite_mapTheory pred_setTheory listTheory rich_listTheory sortingTheory ottTheory milUtilityTheory milTheory milSemanticsUtilityTheory milTracesTheory milMetaTheory milInitializationTheory milExecutableUtilityTheory milExecutableTransitionTheory milExecutableCompletenessTheory;
(* ======================================== *)
(* IO execution of bounded number of steps *)
(* ======================================== *)
val _ = new_theory "milExecutableIO";
(* --------------------------------- *)
(* Function and property definitions *)
(* --------------------------------- *)
(* TODO: easy optimization to put transitions at head of exec, reverse the final list *)
Definition IO_bounded_execution_acc:
IO_bounded_execution_acc
(f_tran: v -> t -> i list)
(f_sem: e -> (t |-> v) -> v option)
(State_st_list l s cs fs) (pos:num) (n:num)
(exec:(State_list # ll # State_list) list) :
((State_list # ll # State_list) list) option =
case n of
| 0 => SOME exec
| SUC n' =>
(case DROP pos l of
| [] => SOME exec
| i_assign t c mop::il =>
(case FLOOKUP s t of
| NONE =>
(case f_sem c s of
| NONE => NONE
| SOME v =>
if v <> val_false then
(case sem_instr_exe f_sem (i_assign t c mop) (State_st_list l s cs fs) of
| NONE => NONE
| SOME (v',obs) =>
let (ll,stl) = OoO_Exe_list_instr_not_stored_guard_true_sem_instr
(State_st_list l s cs fs) (i_assign t c mop) v' obs in
case mop of
| o_store res_MEM ta tv =>
(case OoO_Cmt_list_stored f_sem stl t ta tv of
| NONE => NONE
| SOME (ll',stl') =>
IO_bounded_execution_acc f_tran f_sem stl' (SUC pos) n'
(exec++[(State_st_list l s cs fs,ll,stl);(stl,ll',stl')]))
| o_store res_PC ta tv =>
(case OoO_Ftc_list_stored f_tran f_sem stl t v' of
| NONE => NONE
| SOME (ll',stl') =>
IO_bounded_execution_acc f_tran f_sem stl' (SUC pos) n'
(exec++[(State_st_list l s cs fs,ll,stl);(stl,ll',stl')]))
| _ => (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem stl (SUC pos) n'
(exec++[(State_st_list l s cs fs,ll,stl)]))
else (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem (State_st_list l s cs fs) (SUC pos) n' exec)
| SOME v =>
(case mop of
| o_store res_MEM ta tv =>
if MEM t cs then (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem (State_st_list l s cs fs) (SUC pos) n' exec
else
(case OoO_Cmt_list_stored_incomplete f_sem (State_st_list l s cs fs) t ta tv of
| NONE => NONE
| SOME (ll,stl) => (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem stl (SUC pos) n'
(exec++[(State_st_list l s cs fs,ll,stl)]))
| o_store res_PC ta tv =>
if MEM t fs then (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem (State_st_list l s cs fs) (SUC pos) n' exec
else
(case OoO_Ftc_list_stored_incomplete f_tran f_sem (State_st_list l s cs fs) t v of
| NONE => NONE
| SOME (ll,stl) => (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem stl (SUC pos) n'
(exec++[(State_st_list l s cs fs,ll,stl)]))
| _ => (* instruction is completed, move on *)
IO_bounded_execution_acc f_tran f_sem (State_st_list l s cs fs) (SUC pos) n' exec)))
End
(* FIXME: double check how PRE affects all theorem statements *)
Definition IO_bounded_execution:
IO_bounded_execution
(f_tran : v -> t -> i list)
(f_sem: e -> (t |-> v) -> v option)
(stl:State_list) (pos:num) (n:num) :
((State_list # ll # State_list) list) option =
IO_bounded_execution_acc f_tran f_sem stl (PRE pos) n []
End
Definition step_execution_list_OoO_HD:
step_execution_list_OoO_HD stl pi n =
(FST (HD pi) = stl /\
step_execution out_of_order_step_list pi /\
LENGTH pi <= 2*n)
End
Definition step_execution_list_IO_HD:
step_execution_list_IO_HD stl pi pos n =
(FST (HD pi) = stl /\
step_execution in_order_step_list pi /\
Completed_list_up_to sem_expr (SND (SND (LAST pi))) (pos + n) /\
LENGTH pi <= 2*n)
End
(* ----------------------- *)
(* Execution OoO soundness *)
(* ----------------------- *)
Theorem NO_DUPLICATES_FIND_instr:
!l t i.
NO_DUPLICATES l ==>
MEM i l ==>
bound_name_instr i = t ==>
FIND_instr t l = SOME i
Proof
rw [] >>
Cases_on `FIND_instr (bound_name_instr i) l` >-
METIS_TAC [FIND_instr_eq_NONE,MEM_MAP,NO_DUPLICATES_bound_name_instr] >>
METIS_TAC [FIND_instr_eq_SOME,NO_DUPLICATES_bound_name_instr]
QED
(* FIXME: extract lemma on one-step cases *)
Theorem IO_bounded_execution_acc_OoO_execution_sound:
!n stl pos pi pi'.
State_st_list_well_formed_ok stl ==>
step_execution out_of_order_step_list pi ==>
SND (SND (LAST pi)) = stl ==>
IO_bounded_execution_acc translate_val_list sem_expr stl pos n pi = SOME pi' ==>
?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2*n
Proof
Induct_on `n` >>
Cases_on `stl` >> rename1 `State_st_list l s cs fs` >-
fs [IO_bounded_execution_acc] >>
once_rewrite_tac [IO_bounded_execution_acc] >>
fs [] >> rw [] >>
Cases_on `DROP pos l` >> fs [] >>
Cases_on `h` >>
rename1 `i_assign t' c mop::l'` >> rename1 `i_assign t c mop` >>
fs [] >>
Cases_on `FLOOKUP s t` >> fs [] >-
(Cases_on `sem_expr c s` >> fs [] >>
rename1 `sem_expr c s = SOME v` >>
Cases_on `v = val_false` >> fs [] >-
(`?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw []) >>
Cases_on `sem_instr_exe sem_expr (i_assign t c mop) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> rename1 `(v',obs)` >> fs [] >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr
(State_st_list l s cs fs) (i_assign t c mop) v' obs` >>
fs [] >> rename1 `(ll,stl)` >>
`MEM (i_assign t c mop) l` by METIS_TAC [DROP_HEAD_MEM] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [State_st_list_well_formed_ok_OoO_Exe_list_instr_not_stored_guard_true_sem_instr] >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`FIND_instr t l = SOME (i_assign t c mop)`
by METIS_TAC [State_st_list_ok,NO_DUPLICATES_FIND_instr,bound_name_instr] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
Cases_on `mop` >> fs [] >| [
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e'` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++ [(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`],
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r'` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++ [(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`],
Cases_on `r` >> fs [] >| [
Cases_on `OoO_Ftc_list_stored translate_val_list sem_expr stl t v'` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(ll',stl')` >>
rename1 `o_store res_PC ta tv` >>
`stl = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')]` >>
`FLOOKUP (s |+ (t,v')) t = SOME v'` by fs [FLOOKUP_UPDATE] >>
`State_st_list_well_formed_ok stl'`
by METIS_TAC [State_st_list_well_formed_ok_OoO_Ftc_list_stored] >>
`out_of_order_step_list (State_st_list l (s |+ (t,v')) cs fs) ll' stl'`
by METIS_TAC [OoO_Ftc_list_stored_SOME_out_of_order_step_list] >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`step_execution out_of_order_step_list
(pi ++ [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)])`
suffices_by METIS_TAC [step_execution_rules] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++
[(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);
(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl'` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`],
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++
[(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);
(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`],
rename1 `o_store res_MEM ta tv` >>
Cases_on `OoO_Cmt_list_stored sem_expr stl t ta tv` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(ll',stl')` >>
`stl = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')]` >>
`FLOOKUP (s |+ (t,v')) t = SOME v'` by fs [FLOOKUP_UPDATE] >>
`FLOOKUP (s |+ (t,v')) t <> NONE` by fs [] >>
`State_st_list_well_formed_ok stl'`
by METIS_TAC [State_st_list_well_formed_ok_OoO_Cmt_list_stored] >>
`out_of_order_step_list (State_st_list l (s |+ (t,v')) cs fs) ll' stl'`
by METIS_TAC [OoO_Cmt_list_stored_SOME_out_of_order_step_list] >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`step_execution out_of_order_step_list
(pi ++ [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)])`
suffices_by METIS_TAC [step_execution_rules] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++
[(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);
(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl'` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`]
]
]) >>
`MEM (i_assign t c mop) l` by METIS_TAC [DROP_HEAD_MEM] >>
`FIND_instr t l = SOME (i_assign t c mop)`
by METIS_TAC [State_st_list_well_formed_ok,State_st_list_ok,NO_DUPLICATES_FIND_instr,bound_name_instr] >>
Cases_on `mop` >> fs [] >| [
`?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw [],
`?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw [],
Cases_on `r` >> fs [] >| [
Cases_on `MEM t fs` >> fs [] >-
(`?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw []) >>
Cases_on `OoO_Ftc_list_stored_incomplete translate_val_list sem_expr (State_st_list l s cs fs) t x` >> fs [] >>
Cases_on `x'` >> fs [] >> rename1 `(ll,stl)` >> rename1 `o_store res_PC ta tv` >>
rename1 `FLOOKUP s t = SOME v` >>
`State_st_list_ok (State_st_list l s cs fs)`
by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Ftc_list_stored_incomplete_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++
[(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);
(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`],
`?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw [],
Cases_on `MEM t cs` >> fs [] >-
(`?pi''. pi' = pi ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw []) >>
rename1 `o_store res_MEM ta tv` >>
Cases_on `OoO_Cmt_list_stored_incomplete sem_expr (State_st_list l s cs fs) t ta tv` >> fs [] >>
Cases_on `x'` >> fs [] >> rename1 `(ll,stl)` >>
rename1 `FLOOKUP s t = SOME v` >>
`FLOOKUP s t <> NONE` by rw [] >>
`State_st_list_ok (State_st_list l s cs fs)`
by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Cmt_list_stored_incomplete_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution out_of_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++
[(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);
(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution out_of_order_step_list pi' /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
fs [Abbr `pi0`]
]
]
QED
Theorem IO_bounded_execution_acc_OoO_empty_sound:
!l s cs fs pos n i il pi.
State_st_list_well_formed_ok (State_st_list l s cs fs) ==>
DROP pos l = i::il ==>
~(Completed_list sem_expr (State_st_list l s cs fs) i) ==>
IO_bounded_execution_acc translate_val_list sem_expr (State_st_list l s cs fs) pos (SUC n) [] = SOME pi ==>
step_execution_list_OoO_HD (State_st_list l s cs fs) pi (SUC n)
Proof
once_rewrite_tac [IO_bounded_execution_acc] >>
fs [] >> rw [] >>
Cases_on `i` >> rename1 `i_assign t c mop` >> fs [] >>
`MEM (i_assign t c mop) l` by METIS_TAC [DROP_HEAD_MEM] >>
`FIND_instr t l = SOME (i_assign t c mop)`
by METIS_TAC [State_st_list_well_formed_ok,State_st_list_ok,NO_DUPLICATES_FIND_instr,bound_name_instr] >>
Cases_on `FLOOKUP s t` >> fs [] >> Cases_on `mop` >> fs [Completed_list] >| [
Cases_on `sem_expr c s` >> fs [] >>
rename1 `v <> val_false` >>
Cases_on `v = val_false` >> fs [] >>
Cases_on `sem_instr_exe sem_expr (i_assign t c (o_internal e)) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(v',obs)` >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr
(State_st_list l s cs fs) (i_assign t c (o_internal e)) v' obs` >>
fs [] >> rename1 `(ll,stl)` >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
sg `step_execution out_of_order_step_list [(State_st_list l s cs fs,ll,stl)]` >-
(fs [step_list_to_step] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST [(State_st_list l s cs fs,ll,stl)])) = stl` by fs [] >>
`?pi'. pi = [(State_st_list l s cs fs,ll,stl)] ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD ([(State_st_list l s cs fs,ll,stl)] ++ pi')) = State_st_list l s cs fs` by fs [] >>
`LENGTH pi <= 2 * (SUC n)` by rw [] >>
METIS_TAC [step_execution_list_OoO_HD],
Cases_on `sem_expr c s` >> fs [] >>
rename1 `v <> val_false` >>
Cases_on `v = val_false` >> fs [] >>
Cases_on `sem_instr_exe sem_expr (i_assign t c (o_load r n')) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(v',obs)` >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr (State_st_list l s cs fs) (i_assign t c (o_load r n')) v' obs` >>
fs [] >> rename1 `(ll,stl)` >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
sg `step_execution out_of_order_step_list [(State_st_list l s cs fs,ll,stl)]` >-
(fs [step_list_to_step] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST [(State_st_list l s cs fs,ll,stl)])) = stl` by fs [] >>
`?pi'. pi = [(State_st_list l s cs fs,ll,stl)] ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD ([(State_st_list l s cs fs,ll,stl)] ++ pi')) = State_st_list l s cs fs` by fs [] >>
`LENGTH pi <= 2 * (SUC n)` by rw [] >>
METIS_TAC [step_execution_list_OoO_HD],
Cases_on `sem_expr c s` >> fs [] >>
rename1 `v <> val_false` >>
Cases_on `v = val_false` >> Cases_on `r` >> fs [Completed_list] >| [
rename1 `o_store res_PC ta tv` >>
Cases_on `sem_instr_exe sem_expr (i_assign t c (o_store res_PC ta tv)) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(v',obs)` >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr (State_st_list l s cs fs) (i_assign t c (o_store res_PC ta tv)) v' obs` >> fs [] >>
rename1 `(ll,stl)` >>
Cases_on `OoO_Ftc_list_stored translate_val_list sem_expr stl t v'` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(ll',stl')` >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
`stl = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
`FLOOKUP (s |+ (t,v')) t = SOME v'` by fs [FLOOKUP_UPDATE] >>
`FLOOKUP (s |+ (t,v')) t <> NONE` by fs [] >>
`out_of_order_step_list (State_st_list l (s |+ (t,v')) cs fs) ll' stl'`
by METIS_TAC [OoO_Ftc_list_stored_SOME_out_of_order_step_list] >>
`State_st_list_ok stl'` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl'`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
Q.ABBREV_TAC `pi0 = [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')]` >>
sg `step_execution out_of_order_step_list pi0` >-
(rw [Abbr `pi0`,step_list_to_step] >>
`step_execution out_of_order_step_list ([] ++
[(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')])`
suffices_by fs [] >>
`step_execution out_of_order_step_list ([] ++
[(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)])`
suffices_by METIS_TAC [step_execution_rules] >>
fs [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl'` by fs [Abbr `pi0`] >>
`?pi'. pi = pi0 ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD (pi0 ++ pi')) = State_st_list l s cs fs` by fs [Abbr `pi0`] >>
`LENGTH pi <= 2 * (SUC n)` by rw [Abbr `pi0`] >>
METIS_TAC [step_execution_list_OoO_HD],
rename1 `o_store res_REG ta tv` >>
Cases_on `sem_instr_exe sem_expr (i_assign t c (o_store res_REG ta tv)) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> rename1 `(v',obs)` >> fs [] >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr (State_st_list l s cs fs)
(i_assign t c (o_store res_REG ta tv)) v' obs` >>
fs [] >> rename1 `(ll,stl)` >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
sg `step_execution out_of_order_step_list [(State_st_list l s cs fs,ll,stl)]` >-
(fs [step_list_to_step] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST [(State_st_list l s cs fs,ll,stl)])) = stl` by fs [] >>
`?pi'. pi = [(State_st_list l s cs fs,ll,stl)] ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD ([(State_st_list l s cs fs,ll,stl)] ++ pi')) = State_st_list l s cs fs` by fs [] >>
`LENGTH pi <= 2 * (SUC n)` by rw [] >>
METIS_TAC [step_execution_list_OoO_HD],
rename1 `o_store res_MEM ta tv` >>
Cases_on `sem_instr_exe sem_expr (i_assign t c (o_store res_MEM ta tv)) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(v',obs)` >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr (State_st_list l s cs fs) (i_assign t c (o_store res_MEM ta tv)) v' obs` >> fs [] >>
rename1 `(ll,stl)` >>
Cases_on `OoO_Cmt_list_stored sem_expr stl t ta tv` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(ll',stl')` >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
`stl = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
`FLOOKUP (s |+ (t,v')) t = SOME v'` by fs [FLOOKUP_UPDATE] >>
`FLOOKUP (s |+ (t,v')) t <> NONE` by fs [] >>
`out_of_order_step_list (State_st_list l (s |+ (t,v')) cs fs) ll' stl'`
by METIS_TAC [OoO_Cmt_list_stored_SOME_out_of_order_step_list] >>
`State_st_list_ok stl'` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl'`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
Q.ABBREV_TAC `pi0 = [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')]` >>
sg `step_execution out_of_order_step_list pi0` >-
(rw [Abbr `pi0`,step_list_to_step] >>
`step_execution out_of_order_step_list ([] ++
[(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')])`
suffices_by fs [] >>
`step_execution out_of_order_step_list ([] ++
[(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs)])`
suffices_by METIS_TAC [step_execution_rules] >>
fs [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl'` by fs [Abbr `pi0`] >>
`?pi'. pi = pi0 ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD (pi0 ++ pi')) = State_st_list l s cs fs` by fs [Abbr `pi0`] >>
`LENGTH pi <= 2 * (SUC n)` by rw [Abbr `pi0`] >>
METIS_TAC [step_execution_list_OoO_HD]
],
rename1 `o_store r ta tv` >>
rename1 `FLOOKUP s t = SOME v` >>
Cases_on `r` >> fs [Completed_list] >-
(Cases_on `MEM t fs` >> fs [] >>
Cases_on `OoO_Ftc_list_stored_incomplete translate_val_list sem_expr (State_st_list l s cs fs) t v` >> fs [] >>
Cases_on `x` >> fs [] >>
rename1 `(ll,stl)` >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Ftc_list_stored_incomplete_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
sg `step_execution out_of_order_step_list [(State_st_list l s cs fs,ll,stl)]` >-
(fs [step_list_to_step] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST [(State_st_list l s cs fs,ll,stl)])) = stl` by fs [] >>
`?pi'. pi = [(State_st_list l s cs fs,ll,stl)] ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD ([(State_st_list l s cs fs,ll,stl)] ++ pi')) = State_st_list l s cs fs` by fs [] >>
`LENGTH pi <= 2 * (SUC n)` by rw [] >>
METIS_TAC [step_execution_list_OoO_HD]) >>
Cases_on `MEM t cs` >> fs [] >>
Cases_on `OoO_Cmt_list_stored_incomplete sem_expr (State_st_list l s cs fs) t ta tv` >> fs [] >>
Cases_on `x` >> fs [] >>
rename1 `(ll,stl)` >>
`FLOOKUP s t <> NONE` by fs [] >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Cmt_list_stored_incomplete_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
sg `step_execution out_of_order_step_list [(State_st_list l s cs fs,ll,stl)]` >-
(fs [step_list_to_step] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST [(State_st_list l s cs fs,ll,stl)])) = stl` by fs [] >>
`?pi'. pi = [(State_st_list l s cs fs,ll,stl)] ++ pi' /\
step_execution out_of_order_step_list pi /\
LENGTH pi' <= 2 * n`
by METIS_TAC [IO_bounded_execution_acc_OoO_execution_sound] >>
`FST (HD ([(State_st_list l s cs fs,ll,stl)] ++ pi')) = State_st_list l s cs fs` by fs [] >>
`LENGTH pi <= 2 * (SUC n)` by rw [] >>
METIS_TAC [step_execution_list_OoO_HD]
]
QED
(* FIXME: replace by NTH version just below? *)
Theorem IO_bounded_execution_out_of_order_step_list_sound:
!l s cs fs pos n i il pi.
State_st_list_well_formed_ok (State_st_list l s cs fs) ==>
DROP (PRE pos) l = i::il ==>
~(Completed_list sem_expr (State_st_list l s cs fs) i) ==>
IO_bounded_execution translate_val_list sem_expr (State_st_list l s cs fs) pos (SUC n) = SOME pi ==>
FST (HD pi) = State_st_list l s cs fs /\
step_execution out_of_order_step_list pi /\
LENGTH pi <= 2 * n + 2
Proof
rw [IO_bounded_execution] >>
`2 * SUC n = 2 * n + 2` by DECIDE_TAC >>
METIS_TAC [IO_bounded_execution_acc_OoO_empty_sound,step_execution_list_OoO_HD]
QED
Theorem IO_bounded_execution_out_of_order_step_list_sound_NTH:
!l s cs fs pos n i pi.
State_st_list_well_formed_ok (State_st_list l s cs fs) ==>
NTH (PRE pos) l = SOME i ==>
~(Completed_list sem_expr (State_st_list l s cs fs) i) ==>
IO_bounded_execution translate_val_list sem_expr (State_st_list l s cs fs) pos (SUC n) = SOME pi ==>
FST (HD pi) = State_st_list l s cs fs /\
step_execution out_of_order_step_list pi /\
LENGTH pi <= 2 * n + 2
Proof
METIS_TAC [
NTH_SOME_DROP,
IO_bounded_execution_out_of_order_step_list_sound
]
QED
(* FIXME: replace by NTH version just below? *)
Theorem IO_bounded_execution_out_of_order_step_sound:
!l s cs fs pos n i il pi.
State_st_list_well_formed_ok (State_st_list l s cs fs) ==>
DROP (PRE pos) l = i::il ==>
~(Completed_list sem_expr (State_st_list l s cs fs) i) ==>
IO_bounded_execution translate_val_list sem_expr (State_st_list l s cs fs) pos (SUC n) = SOME pi ==>
FST (HD pi) = State_st_list l s cs fs /\
step_execution out_of_order_step (MAP step_list_to_step pi) /\
LENGTH pi <= 2 * n + 2
Proof
METIS_TAC [
step_execution_out_of_order_step_list_step,
IO_bounded_execution_out_of_order_step_list_sound
]
QED
Theorem IO_bounded_execution_out_of_order_step_sound_NTH:
!stl pos n i pi.
State_st_list_well_formed_ok stl ==>
NTH (PRE pos) (state_program_list stl) = SOME i ==>
~(Completed_list sem_expr stl i) ==>
IO_bounded_execution translate_val_list sem_expr stl pos (SUC n) = SOME pi ==>
FST (HD pi) = stl /\
step_execution out_of_order_step (MAP step_list_to_step pi) /\
LENGTH pi <= 2 * n + 2
Proof
Cases_on `stl` >>
rw [state_program_list] >>
METIS_TAC [
NTH_SOME_DROP,
IO_bounded_execution_out_of_order_step_sound
]
QED
(* ---------------------- *)
(* Execution IO soundness *)
(* ---------------------- *)
Theorem IO_bounded_execution_acc_IO_execution_sound:
translate_val_list_SORTED ==>
!n l s cs fs pos pi pi'.
State_st_list_well_formed_ok (State_st_list l s cs fs) ==>
SORTED bound_name_instr_le l ==>
Completed_list_up_to sem_expr (State_st_list l s cs fs) pos ==>
step_execution in_order_step_list pi ==>
SND (SND (LAST pi)) = State_st_list l s cs fs ==>
IO_bounded_execution_acc translate_val_list sem_expr (State_st_list l s cs fs) pos n pi = SOME pi' ==>
?pi''. pi' = pi ++ pi'' /\
step_execution in_order_step_list pi' /\
Completed_list_up_to sem_expr (SND (SND (LAST pi'))) (pos + n) /\
LENGTH pi'' <= 2 * n
Proof
once_rewrite_tac [translate_val_list_SORTED] >>
strip_tac >>
Induct_on `n` >- fs [IO_bounded_execution_acc] >>
once_rewrite_tac [IO_bounded_execution_acc] >>
fs [] >> rw [] >>
Cases_on `DROP pos l` >> fs [] >-
(rw [] >> fs [Completed_list_up_to] >> rw [] >>
`TAKE (pos + SUC n) l = TAKE pos l` suffices_by METIS_TAC [] \\
rw [LENGTH_TAKE_PLUS]) >>
Cases_on `h` >>
rename1 `i_assign t' c mop::l'` >> rename1 `i_assign t c mop` >>
fs [] >>
Cases_on `FLOOKUP s t` >> fs [] >-
(Cases_on `sem_expr c s` >> fs [] >>
rename1 `sem_expr c s = SOME v` >>
Cases_on `v = val_false` >> fs [] >-
(`Completed_list sem_expr (State_st_list l s cs fs) (i_assign t c mop)`
by (Cases_on `mop` >> rw [Completed_list] >> Cases_on `r` >> rw [Completed_list]) >>
sg `Completed_list_up_to sem_expr (State_st_list l s cs fs) (SUC pos)` >-
(rw [Completed_list_up_to] >>
`TAKE (SUC pos) l = SNOC (i_assign t c mop) (TAKE pos l)`
by rw [DROP_TAKE_SNOC] >>
fs [Completed_list_up_to]) >>
Q.PAT_X_ASSUM `!l s cs. P`
(STRIP_ASSUME_TAC o (Q.SPECL [`l`,`s`,`cs`,`fs`,`SUC pos`, `pi`,`pi'`])) >>
`?pi''. pi' = pi ++ pi'' /\
step_execution in_order_step_list pi' /\
Completed_list_up_to sem_expr (SND (SND (LAST pi'))) (n + (SUC pos)) /\
LENGTH pi'' ≤ 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `pi''` >> rw [] >>
`pos + SUC n = n + SUC pos` by rw [] >>
rw []) >>
Cases_on `sem_instr_exe sem_expr (i_assign t c mop) (State_st_list l s cs fs)` >> fs [] >>
Cases_on `x` >> rename1 `(v',obs)` >> fs [] >>
Cases_on `OoO_Exe_list_instr_not_stored_guard_true_sem_instr
(State_st_list l s cs fs) (i_assign t c mop) v' obs` >>
fs [] >> rename1 `(ll,stl)` >>
`MEM (i_assign t c mop) l` by METIS_TAC [DROP_HEAD_MEM] >>
`FIND_instr t l = SOME (i_assign t c mop)`
by METIS_TAC [State_st_list_well_formed_ok,State_st_list_ok,NO_DUPLICATES_FIND_instr,bound_name_instr] >>
`State_st_list_ok (State_st_list l s cs fs)` by fs [State_st_list_ok,State_st_list_well_formed_ok] >>
`out_of_order_step_list (State_st_list l s cs fs) ll stl`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_SOME_out_of_order_step_list] >>
`State_st_list_ok stl` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
sg `in_order_step_list (State_st_list l s cs fs) ll stl` >-
(`ll = ll_lb obs act_exe_list t /\ stl = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [in_order_step_list,IO_step_list] >>
fs [out_of_order_step_list] >>
rw [EVERY_MEM] >>
fs [MEM_FILTER] >>
`bound_name_instr i < t` by DECIDE_TAC >>
`MEM i (TAKE pos l)` suffices_by fs [Completed_list_up_to] >>
`MEM i (TAKE pos l) \/ MEM i (DROP pos l)`
by METIS_TAC [TAKE_DROP,MEM_APPEND] >>
`i <> i_assign t c mop` by (Cases_on `i` >> fs [bound_name_instr]) >>
`MEM i (i_assign t c mop::l')` by METIS_TAC [] >>
fs [] >> rw [] >>
sg `SORTED bound_name_instr_le ((TAKE pos l ++ [i_assign t c mop]) ++ l')` >-
(`(TAKE pos l ++ [i_assign t c mop]) ++ l' = l` suffices_by rw [] >>
`l = TAKE pos l ++ (i_assign t c mop::l')` by METIS_TAC [TAKE_DROP] >>
once_rewrite_tac [GSYM APPEND_ASSOC] >>
`[i_assign t c mop] ++ l' = i_assign t c mop::l'` by rw [] >>
METIS_TAC []) >>
`!x y. MEM x (TAKE pos l ++ [i_assign t c mop]) ==> MEM y l' ==> bound_name_instr_le x y`
by METIS_TAC [SORTED_APPEND,transitive_bound_name_instr_le] >>
`MEM (i_assign t c mop) (TAKE pos l ++ [i_assign t c mop])` by rw [] >>
`bound_name_instr_le (i_assign t c mop) i` by METIS_TAC [] >>
fs [bound_name_instr_le,name_le,bound_name_instr]) >>
Cases_on `mop` >> fs [] >| [
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution in_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e'` >> fs [] >> Cases_on `r` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++ [(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
Cases_on `stl` >>
rename1 `(ll,State_st_list l'' s'' cs'' fs'')` >>
`SORTED bound_name_instr_le l''` by fs [OoO_Exe_list_instr_not_stored_guard_true_sem_instr] >>
sg `Completed_list sem_expr (State_st_list l'' s'' cs'' fs'') (i_assign t c (o_internal e))` >-
(fs [Completed_list,OoO_Exe_list_instr_not_stored_guard_true_sem_instr] >>
rw [FLOOKUP_DEF]) >>
sg `Completed_list_up_to sem_expr (State_st_list l'' s'' cs'' fs'') (SUC pos)` >-
(rw [Completed_list_up_to] >>
`ll = ll_lb obs act_exe_list t /\
State_st_list l'' s'' cs'' fs'' = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
`TAKE (SUC pos) l = SNOC (i_assign t c (o_internal e)) (TAKE pos l)` by rw [DROP_TAKE_SNOC] >>
fs [] >>
`Completed_list sem_expr (State_st_list l s cs fs) i`
by fs [Completed_list_up_to] >>
`MEM i l` by METIS_TAC [MEM_TAKE] >>
(* TODO: adapt well_formed_state_OoO_completed_t_preserved for lists *)
`Completed (state_list_to_state (State_st_list l s cs fs)) i`
by METIS_TAC [Completed_list_correct] >>
`Completed (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) i`
suffices_by METIS_TAC [Completed_list_correct] >>
`Completed_t (state_list_to_state (State_st_list l s cs fs)) (bound_name_instr i)`
by (fs [state_list_to_state] >> rw [Completed_t] >> METIS_TAC []) >>
`Completed_t (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) (bound_name_instr i)`
by METIS_TAC [state_list_to_state,
out_of_order_step_list_sound,
well_formed_state_OoO_completed_t_preserved,
State_st_list_well_formed_ok] >>
fs [state_list_to_state,Completed_t,State_st_list_well_formed_ok] >>
METIS_TAC [wfs_unique_instr_names]) >>
Q.PAT_X_ASSUM `!l s cs. P`
(STRIP_ASSUME_TAC o (Q.SPECL [`l''`,`s''`,`cs''`,`fs''`,`SUC pos`, `pi0`,`pi'`])) >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution in_order_step_list pi' /\
Completed_list_up_to sem_expr (SND (SND (LAST pi'))) (n + SUC pos) /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `(State_st_list l s cs fs,ll,State_st_list l'' s'' cs'' fs'')::pi''` >>
`pos + SUC n = n + SUC pos` by DECIDE_TAC >>
rw [Abbr `pi0`],
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,stl)]` >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `step_execution in_order_step_list pi0` >-
(fs [Abbr `pi0`,step_list_to_step] >>
`pi <> []` by METIS_TAC [step_execution_not_empty_list] >>
`pi = [] \/ ?e pi1. pi = SNOC e pi1` by fs [SNOC_CASES] >> fs [SNOC_APPEND] >>
Cases_on `e` >> fs [] >> Cases_on `r'` >> rename1 `(stl1,ll1,stl2)` >>
fs [step_list_to_step] >> rw [] >>
`pi1 ++ [(stl1,ll1,State_st_list l s cs fs)] ++ [(State_st_list l s cs fs,ll,stl)] =
pi1 ++ [(stl1,ll1,State_st_list l s cs fs);(State_st_list l s cs fs,ll,stl)]`
by fs [] >>
rw [] >> METIS_TAC [step_execution_rules]) >>
`SND (SND (LAST pi0)) = stl` by fs [Abbr `pi0`] >>
Cases_on `stl` >>
rename1 `(ll,State_st_list l'' s'' cs'' fs'')` >>
`SORTED bound_name_instr_le l''` by fs [OoO_Exe_list_instr_not_stored_guard_true_sem_instr] >>
sg `Completed_list sem_expr (State_st_list l'' s'' cs'' fs'') (i_assign t c (o_load r n'))` >-
(fs [Completed_list,OoO_Exe_list_instr_not_stored_guard_true_sem_instr] >>
rw [FLOOKUP_DEF]) >>
sg `Completed_list_up_to sem_expr (State_st_list l'' s'' cs'' fs'') (SUC pos)` >-
(rw [Completed_list_up_to] >>
`ll = ll_lb obs act_exe_list t /\
State_st_list l'' s'' cs'' fs'' = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
`TAKE (SUC pos) l = SNOC (i_assign t c (o_load r n')) (TAKE pos l)` by rw [DROP_TAKE_SNOC] >>
fs [] >>
`Completed_list sem_expr (State_st_list l s cs fs) i`
by fs [Completed_list_up_to] >>
`MEM i l` by METIS_TAC [MEM_TAKE] >>
(* TODO: adapt well_formed_state_OoO_completed_t_preserved for lists *)
`Completed (state_list_to_state (State_st_list l s cs fs)) i`
by METIS_TAC [Completed_list_correct] >>
`Completed (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) i`
suffices_by METIS_TAC [Completed_list_correct] >>
`Completed_t (state_list_to_state (State_st_list l s cs fs)) (bound_name_instr i)`
by (fs [state_list_to_state] >> rw [Completed_t] >> METIS_TAC []) >>
`Completed_t (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) (bound_name_instr i)`
by METIS_TAC [state_list_to_state,
out_of_order_step_list_sound,
well_formed_state_OoO_completed_t_preserved,
State_st_list_well_formed_ok] >>
fs [state_list_to_state,Completed_t,State_st_list_well_formed_ok] >>
METIS_TAC [wfs_unique_instr_names]) >>
Q.PAT_X_ASSUM `!l s cs. P`
(STRIP_ASSUME_TAC o (Q.SPECL [`l''`,`s''`,`cs''`,`fs''`,`SUC pos`, `pi0`,`pi'`])) >>
`?pi''. pi' = pi0 ++ pi'' /\
step_execution in_order_step_list pi' /\
Completed_list_up_to sem_expr (SND (SND (LAST pi'))) (n + SUC pos) /\
LENGTH pi'' <= 2 * n` by METIS_TAC [] >>
Q.EXISTS_TAC `(State_st_list l s cs fs,ll,State_st_list l'' s'' cs'' fs'')::pi''` >>
`pos + SUC n = n + SUC pos` by DECIDE_TAC >>
rw [Abbr `pi0`],
Cases_on `r` >> fs [] >| [
Cases_on `OoO_Ftc_list_stored translate_val_list sem_expr stl t v'` >> fs [] >>
Cases_on `x` >> fs [] >> rename1 `(ll',stl')` >>
rename1 `o_store res_PC ta tv` >>
`stl = State_st_list l (s |+ (t,v')) cs fs`
by METIS_TAC [OoO_Exe_list_instr_not_stored_guard_true_sem_instr_result_form] >>
rw [] >>
Q.ABBREV_TAC `pi0 = pi ++ [(State_st_list l s cs fs,ll,State_st_list l (s |+ (t,v')) cs fs);
(State_st_list l (s |+ (t,v')) cs fs,ll',stl')]` >>
`FLOOKUP (s |+ (t,v')) t = SOME v'` by fs [FLOOKUP_UPDATE] >>
`out_of_order_step_list (State_st_list l (s |+ (t,v')) cs fs) ll' stl'`
by METIS_TAC [OoO_Ftc_list_stored_SOME_out_of_order_step_list] >>
`State_st_list_ok stl'` by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_ok] >>
`State_st_list_well_formed_ok stl'`
by METIS_TAC [step_invariant,step_invariant_out_of_order_step_list_well_formed_ok] >>
`State_st_list_well_formed_ok (SND (SND (LAST pi0)))` by fs [Abbr `pi0`] >>
sg `Completed_list_up_to sem_expr (State_st_list l (s |+ (t,v')) cs fs) pos` >-
(rw [Completed_list_up_to] >>
`MEM i l` by METIS_TAC [MEM_TAKE] >>
`Completed_list sem_expr (State_st_list l s cs fs) i`
by fs [Completed_list_up_to] >>
`Completed (state_list_to_state (State_st_list l s cs fs)) i`
by METIS_TAC [Completed_list_correct] >>
`Completed (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) i`
suffices_by METIS_TAC [Completed_list_correct] >>
`Completed_t (state_list_to_state (State_st_list l s cs fs)) (bound_name_instr i)`
by (fs [state_list_to_state] >> rw [Completed_t] >> METIS_TAC []) >>
`Completed_t (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) (bound_name_instr i)`
by METIS_TAC [state_list_to_state,
out_of_order_step_list_sound,
well_formed_state_OoO_completed_t_preserved,
State_st_list_well_formed_ok] >>
fs [state_list_to_state,Completed_t,State_st_list_well_formed_ok] >>
METIS_TAC [wfs_unique_instr_names]) >>
sg `in_order_step_list (State_st_list l (s |+ (t,v')) cs fs) ll' stl'` >-
(`ll' = ll_lb (obs_il v') (act_ftc_list (translate_val_list v' (max_bound_name_list l))) t /\
stl' = State_st_list (l ++ translate_val_list v' (max_bound_name_list l)) (s |+ (t,v')) cs (t::fs)`
by METIS_TAC [OoO_Ftc_list_stored_result_form] >>
rw [in_order_step_list,IO_step_list] >>
fs [out_of_order_step_list] >>
rw [EVERY_MEM] >>
fs [MEM_FILTER] >>
`bound_name_instr i < t` by DECIDE_TAC >>
`MEM i (TAKE pos l)` suffices_by fs [Completed_list_up_to] >>
`MEM i (TAKE pos l) \/ MEM i (DROP pos l)`
by METIS_TAC [TAKE_DROP,MEM_APPEND] >>
`i <> i_assign t c (o_store res_PC ta tv)` by (Cases_on `i` >> fs [bound_name_instr]) >>
`MEM i (i_assign t c (o_store res_PC ta tv)::l')` by METIS_TAC [] >>
fs [] >> rw [] >>
sg `SORTED bound_name_instr_le ((TAKE pos l ++ [i_assign t c (o_store res_PC ta tv)]) ++ l')` >-
(`(TAKE pos l ++ [i_assign t c (o_store res_PC ta tv)]) ++ l' = l` suffices_by rw [] >>
`l = TAKE pos l ++ (i_assign t c (o_store res_PC ta tv)::l')` by METIS_TAC [TAKE_DROP] >>
once_rewrite_tac [GSYM APPEND_ASSOC] >>
`[i_assign t c (o_store res_PC ta tv)] ++ l' = i_assign t c (o_store res_PC ta tv)::l'` by rw [] >>
METIS_TAC []) >>
`!x y. MEM x (TAKE pos l ++ [i_assign t c (o_store res_PC ta tv)]) ==> MEM y l' ==> bound_name_instr_le x y`
by METIS_TAC [SORTED_APPEND,transitive_bound_name_instr_le] >>
`MEM (i_assign t c (o_store res_PC ta tv)) (TAKE pos l ++ [i_assign t c (o_store res_PC ta tv)])` by rw [] >>
`bound_name_instr_le (i_assign t c (o_store res_PC ta tv)) i` by METIS_TAC [] >>
fs [bound_name_instr_le,name_le,bound_name_instr]) >>
sg `SORTED bound_name_instr_le (l ++ translate_val_list v' (max_bound_name_list l))` >-
(`!x y. MEM x l ==> MEM y (translate_val_list v' (max_bound_name_list l)) ==> bound_name_instr_le x y`
suffices_by METIS_TAC [SORTED_APPEND,transitive_bound_name_instr_le] >>
rw [bound_name_instr_le,name_le] >>
`bound_name_instr x < bound_name_instr y` suffices_by rw [] >>
`y IN (translate_val v' (MAX_SET (bound_names_program (set l))))`
by METIS_TAC [translate_val_list_correct,max_bound_name_list_correct] >>
`FINITE (set l)` by rw [] >>
METIS_TAC [translate_val_max_name_lt]) >>
`Completed_list sem_expr (State_st_list (l ++ translate_val_list v' (max_bound_name_list l))
(s |+ (t,v')) cs (t::fs)) (i_assign t c (o_store res_PC ta tv))` by rw [Completed_list] >>
sg `Completed_list_up_to sem_expr stl' (SUC pos)` >-
(`stl' = State_st_list (l ++ translate_val_list v' (max_bound_name_list l)) (s |+ (t,v')) cs (t::fs)`
by METIS_TAC [OoO_Ftc_list_stored_result_form] >>
rw [Completed_list_up_to] >>
`DROP pos (l ++ translate_val_list v' (max_bound_name_list l)) =
i_assign t c (o_store res_PC ta tv)::l' ++ translate_val_list v' (max_bound_name_list l)`
by rw [DROP_CONS_APPEND] >>
`TAKE (SUC pos) (l ++ translate_val_list v' (max_bound_name_list l)) =
SNOC (i_assign t c (o_store res_PC ta tv)) (TAKE pos (l ++ translate_val_list v' (max_bound_name_list l)))`
by rw [DROP_TAKE_SNOC] >>
fs [] >>
`MEM i (TAKE pos l)` by METIS_TAC [DROP_CONS_TAKE_APPEND] >>
`MEM i l` by METIS_TAC [MEM_TAKE] >>
`Completed_list sem_expr (State_st_list l (s |+ (t,v')) cs fs) i`
by fs [Completed_list_up_to] >>
`Completed (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) i`
by fs [Completed_list_correct] >>
`Completed_t (state_list_to_state (State_st_list l (s |+ (t,v')) cs fs)) (bound_name_instr i)`
by (fs [state_list_to_state] >> rw [Completed_t] >> METIS_TAC []) >>
`Completed_t (state_list_to_state (State_st_list (l ++ translate_val_list v' (max_bound_name_list l))
(s |+ (t,v')) cs (t::fs))) (bound_name_instr i)`
by METIS_TAC [state_list_to_state,
out_of_order_step_list_sound,
well_formed_state_OoO_completed_t_preserved,
State_st_list_well_formed_ok] >>
`Completed (state_list_to_state (State_st_list (l ++ translate_val_list v' (max_bound_name_list l))
(s |+ (t,v')) cs (t::fs))) i` suffices_by METIS_TAC [Completed_list_correct] >>