forked from CakeML/cakeml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordPropsScript.sml
5062 lines (4790 loc) · 199 KB
/
wordPropsScript.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
(*
Properties about wordLang and its semantics
*)
open preamble BasicProvers
wordLangTheory wordSemTheory
asmTheory reg_allocTheory backendPropsTheory;
(*
Main lemmas:
0) Clock lemmas (add_clock, dec_clock, IO monotonicity)
1) Code table constancy across eval
2) Swapping stack for one with identical values (but different keys)
3) Thms to handle the permutation oracle
4) mono and conj for every_var etc.
5) Effect of extra locals (locals_rel)
6) Other misc things and defs followed by syntactic things
*)
val _ = temp_delsimps ["NORMEQ_CONV"]
val _ = new_theory "wordProps";
(* TODO: move *)
Theorem mem_list_rearrange:
∀ls x f. MEM x (list_rearrange f ls) ⇔ MEM x ls
Proof
full_simp_tac(srw_ss())[MEM_EL]>>srw_tac[][wordSemTheory.list_rearrange_def]>>
imp_res_tac BIJ_IFF_INV>>
full_simp_tac(srw_ss())[BIJ_DEF,INJ_DEF,SURJ_DEF]>>
srw_tac[][EQ_IMP_THM]>>full_simp_tac(srw_ss())[EL_GENLIST]
>- metis_tac[]>>
qexists_tac `g n`>>full_simp_tac(srw_ss())[]
QED
val GENLIST_I =
GENLIST_EL |> Q.SPECL [`xs`,`\i. EL i xs`,`LENGTH xs`]
|> SIMP_RULE std_ss []
val ALL_DISTINCT_EL = ``ALL_DISTINCT xs``
|> ONCE_REWRITE_CONV [GSYM GENLIST_I]
|> SIMP_RULE std_ss [ALL_DISTINCT_GENLIST]
Theorem PERM_list_rearrange:
!f xs. ALL_DISTINCT xs ==> PERM xs (list_rearrange f xs)
Proof
srw_tac[][] \\ match_mp_tac PERM_ALL_DISTINCT
\\ full_simp_tac(srw_ss())[mem_list_rearrange]
\\ full_simp_tac(srw_ss())[wordSemTheory.list_rearrange_def] \\ srw_tac[][]
\\ full_simp_tac(srw_ss())[ALL_DISTINCT_GENLIST] \\ srw_tac[][]
\\ full_simp_tac(srw_ss())[BIJ_DEF,INJ_DEF,SURJ_DEF]
\\ full_simp_tac(srw_ss())[ALL_DISTINCT_EL]
QED
Theorem PERM_ALL_DISTINCT_MAP:
!xs ys. PERM xs ys ==>
ALL_DISTINCT (MAP f xs) ==>
ALL_DISTINCT (MAP f ys) /\ !x. MEM x ys <=> MEM x xs
Proof
full_simp_tac(srw_ss())[MEM_PERM] \\ srw_tac[][]
\\ `PERM (MAP f xs) (MAP f ys)` by full_simp_tac(srw_ss())[PERM_MAP]
\\ metis_tac [ALL_DISTINCT_PERM]
QED
Theorem ALL_DISTINCT_MEM_IMP_ALOOKUP_SOME:
ALL_DISTINCT (MAP FST xs) /\ MEM (x,y) xs ==> ALOOKUP xs x = SOME y
Proof
map_every qid_spec_tac [‘x’, ‘y’] >> Induct_on ‘xs’ >>
full_simp_tac(srw_ss())[]
\\ Cases \\ full_simp_tac(srw_ss())[ALOOKUP_def] \\ srw_tac[][]
\\ res_tac \\ full_simp_tac(srw_ss())[MEM_MAP,FORALL_PROD]
\\ rev_full_simp_tac(srw_ss())[]
QED
(* -- *)
(* Clock lemmas *)
(*TODO: define globally somewhere? *)
fun get_thms ty = { case_def = TypeBase.case_def_of ty, nchotomy = TypeBase.nchotomy_of ty }
val case_eq_thms = pair_case_eq::bool_case_eq::map (prove_case_eq_thm o get_thms)
[``:'a option``,``:'a list``,``:'a word_loc``,``:'a inst``
,``:'a arith``,``:'a addr``,``:memop``,``:'a wordSem$result``,``:'a ffi_result``] |> LIST_CONJ |> curry save_thm "case_eq_thms"
Theorem set_store_const[simp]:
(set_store x y z).clock = z.clock ∧
(set_store x y z).ffi = z.ffi ∧
(set_store x y z).compile = z.compile ∧
(set_store x y z).compile_oracle = z.compile_oracle ∧
(set_store x y z).be = z.be ∧
(set_store x y z).data_buffer = z.data_buffer ∧
(set_store x y z).code_buffer = z.code_buffer ∧
(set_store x y z).code = z.code ∧
(set_store x y z).locals_size = z.locals_size ∧
(set_store x y z).stack_limit = z.stack_limit ∧
(set_store x y z).stack_max = z.stack_max ∧
(set_store x y z).stack_size = z.stack_size
Proof
EVAL_TAC
QED
Theorem set_store_with_const[simp]:
(set_store x y (z with clock := k)) = set_store x y z with clock := k
Proof
EVAL_TAC
QED
Theorem stack_size_eq:
(stack_size(StackFrame n l NONE::stack) = OPTION_MAP2 $+ n (stack_size stack)) /\
(stack_size(StackFrame n l (SOME handler)::stack) =
OPTION_MAP2 $+ (OPTION_MAP ($+ 3) n) (stack_size stack)) /\
(stack_size [] = SOME 1)
Proof
rw[stack_size_def,stack_size_frame_def]
QED
Theorem stack_size_eq2:
(stack_size(sfrm::stack) =
OPTION_MAP2 $+ (stack_size_frame sfrm) (stack_size stack)) /\
(stack_size [] = SOME 1)
Proof
rw[stack_size_def,stack_size_frame_def]
QED
Theorem push_env_const[simp]:
(push_env x y z).clock = z.clock ∧
(push_env x y z).ffi = z.ffi ∧
(push_env x y z).termdep = z.termdep ∧
(push_env x y z).data_buffer = z.data_buffer ∧
(push_env x y z).code_buffer = z.code_buffer ∧
(push_env x y z).compile = z.compile ∧
(push_env x y z).compile_oracle = z.compile_oracle ∧
(push_env x y z).gc_fun = z.gc_fun ∧
(push_env x y z).be = z.be ∧
(push_env x y z).code = z.code ∧
(push_env x y z).stack_limit = z.stack_limit ∧
(push_env x y z).stack_size = z.stack_size
Proof
Cases_on`y`>>simp[push_env_def,UNCURRY] >>
rename1`SOME p` >>
PairCases_on`p` >>
srw_tac[][push_env_def] >> srw_tac[][]
QED
Theorem push_env_with_const[simp]:
(push_env x y (z with clock := k) = push_env x y z with clock := k) ∧
(push_env x y (z with locals := l) = push_env x y z with locals := l)
Proof
Cases_on`y`>>srw_tac[][push_env_def] >> unabbrev_all_tac >> simp[state_component_equality] >>
rename1`SOME p` >>
PairCases_on`p` >>
srw_tac[][push_env_def] >> unabbrev_all_tac >> simp[state_component_equality]
QED
Theorem pop_env_const:
pop_env x = SOME y ⇒
y.clock = x.clock /\
y.ffi = x.ffi ∧
y.be = x.be ∧
y.compile = x.compile ∧
y.compile_oracle = x.compile_oracle ∧
y.data_buffer = x.data_buffer ∧
y.code_buffer = x.code_buffer ∧
y.code = x.code ∧
y.stack_limit = x.stack_limit ∧
y.stack_max = x.stack_max ∧
y.stack_size = x.stack_size
Proof
srw_tac[][pop_env_def] >>
every_case_tac >> full_simp_tac(srw_ss())[] >> srw_tac[][]
QED
Theorem pop_env_with_const[simp]:
pop_env (z with clock := k) = OPTION_MAP (λs. s with clock := k) (pop_env z) ∧
pop_env (z with locals := l) = pop_env z
Proof
srw_tac[][pop_env_def] >> every_case_tac >> full_simp_tac(srw_ss())[]
QED
Theorem call_env_const[simp]:
(call_env x ss y).clock = y.clock ∧
(call_env x ss y).compile_oracle = y.compile_oracle ∧
(call_env x ss y).compile = y.compile ∧
(call_env x ss y).be = y.be ∧
(call_env x ss y).gc_fun = y.gc_fun ∧
(call_env x ss y).ffi = y.ffi ∧
(call_env x ss y).code = y.code ∧
(call_env x ss y).code_buffer = y.code_buffer ∧
(call_env x ss y).data_buffer = y.data_buffer ∧
(call_env x ss y).stack_limit = y.stack_limit ∧
(call_env x ss y).stack_size = y.stack_size
Proof
EVAL_TAC
QED
Theorem call_env_with_const[simp]:
call_env x ss (y with clock := k) = call_env x ss y with clock := k
Proof
EVAL_TAC
QED
Theorem flush_state_const[simp]:
(flush_state b y).clock = y.clock ∧
(flush_state b y).compile_oracle = y.compile_oracle ∧
(flush_state b y).compile = y.compile ∧
(flush_state b y).be = y.be ∧
(flush_state b y).gc_fun = y.gc_fun ∧
(flush_state b y).ffi = y.ffi ∧
(flush_state b y).code = y.code ∧
(flush_state b y).code_buffer = y.code_buffer ∧
(flush_state b y).data_buffer = y.data_buffer ∧
(flush_state b y).stack_limit = y.stack_limit ∧
(flush_state b y).stack_size = y.stack_size ∧
(flush_state F y).stack = y.stack
Proof
Cases_on `b` \\ EVAL_TAC
QED
Theorem flush_state_with_const[simp]:
flush_state b (y with clock := k) = flush_state b y with clock := k
Proof
Cases_on `b` \\ EVAL_TAC
QED
Theorem has_space_with_const[simp]:
has_space x (y with clock := k) = has_space x y
Proof
EVAL_TAC
QED
Theorem gc_const:
gc x = SOME y ⇒
y.clock = x.clock ∧
y.ffi = x.ffi ∧
y.code = x.code ∧
y.be = x.be ∧
y.code_buffer = x.code_buffer ∧
y.data_buffer = x.data_buffer ∧
y.compile = x.compile ∧
y.compile_oracle = x.compile_oracle ∧
y.locals_size = x.locals_size ∧
y.stack_limit = x.stack_limit ∧
y.stack_max = x.stack_max ∧
y.stack_size = x.stack_size
Proof
simp[gc_def] >>
every_case_tac >> full_simp_tac(srw_ss())[] >> srw_tac[][] >> srw_tac[][]
QED
Theorem gc_with_const[simp]:
gc (x with clock := k) = OPTION_MAP (λs. s with clock := k) (gc x) ∧
gc (x with locals := l) = OPTION_MAP (λs. s with locals := l) (gc x)
Proof
EVAL_TAC >>
CASE_TAC >> EVAL_TAC >>
CASE_TAC >> EVAL_TAC >>
CASE_TAC >> EVAL_TAC >>
CASE_TAC >> EVAL_TAC
QED
Theorem alloc_const:
alloc c names s = (r,s') ⇒
s'.clock = s.clock ∧
s'.ffi = s.ffi ∧
s'.code = s.code ∧
s'.be = s.be ∧
s'.code_buffer = s.code_buffer ∧
s'.data_buffer = s.data_buffer ∧
s'.compile = s.compile ∧
s'.compile_oracle = s.compile_oracle ∧
s'.stack_limit = s.stack_limit ∧
s'.stack_size = s.stack_size
Proof
srw_tac[][alloc_def] >>
every_case_tac >> full_simp_tac(srw_ss())[] >> srw_tac[][] >>
imp_res_tac pop_env_const >> full_simp_tac(srw_ss())[] >>
imp_res_tac gc_const >> full_simp_tac(srw_ss())[]
QED
Theorem alloc_with_const[simp]:
alloc c names (s with clock := k) =
(λ(r,s). (r,s with clock := k)) (alloc c names s)
Proof
srw_tac[][alloc_def] >>
CASE_TAC >> full_simp_tac(srw_ss())[] >>
CASE_TAC >> full_simp_tac(srw_ss())[] >> srw_tac[][] >>
CASE_TAC >> full_simp_tac(srw_ss())[] >>
CASE_TAC >> full_simp_tac(srw_ss())[] >>
CASE_TAC >> full_simp_tac(srw_ss())[] >>
CASE_TAC >> full_simp_tac(srw_ss())[]
QED
Theorem get_var_with_const[simp]:
get_var x (y with clock := k) = get_var x y /\
get_var x (y with permute := p) = get_var x y /\
get_var x (y with code_buffer := cb) = get_var x y /\
get_var x (y with data_buffer := db) = get_var x y /\
get_var x (y with code := cc) = get_var x y /\
get_var x (y with compile_oracle := co) = get_var x y /\
get_var x (y with compile := ccc) = get_var x y /\
get_var x (y with stack := xs) = get_var x y /\
get_var x (y with locals_size := ss) = get_var x y /\
get_var x (y with stack_limit := n) = get_var x y /\
get_var x (y with stack_max := ss) = get_var x y /\
get_var x (y with stack_size := ssize) = get_var x y
Proof
EVAL_TAC
QED
Theorem get_vars_with_const[simp]:
get_vars x (y with clock := k) = get_vars x y /\
get_vars x (y with permute := p) = get_vars x y /\
get_vars x (y with code_buffer := cb) = get_vars x y /\
get_vars x (y with data_buffer := db) = get_vars x y /\
get_vars x (y with code := cc) = get_vars x y /\
get_vars x (y with compile_oracle := co) = get_vars x y /\
get_vars x (y with compile := ccc) = get_vars x y /\
get_vars x (y with stack := xs) = get_vars x y /\
get_vars x (y with locals_size := ss) = get_vars x y /\
get_vars x (y with stack_limit := n) = get_vars x y /\
get_vars x (y with stack_max := ss) = get_vars x y /\
get_vars x (y with stack_size := ssize) = get_vars x y
Proof
Induct_on`x`>>srw_tac[][get_vars_def]
QED
Theorem get_fp_var_with_const[simp]:
get_fp_var x (y with clock := k) = get_fp_var x y
Proof
EVAL_TAC
QED
Theorem set_var_const[simp]:
(set_var x y z).clock = z.clock ∧
(set_var x y z).be = z.be ∧
(set_var x y z).ffi = z.ffi ∧
(set_var x y z).compile = z.compile ∧
(set_var x y z).compile_oracle = z.compile_oracle ∧
(set_var x y z).code_buffer = z.code_buffer ∧
(set_var x y z).data_buffer = z.data_buffer ∧
(set_var x y z).stack = z.stack ∧
(set_var x y z).locals_size = z.locals_size ∧
(set_var x y z).stack_limit = z.stack_limit ∧
(set_var x y z).stack_max = z.stack_max ∧
(set_var x y z).stack_size = z.stack_size
Proof
EVAL_TAC
QED
Theorem unset_var_const[simp]:
(unset_var x z).clock = z.clock ∧
(unset_var x z).be = z.be ∧
(unset_var x z).ffi = z.ffi ∧
(unset_var x z).compile = z.compile ∧
(unset_var x z).compile_oracle = z.compile_oracle ∧
(unset_var x z).code_buffer = z.code_buffer ∧
(unset_var x z).data_buffer = z.data_buffer ∧
(unset_var x z).stack = z.stack ∧
(unset_var x z).locals_size = z.locals_size ∧
(unset_var x z).stack_limit = z.stack_limit ∧
(unset_var x z).stack_max = z.stack_max ∧
(unset_var x z).stack_size = z.stack_size
Proof
EVAL_TAC
QED
Theorem set_fp_var_const[simp]:
(set_fp_var x y z).clock = z.clock ∧
(set_fp_var x y z).ffi = z.ffi ∧
(set_fp_var x y z).stack = z.stack ∧
(set_fp_var x y z).locals_size = z.locals_size ∧
(set_fp_var x y z).stack_limit = z.stack_limit ∧
(set_fp_var x y z).stack_max = z.stack_max ∧
(set_fp_var x y z).stack_size = z.stack_size
Proof
EVAL_TAC
QED
Theorem set_var_with_const[simp]:
set_var x y (z with clock := k) = set_var x y z with clock := k /\
set_var x y (z with permute := p) = set_var x y z with permute := p
Proof
EVAL_TAC
QED
Theorem set_fp_var_with_const[simp]:
set_fp_var x y (z with clock := k) = set_fp_var x y z with clock := k
Proof
EVAL_TAC
QED
Theorem set_vars_const[simp]:
(set_vars x y z).clock = z.clock ∧
(set_vars x y z).compile_oracle = z.compile_oracle ∧
(set_vars x y z).code = z.code ∧
(set_vars x y z).code_buffer = z.code_buffer ∧
(set_vars x y z).data_buffer = z.data_buffer ∧
(set_vars x y z).compile = z.compile ∧
(set_vars x y z).be = z.be ∧
(set_vars x y z).ffi = z.ffi ∧
(set_vars x y z).locals_size = z.locals_size ∧
(set_vars x y z).stack_limit = z.stack_limit ∧
(set_vars x y z).stack_max = z.stack_max ∧
(set_vars x y z).stack_size = z.stack_size
Proof
EVAL_TAC
QED
Theorem set_vars_with_const[simp]:
set_vars x y (z with clock := k) = set_vars x y z with clock := k /\
set_vars x y (z with permute := p) = set_vars x y z with permute := p
Proof
EVAL_TAC
QED
Theorem mem_load_with_const[simp]:
mem_load x (y with clock := k) = mem_load x y ∧
mem_load x (y with code := c) = mem_load x y ∧
mem_load x (y with compile_oracle := co) = mem_load x y ∧
mem_load x (y with compile := cc) = mem_load x y
Proof
EVAL_TAC
QED
Theorem mem_store_const_full:
mem_store x y z = SOME a ⇒
a.clock = z.clock ∧
a.be = z.be ∧
a.ffi = z.ffi ∧
a.handler = z.handler ∧
a.code = z.code ∧
a.code_buffer = z.code_buffer ∧
a.data_buffer = z.data_buffer ∧
a.compile = z.compile ∧
a.compile_oracle = z.compile_oracle ∧
a.stack = z.stack ∧
a.locals_size = z.locals_size ∧
a.stack_limit = z.stack_limit ∧
a.stack_max = z.stack_max ∧
a.stack_size = z.stack_size
Proof
EVAL_TAC >> srw_tac[][] >> srw_tac[][]
QED
Theorem mem_store_const:
mem_store x y z = SOME a ⇒
a.clock = z.clock ∧
a.ffi = z.ffi
Proof
metis_tac [mem_store_const_full]
QED
Theorem mem_store_with_const[simp]:
mem_store x z (y with clock := k) = OPTION_MAP (λs. s with clock := k) (mem_store x z y)
Proof
EVAL_TAC >> every_case_tac >> simp[]
QED
Theorem word_exp_with_const[simp]:
∀x y k c co cc.
word_exp (x with clock := k) y = word_exp x y ∧
word_exp (x with code := c) y = word_exp x y ∧
word_exp (x with compile_oracle := co) y = word_exp x y ∧
word_exp (x with compile := cc) y = word_exp x y
Proof
recInduct word_exp_ind >>
rw[word_exp_def] >>
every_case_tac >> fs[]>>
ntac 2 (pop_assum mp_tac)>>
qpat_abbrev_tac`ls = MAP A B`>>
qpat_abbrev_tac`ls' = MAP A B`>>
`ls = ls'` by
(unabbrev_all_tac>>fs[MAP_EQ_f]) >>
rw[]
QED
Theorem assign_const_full:
assign x y z = SOME a ⇒
a.code = z.code ∧
a.code_buffer = z.code_buffer ∧
a.data_buffer = z.data_buffer ∧
a.compile = z.compile ∧
a.compile_oracle = z.compile_oracle ∧
a.clock = z.clock ∧
a.ffi = z.ffi ∧
a.handler = z.handler ∧
a.stack = z.stack ∧
a.locals_size = z.locals_size ∧
a.stack_limit = z.stack_limit ∧
a.stack_max = z.stack_max ∧
a.stack_size = z.stack_size
Proof
EVAL_TAC >> every_case_tac >> full_simp_tac(srw_ss())[] >> srw_tac[][] >> srw_tac[][]
QED
Theorem assign_const:
assign x y z = SOME a ⇒
a.clock = z.clock ∧
a.ffi = z.ffi
Proof
metis_tac [assign_const_full]
QED
Theorem assign_with_const[simp]:
assign x y (z with clock := k) = OPTION_MAP (λs. s with clock := k) (assign x y z)
Proof
EVAL_TAC >> every_case_tac >> EVAL_TAC >> full_simp_tac(srw_ss())[]
QED
Theorem inst_with_const[simp]:
inst i (s with clock := k) = OPTION_MAP (λs. s with clock := k) (inst i s)
Proof
rw[inst_def] >> every_case_tac >> full_simp_tac(srw_ss())[]
QED
Theorem inst_const_full:
inst i s = SOME s' ⇒
s'.code = s.code ∧
s'.code_buffer = s.code_buffer ∧
s'.data_buffer = s.data_buffer ∧
s'.compile = s.compile ∧
s'.compile_oracle = s.compile_oracle ∧
s'.clock = s.clock ∧
s'.ffi = s.ffi ∧
s'.handler = s.handler ∧
s'.stack = s.stack ∧
s'.locals_size = s.locals_size ∧
s'.stack_limit = s.stack_limit ∧
s'.stack_max = s.stack_max ∧
s'.stack_size = s.stack_size
Proof
rw[inst_def, set_var_def,set_fp_var_def] >>
every_case_tac >> full_simp_tac(srw_ss())[] >>
imp_res_tac assign_const_full >> full_simp_tac(srw_ss())[] >> srw_tac[][] >>
imp_res_tac mem_store_const_full >> full_simp_tac(srw_ss())[] >> srw_tac[][]
QED
Theorem inst_const:
inst i s = SOME s' ⇒
s'.clock = s.clock ∧
s'.ffi = s.ffi
Proof
metis_tac [inst_const_full]
QED
Theorem jump_exc_const:
jump_exc s = SOME (x,y) ⇒
x.clock = s.clock ∧
x.ffi = s.ffi
Proof
EVAL_TAC >> every_case_tac >> EVAL_TAC >> srw_tac[][] >> srw_tac[][]
QED
Theorem jump_exc_with_const[simp]:
jump_exc (s with clock := k) = OPTION_MAP (λ(s,t). (s with clock := k, t)) (jump_exc s)
Proof
EVAL_TAC >> every_case_tac >> EVAL_TAC
QED
Theorem get_var_imm_with_const[simp]:
get_var_imm x (y with clock := k) = get_var_imm x y
Proof
Cases_on`x`>>EVAL_TAC
QED
Theorem dec_clock_const[simp]:
(dec_clock s).be = s.be /\
(dec_clock s).ffi = s.ffi /\
(dec_clock s).code = s.code /\
(dec_clock s).code_buffer = s.code_buffer /\
(dec_clock s).data_buffer = s.data_buffer /\
(dec_clock s).compile_oracle = s.compile_oracle ∧
(dec_clock s).stack = s.stack ∧
(dec_clock s).permute = s.permute ∧
(dec_clock s).compile = s.compile ∧
(dec_clock s).locals_size = s.locals_size ∧
(dec_clock s).stack_limit = s.stack_limit ∧
(dec_clock s).stack_max = s.stack_max ∧
(dec_clock s).stack_size = s.stack_size
Proof
EVAL_TAC
QED
Theorem sh_mem_set_var_const:
sh_mem_set_var r v s = (x,s') ==>
s'.clock = s.clock ∧
s'.compile_oracle = s.compile_oracle ∧
s'.compile = s.compile ∧
s'.be = s.be ∧
s'.gc_fun = s.gc_fun ∧
s'.code = s.code ∧
s'.code_buffer = s.code_buffer ∧
s'.data_buffer = s.data_buffer ∧
s'.permute = s.permute ∧
s'.handler = s.handler ∧
s'.stack_limit = s.stack_limit ∧
s'.stack_max = s.stack_max ∧
(r = NONE ==> s'.ffi = s.ffi) ∧
(r = SOME (FFI_final outcome) ==> s'.ffi = s.ffi) ∧
(r = NONE ==> s'.locals_size = s.locals_size) ∧
(r = SOME (FFI_return f l) ==> s'.locals_size = s.locals_size) ∧
(r = NONE ==> s'.stack_max = s.stack_max) ∧
(r = SOME (FFI_return f l) ==> s'.stack_max = s.stack_max) ∧
(r = NONE ==> s'.stack_size = s.stack_size) ∧
(r = SOME (FFI_return f l) ==> s'.stack_size = s.stack_size)
Proof
Cases_on `r` >>
gvs[sh_mem_set_var_def] >>
rename1 `sh_mem_set_var (SOME res) _ _ = _` >>
Cases_on `res` >>
rpt strip_tac >>
gvs[sh_mem_set_var_def,set_var_def] >>
simp[flush_state_def]
QED
Theorem sh_mem_store_const:
sh_mem_store ad v s = (res, s') ==>
s'.clock = s.clock ∧
s'.compile_oracle = s.compile_oracle ∧
s'.compile = s.compile ∧
s'.be = s.be ∧
s'.gc_fun = s.gc_fun ∧
s'.code = s.code ∧
s'.code_buffer = s.code_buffer ∧
s'.data_buffer = s.data_buffer ∧
s'.permute = s.permute ∧
s'.handler = s.handler ∧
s'.stack_limit = s.stack_limit ∧
s'.stack_max = s.stack_max ∧
(res = SOME Error ==> s'.locals_size = s.locals_size) ∧
(res = NONE ==> s'.locals_size = s.locals_size) ∧
(res = NONE ==> s'.stack_max = s.stack_max) ∧
(res = SOME Error ==> s'.stack_max = s.stack_max) ∧
(res = NONE ==> s'.stack_size = s.stack_size) ∧
(res = SOME Error ==> s'.stack_size = s.stack_size)
Proof
gvs[sh_mem_store_def] >>
rpt (TOP_CASE_TAC>> fs[]) >>
rpt strip_tac >>
gvs[flush_state_def]
QED
Theorem sh_mem_store_byte_const:
sh_mem_store_byte ad v s = (res, s') ==>
s'.clock = s.clock ∧
s'.compile_oracle = s.compile_oracle ∧
s'.compile = s.compile ∧
s'.be = s.be ∧
s'.gc_fun = s.gc_fun ∧
s'.code = s.code ∧
s'.code_buffer = s.code_buffer ∧
s'.data_buffer = s.data_buffer ∧
s'.permute = s.permute ∧
s'.handler = s.handler ∧
s'.stack_limit = s.stack_limit ∧
s'.stack_max = s.stack_max ∧
(res = SOME Error ==> s'.locals_size = s.locals_size) ∧
(res = NONE ==> s'.locals_size = s.locals_size) ∧
(res = NONE ==> s'.stack_max = s.stack_max) ∧
(res = SOME Error ==> s'.stack_max = s.stack_max) ∧
(res = NONE ==> s'.stack_size = s.stack_size) ∧
(res = SOME Error ==> s'.stack_size = s.stack_size)
Proof
gvs[sh_mem_store_byte_def] >>
rpt (TOP_CASE_TAC>> fs[]) >>
rpt strip_tac >>
gvs[flush_state_def]
QED
Theorem share_inst_const:
share_inst op v c s = (res, s') ==>
s'.code = s.code ∧
s'.code_buffer = s.code_buffer ∧
s'.data_buffer = s.data_buffer ∧
s'.compile = s.compile ∧
s'.compile_oracle = s.compile_oracle ∧
s'.permute = s.permute ∧
s'.clock = s.clock ∧
s'.handler = s.handler ∧
s'.stack_limit = s.stack_limit ∧
s'.stack_max = s.stack_max
Proof
Cases_on `op` >>
gvs[share_inst_def]
>- ( rpt strip_tac >>
metis_tac[sh_mem_set_var_const] )
>- ( rpt strip_tac >>
metis_tac[sh_mem_set_var_const] )
>> gvs[AllCaseEqs()]
>> rpt strip_tac
>> gvs[]
>> metis_tac[sh_mem_store_const,sh_mem_store_byte_const]
QED
Theorem sh_mem_set_var_with_const:
sh_mem_set_var res v s = (r,s') ==>
sh_mem_set_var res v (s with clock := k) = (r,s' with clock := k)
Proof
Cases_on `res` >>
gvs[sh_mem_set_var_def] >>
rename1 `sh_mem_set_var (SOME res)` >>
Cases_on `res` >>
gvs[sh_mem_set_var_def]
QED
Theorem sh_mem_load_with_const:
sh_mem_load a (s with clock := k) = sh_mem_load a s
Proof
gvs[sh_mem_load_def]
QED
Theorem sh_mem_load_byte_with_const:
sh_mem_load_byte a (s with clock := k) = sh_mem_load_byte a s
Proof
gvs[sh_mem_load_byte_def]
QED
Theorem sh_mem_store_with_const:
sh_mem_store a w s = (r, s') ==>
sh_mem_store a w (s with clock := k) = (r, s' with clock := k)
Proof
gvs[sh_mem_store_def] >>
rpt strip_tac >>
rpt (TOP_CASE_TAC >> gvs[]) >>
gvs[]
QED
Theorem sh_mem_store_byte_with_const:
sh_mem_store_byte a w s = (r, s') ==>
sh_mem_store_byte a w (s with clock := k) = (r, s' with clock := k)
Proof
gvs[sh_mem_store_byte_def] >>
rpt strip_tac >>
rpt (TOP_CASE_TAC >> gvs[]) >>
gvs[]
QED
Theorem share_inst_with_const:
share_inst op v c s = (r,s') ==>
share_inst op v c (s with clock := k) = (r, s' with clock := k)
Proof
rpt strip_tac >>
Cases_on `op` >>
gvs[share_inst_def]
>- metis_tac[sh_mem_set_var_with_const,
sh_mem_load_with_const]
>- metis_tac[sh_mem_set_var_with_const,
sh_mem_load_byte_with_const] >>
rpt (TOP_CASE_TAC >> gvs[])
>- metis_tac[sh_mem_store_with_const]
>- metis_tac[sh_mem_store_byte_with_const]
QED
(*code and gc_fun are unchanged across eval*)
Theorem pop_env_code_gc_fun_clock:
pop_env r = SOME x ⇒
r.code = x.code ∧
r.code_buffer = x.code_buffer ∧
r.data_buffer = x.data_buffer ∧
r.gc_fun = x.gc_fun ∧
r.clock = x.clock ∧
r.be = x.be ∧
r.mdomain = x.mdomain ∧
r.sh_mdomain = x.sh_mdomain ∧
r.compile = x.compile ∧
r.compile_oracle = x.compile_oracle ∧
r.stack_limit = x.stack_limit ∧
r.stack_max = x.stack_max ∧
r.stack_size = x.stack_size
Proof
fs[pop_env_def]>>EVERY_CASE_TAC>>fs[state_component_equality]
QED
(* Standard add clock lemma for FBS *)
(* TODO: generated names *)
Theorem evaluate_add_clock:
∀p s r s'.
evaluate (p,s) = (r,s') ∧ r ≠ SOME TimeOut ⇒
evaluate (p,s with clock := s.clock + extra) = (r,s' with clock := s'.clock + extra)
Proof
recInduct evaluate_ind >>
srw_tac[][evaluate_def] >>
TRY CASE_TAC >> full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >> rveq >>
TRY CASE_TAC >> full_simp_tac(srw_ss())[] >>
TRY CASE_TAC >> full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >> rveq
>~ [`share_inst`]
>- (
Cases_on `op` >>
gvs[share_inst_def,sh_mem_load_def,
sh_mem_load_byte_def,sh_mem_store_def,
sh_mem_store_byte_def]
>- (
IF_CASES_TAC >>
gvs[sh_mem_set_var_def] >>
qpat_abbrev_tac`res = call_FFI _ _ _ _` >>
Cases_on `res` >>
gvs[sh_mem_set_var_def] )
>- (
IF_CASES_TAC >>
gvs[sh_mem_set_var_def] >>
qpat_abbrev_tac`res = call_FFI _ _ _ _` >>
Cases_on `res` >>
gvs[sh_mem_set_var_def] )
>> rpt (TOP_CASE_TAC >> gvs[AllCaseEqs()] )
) >>
TRY (
rename1`find_code _ (add_ret_loc _ _)` >>
Cases_on`get_vars args s`>>full_simp_tac(srw_ss())[]>>
Cases_on`find_code dest (add_ret_loc (SOME x) x') s.code s.stack_size`>>full_simp_tac(srw_ss())[]>>
PairCases_on`x''`>>PairCases_on`x`>>full_simp_tac(srw_ss())[]>>
Cases_on`cut_env x1 s.locals`>>full_simp_tac(srw_ss())[]>>
qpat_x_assum`A=(r,s')` mp_tac>>
rpt(IF_CASES_TAC>>full_simp_tac(srw_ss())[])>>
full_case_tac>>full_simp_tac(srw_ss())[]>>Cases_on`q`>>TRY(Cases_on `x''`)>>
fsrw_tac[ARITH_ss][dec_clock_def]>>
rev_full_simp_tac(srw_ss()++ARITH_ss)[]>>
every_case_tac >> full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >>
rev_full_simp_tac(srw_ss())[] >> full_simp_tac(srw_ss())[] >>
imp_res_tac pop_env_const >> full_simp_tac(srw_ss())[] >>
rev_full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >> srw_tac[][] >>
full_simp_tac(srw_ss())[])>>
TRY (
rename1`find_code _ (add_ret_loc _ _)` >>
Cases_on`get_vars args s`>>full_simp_tac(srw_ss())[]>>
Cases_on`find_code dest (add_ret_loc ret x') s.code s.stack_size`>>full_simp_tac(srw_ss())[]>>
Cases_on`ret`>>full_simp_tac(srw_ss())[]>>
PairCases_on`x''`>>full_simp_tac(srw_ss())[]>>
PairCases_on`x'''`>>full_simp_tac(srw_ss())[]>>
Cases_on`cut_env x'''1 s.locals`>>full_simp_tac(srw_ss())[]>>
qpat_x_assum`A=(r,s')` mp_tac>>
rpt(IF_CASES_TAC>>full_simp_tac(srw_ss())[])>>
Cases_on`evaluate (x''1,call_env x''0 x''2 (push_env x'' (SOME x) (dec_clock s)))`>>Cases_on`q`>>TRY(Cases_on`x'''`)>>
fsrw_tac[ARITH_ss][dec_clock_def]>>
rev_full_simp_tac(srw_ss()++ARITH_ss)[]>>srw_tac[][]>>
every_case_tac >> full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >>
rev_full_simp_tac(srw_ss())[] >> full_simp_tac(srw_ss())[] >>
imp_res_tac pop_env_const >> full_simp_tac(srw_ss())[] >>
rev_full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >> srw_tac[][] >>
full_simp_tac(srw_ss())[])>>
TRY (
rename1`alloc _ _ _ = _` >>
fs[alloc_def,gc_def,LET_THM]>> every_case_tac >>
fs[call_env_def,push_env_def,LET_THM,env_to_list_def
,set_store_def,state_component_equality,flush_state_def]>>
imp_res_tac pop_env_code_gc_fun_clock>>fs[]) >>
TRY (
TOP_CASE_TAC>>fs[]>>rw[]>>fs[state_component_equality,unset_var_def,set_var_def]>>
NO_TAC)>>
full_simp_tac(srw_ss())[LET_THM,dec_clock_def] >>
TRY pairarg_tac >> full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >>
imp_res_tac alloc_const >> full_simp_tac(srw_ss())[] >>
imp_res_tac inst_const >> full_simp_tac(srw_ss())[] >>
TRY(Cases_on`mem_store c x s`)>>
imp_res_tac mem_store_const >> fs[]>>
simp[state_component_equality,dec_clock_def] >>
full_simp_tac(srw_ss())[ffiTheory.call_FFI_def,LET_THM] >>rfs[]>>
every_case_tac >> full_simp_tac(srw_ss())[] >> rveq >> full_simp_tac(srw_ss())[] >> rveq >>
simp[state_component_equality,dec_clock_def] >>
imp_res_tac jump_exc_const >> full_simp_tac(srw_ss())[] >>
rev_full_simp_tac(srw_ss())[] >>fsrw_tac[ARITH_ss][] >>
rev_full_simp_tac(srw_ss()++ARITH_ss)[]>>rveq>>full_simp_tac(srw_ss())[]>>
fs[call_env_def,flush_state_def]>>metis_tac[]
QED
val tac = EVERY_CASE_TAC>>full_simp_tac(srw_ss())[state_component_equality]
val tac2 =
strip_tac>>rveq>>full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_clock>>full_simp_tac(srw_ss())[]>>
`¬ (s.clock ≤ r.clock)` by DECIDE_TAC>>full_simp_tac(srw_ss())[]>>
`s.clock -1 -r.clock = s.clock - r.clock-1` by DECIDE_TAC>>full_simp_tac(srw_ss())[]
(* This lemma is interesting in wordLang because of the use of MustTerminate
To remove MustTerminate, we need to inject an exact number of clock ticks
corresponding to the ticks used in the MustTerminate block
The number of clock ticks is fixed for any program, and can be characterized by st.clock - rst.clock *)
Theorem evaluate_dec_clock:
∀prog st res rst.
evaluate(prog,st) = (res,rst) ⇒
evaluate(prog,st with clock:=st.clock-rst.clock) = (res,rst with clock:=0)
Proof
recInduct evaluate_ind >>srw_tac[][evaluate_def]>>full_simp_tac(srw_ss())[call_env_def,dec_clock_def]
>- (tac>>imp_res_tac alloc_const>>full_simp_tac(srw_ss())[])
>- (tac>>rw[]>>fs[state_component_equality,unset_var_def,set_var_def])
>- tac
>- (TOP_CASE_TAC>>full_simp_tac(srw_ss())[]>> assume_tac inst_const>>tac)
>- tac
>- tac
>- tac
>- tac
>- (tac>>imp_res_tac mem_store_const>>full_simp_tac(srw_ss())[])
>- DECIDE_TAC
>- `F`by DECIDE_TAC
>- (full_simp_tac(srw_ss())[state_component_equality]>>DECIDE_TAC)
>- (srw_tac[][]>>full_simp_tac(srw_ss())[state_component_equality,LET_THM])
>-
(qpat_x_assum`A=(res,rst)` mp_tac>>simp[]>>pairarg_tac>>full_simp_tac(srw_ss())[]>>
IF_CASES_TAC>>full_simp_tac(srw_ss())[]
>-
(strip_tac>>full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_clock>>full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_add_clock>>full_simp_tac(srw_ss())[]>>
first_x_assum(qspec_then`s1'.clock - rst.clock` mp_tac)>>simp[])
>>
strip_tac>>full_simp_tac(srw_ss())[])
>- tac
>- (tac>>imp_res_tac jump_exc_const>>full_simp_tac(srw_ss())[])
>- tac
>-
(tac>>fs[]>>pairarg_tac>>fs[]>>
every_case_tac>>fs[state_component_equality])
>- tac
>- tac
>- (tac>>fs[cut_env_def]>> rveq >> fs [])
>- (
tac >>
Cases_on `op` >>
fs[share_inst_def]
>- (
gvs[sh_mem_load_def,sh_mem_load_byte_def] >>
IF_CASES_TAC >>
gvs[sh_mem_set_var_def] >>
qpat_abbrev_tac `x = call_FFI _ _ _ _` >>
Cases_on `x` >>
gvs[sh_mem_set_var_def]
)
>- (
gvs[sh_mem_load_def,sh_mem_load_byte_def] >>
IF_CASES_TAC >>
gvs[sh_mem_set_var_def] >>
qpat_abbrev_tac `x = call_FFI _ _ _ _` >>
Cases_on `x` >>
gvs[sh_mem_set_var_def]
) >>
gvs[AllCaseEqs(),sh_mem_store_def,sh_mem_store_byte_def] )
>>
qpat_x_assum`A=(res,rst)` mp_tac>>
ntac 6 (TOP_CASE_TAC>>full_simp_tac(srw_ss())[])
>-
(ntac 3 (TOP_CASE_TAC>>full_simp_tac(srw_ss())[state_component_equality])>>
TOP_CASE_TAC>>full_simp_tac(srw_ss())[]>>
tac2>>
first_x_assum(qspec_then`r` assume_tac)>>rev_full_simp_tac(srw_ss())[])
>>
ntac 7 (TOP_CASE_TAC>>full_simp_tac(srw_ss())[])>-
(strip_tac>>rveq>>full_simp_tac(srw_ss())[flush_state_def])>>
ntac 2 (TOP_CASE_TAC>>full_simp_tac(srw_ss())[])>-
tac2>>
TOP_CASE_TAC
>-
(TOP_CASE_TAC>-tac2>>
TOP_CASE_TAC>-tac2>>
reverse TOP_CASE_TAC>-
(tac2>>imp_res_tac pop_env_const>>
rveq>>full_simp_tac(srw_ss())[])>>
strip_tac>>full_simp_tac(srw_ss())[]>>
rev_full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_clock>>full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_add_clock>>full_simp_tac(srw_ss())[]>>
imp_res_tac pop_env_const>>rveq>>full_simp_tac(srw_ss())[]>>
first_x_assum(qspec_then`r.clock-rst.clock` kall_tac)>>
first_x_assum(qspec_then`r.clock-rst.clock` mp_tac)>>
simp[])
>-
(TOP_CASE_TAC>-tac2>>
ntac 3 (TOP_CASE_TAC>>full_simp_tac(srw_ss())[])>>
TOP_CASE_TAC>-tac2>>
reverse TOP_CASE_TAC>- tac2>>
strip_tac>>full_simp_tac(srw_ss())[]>>
rev_full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_clock>>full_simp_tac(srw_ss())[]>>
imp_res_tac evaluate_add_clock>>full_simp_tac(srw_ss())[]>>
imp_res_tac pop_env_const>>rveq>>full_simp_tac(srw_ss())[]>>
first_x_assum(qspec_then`r.clock-rst.clock` kall_tac)>>
first_x_assum(qspec_then`r.clock-rst.clock` mp_tac)>>
simp[])
>>
tac2
QED
(* IO and clock monotonicity *)
Theorem evaluate_io_events_mono:
!exps s1 res s2.
evaluate (exps,s1) = (res, s2) ⇒
s1.ffi.io_events ≼ s2.ffi.io_events
Proof
recInduct evaluate_ind >> ntac 5 strip_tac >>
rpt conj_tac >>
rpt gen_tac >>
full_simp_tac(srw_ss())[evaluate_def] >>
rpt gen_tac >>
rpt (pop_assum mp_tac) >>
rpt (TOP_CASE_TAC >> full_simp_tac(srw_ss())[]) >>
rpt (disch_then strip_assume_tac ORELSE gen_tac) >> full_simp_tac(srw_ss())[] >>
rveq >> full_simp_tac(srw_ss())[] >>
imp_res_tac alloc_const >> full_simp_tac(srw_ss())[] >>