-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathdata_to_word_memoryProofScript.sml
13384 lines (12746 loc) · 505 KB
/
data_to_word_memoryProofScript.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
(*
Part of the correctness proof for data_to_word
*)
open preamble dataSemTheory dataPropsTheory copying_gcTheory
int_bitwiseTheory wordSemTheory data_to_wordTheory set_sepTheory
labSemTheory whileTheory helperLib alignmentTheory multiwordTheory
gc_sharedTheory gc_combinedTheory word_gcFunctionsTheory;
local open blastLib in end;
val shift_def = backend_commonTheory.word_shift_def;
val good_dimindex_def = miscTheory.good_dimindex_def;
val _ = new_theory "data_to_word_memoryProof";
val _ = temp_delsimps ["NORMEQ_CONV", "lift_disj_eq", "lift_imp_disj"]
val _ = diminish_srw_ss ["ABBREV"]
val _ = set_trace "BasicProvers.var_eq_old" 1
val drule = old_drule
(* TODO: move? *)
val clean_tac = rpt var_eq_tac \\ rpt (qpat_x_assum `T` kall_tac)
fun rpt_drule th = drule (th |> GEN_ALL) \\ rpt (disch_then drule \\ fs [])
val _ = augment_srw_ss[rewrites[LENGTH_REPLICATE]]
val _ = set_grammar_ancestry
["dataSem", "dataProps", "wordSem", "data_to_word",
"gc_shared", "gc_combined", "word_gcFunctions"];
val _ = Parse.hide"el";
Overload good_dimindex[local] = ``misc$good_dimindex``
val LESS_4 = DECIDE ``i < 4 <=> (i = 0) \/ (i = 1) \/ (i = 2) \/ (i = 3n)``
val LESS_8 = DECIDE ``i < 8 <=> (i = 0) \/ (i = 1) \/ (i = 2) \/ (i = 3n) \/
(i = 4) \/ (i = 5) \/ (i = 6) \/ (i = 7)``
Theorem word_eq:
!w v. w = v <=> !n. word_bit n w = word_bit n v
Proof
fs [word_bit_thm,fcpTheory.CART_EQ]
\\ rw [] \\ eq_tac \\ rw []
\\ eq_tac \\ rw [] \\ res_tac \\ fs []
QED
Theorem ZIP_REPLICATE:
!n. ZIP (REPLICATE n x, REPLICATE n y) = REPLICATE n (x,y)
Proof
Induct \\ fs [REPLICATE]
QED
Theorem list_max_leq_suff:
EVERY (\x. x <= b) ls ==> list_max ls <= b
Proof
Induct_on`ls` \\ rw[list_max_def]
QED
Theorem list_max_mem:
ls <> [] ==> MEM (list_max ls) ls
Proof
Induct_on`ls` \\ rw[list_max_def]
\\ Cases_on`ls` \\ fs[list_max_def]
QED
Theorem list_max_sum_bound:
SUM ls <= list_max ls * LENGTH ls
Proof
Induct_on`ls` \\ rw[list_max_def,ADD1,LEFT_ADD_DISTRIB]
\\ match_mp_tac LESS_EQ_TRANS
\\ asm_exists_tac \\ simp[]
QED
Theorem list_max_bounded_elements:
!l1 l2. LIST_REL $<= l1 l2 ==> list_max l1 <= list_max l2
Proof
Induct \\ rw[list_max_def] \\ res_tac \\ rw[list_max_def]
QED
Theorem list_max_map:
∀f l. (∀x y. x < y ==> f x < f y) ==> list_max (MAP f l) = if NULL l then 0 else f (list_max l)
Proof
rpt strip_tac
\\ Induct_on`l` \\ rw[list_max_def,NULL_EQ]
\\ res_tac \\ fs[list_max_def] \\ rveq
\\ fs[NOT_LESS]
\\ Cases_on`l = []` \\ fs[list_max_def]
\\ Cases_on`h < list_max l` \\ fs[]
>- ( res_tac \\ fs[] )
\\ `h = list_max l` by fs[]
\\ fs[]
QED
Theorem w2i_i2w_IMP:
(w2i ((i2w i):'a word)) = i ==> INT_MIN (:α) ≤ i ∧ i ≤ INT_MAX (:α)
Proof
Cases_on `i`
\\ fs [integer_wordTheory.i2w_def,integer_wordTheory.w2i_def] \\ rw []
THEN1
(fs [word_msb_def,word_index,bitTheory.BIT_def,bitTheory.BITS_THM]
\\ `(n DIV 2 ** (dimindex (:α) − 1)) MOD 2 < 2` by fs []
\\ Cases_on `(n DIV 2 ** (dimindex (:α) − 1)) MOD 2` \\ fs []
\\ fs [DIV_MOD_MOD_DIV,GSYM EXP,ADD1]
\\ assume_tac DIMINDEX_GT_0
\\ `dimindex (:α) − 1 + 1 = dimindex (:α)` by decide_tac \\ fs []
\\ rfs [dimword_def] \\ fs [DIV_EQ_X]
\\ fs [wordsTheory.INT_MIN_def,integer_wordTheory.INT_MIN_def,
wordsTheory.INT_MAX_def,integer_wordTheory.INT_MAX_def])
\\ full_simp_tac std_ss [GSYM (``-(w:'a word)`` |> SIMP_CONV (srw_ss()) []),
WORD_NEG_NEG,w2n_n2w] \\ fs [X_MOD_Y_EQ_X]
\\ `dimindex (:α) − 1 < dimindex (:α)` by fs []
\\ full_simp_tac std_ss [word_msb_def,word_2comp_n2w,word_index]
\\ fs [bitTheory.BIT_def,bitTheory.BITS_THM]
\\ fs [DIV_MOD_MOD_DIV,GSYM EXP,ADD1]
\\ assume_tac DIMINDEX_GT_0
\\ `dimindex (:α) − 1 + 1 = dimindex (:α)` by decide_tac \\ fs []
\\ fs [dimword_def]
\\ `(2 ** dimindex (:α) − n) < 2 ** dimindex (:α)` by decide_tac \\ fs []
\\ fs [DIV_EQ_X] \\ fs [GSYM EXP,ADD1]
\\ Cases_on `dimindex (:α)` \\ fs []
\\ fs [wordsTheory.INT_MIN_def,integer_wordTheory.INT_MIN_def,
wordsTheory.INT_MAX_def,integer_wordTheory.INT_MAX_def,EXP]
QED
Theorem word_i2w_sub:
!a b. i2w a - i2w b = i2w (a - b)
Proof
fs [integer_wordTheory.word_i2w_add,word_sub_def,integerTheory.int_sub,
integer_wordTheory.MULT_MINUS_ONE]
QED
(* -- *)
Datatype:
tag = BlockTag num | RefTag | BytesTag bool num | NumTag bool | Word64Tag
End
Definition BlockRep_def:
BlockRep tag xs = DataElement xs (LENGTH xs) (BlockTag tag,[])
End
Type ml_el = ``:('a word_loc, tag # ('a word_loc list)) heap_element``
Type ml_heap = ``:'a ml_el list``
Definition Bytes_def:
((Bytes is_bigendian cmp_by_contents (bs:word8 list) (ws:'a word list)):'a ml_el) =
let ws = write_bytes bs ws is_bigendian in
DataElement [] (LENGTH ws) (BytesTag cmp_by_contents (LENGTH bs), MAP Word ws)
End
Definition Bignum_def:
Bignum i =
let (sign,payload:'a word list) = i2mw i in
DataElement [] (LENGTH payload) (NumTag sign, MAP Word payload)
End
Definition BlockNil_def:
BlockNil n = n2w n << 4 + 2w
End
Definition Word64Rep_def:
Word64Rep (:'a) (w:word64) =
if dimindex (:'a) < 64 then
DataElement [] 2 (Word64Tag, [Word ((63 >< 32) w); Word ((31 >< 0) w)])
else
DataElement [] 1 (Word64Tag, [Word (((63 >< 0) w):'a word)])
End
Theorem Word64Rep_DataElement:
∀a w. ∃ws. (Word64Rep a w:'a ml_el) = DataElement [] (LENGTH ws) (Word64Tag,ws)
Proof
Cases \\ rw[Word64Rep_def]
QED
Triviality v_size_LEMMA:
!vs v. MEM v vs ==> v_size v <= v1_size vs
Proof
Induct \\ full_simp_tac (srw_ss()) [v_size_def]
\\ rpt strip_tac \\ res_tac \\ full_simp_tac std_ss [] \\ DECIDE_TAC
QED
(*
code pointers (i.e. Locs) will end in ...0
small numbers end in ...00
NIL-like constructors end in ...10
*)
Definition v_inv_def[schematic]:
(* v_inv v (x,f,tf,heap)
v : the dataSem value
x : the abstract gc value
f : reference values in dataLang to gc address (sort of like the content of the pointer)
tf : time-stamps in dataLang to gc addresses
heap : is the gc abstract heap
*)
(v_inv (Number i) (x,f,tf,heap:'a ml_heap) <=>
if small_int (:'a) i then (x = Data (Word (Smallnum i))) else
?ptr. (x = Pointer ptr (Word 0w)) /\
(heap_lookup ptr heap = SOME (Bignum i))) /\
(v_inv (Word64 w) (x,f,tf,heap) <=>
?ptr. (x = Pointer ptr (Word 0w)) /\
(heap_lookup ptr heap = SOME (Word64Rep (:'a) w))) /\
(v_inv (CodePtr n) (x,f,tf,heap) <=>
(x = Data (Loc n 0))) /\
(v_inv (RefPtr _ n) (x,f,tf,heap) <=>
(x = Pointer (f ' n) (Word 0w)) /\ n IN FDOM f) /\
(v_inv (Block ts n vs) (x,f,tf,heap) <=>
if vs = []
then (x = Data (Word (BlockNil n))) /\
n < dimword(:'a) DIV 16 /\
ts = 0
else
?ptr xs.
EVERY2 (\v x. v_inv v (x,f,tf,heap)) vs xs /\
FLOOKUP tf ts = SOME ptr ∧
(x = Pointer ptr (Word (ptr_bits conf n (LENGTH xs)))) /\
(heap_lookup ptr heap = SOME (BlockRep n xs)))
Termination
WF_REL_TAC `measure (v_size o FST)` \\ rpt strip_tac
\\ imp_res_tac v_size_LEMMA \\ DECIDE_TAC
End
Definition get_refs_def:
(get_refs (Number _) = []) /\
(get_refs (Word64 _) = []) /\
(get_refs (CodePtr _) = []) /\
(get_refs (RefPtr _ p) = [p]) /\
(get_refs (Block _ _ vs) = FLAT (MAP get_refs vs))
Termination
WF_REL_TAC `measure (v_size)` \\ rpt strip_tac \\ Induct_on `vs`
\\ srw_tac [] [v_size_def] \\ res_tac \\ DECIDE_TAC
End
Definition ref_edge_def:
ref_edge refs (x:num) (y:num) =
case lookup x refs of
| SOME (ValueArray ys) => MEM y (get_refs (Block 0 ARB ys))
| _ => F
End
Definition reachable_refs_def:
reachable_refs roots refs t =
?x r. MEM x roots /\ MEM r (get_refs x) /\ RTC (ref_edge refs) r t
End
Definition RefBlock_def:
RefBlock xs = DataElement xs (LENGTH xs) (RefTag,[])
End
Definition bc_ref_inv_def:
bc_ref_inv conf n refs (f,tf,heap,be) =
case (FLOOKUP f n, lookup n refs) of
| (SOME x, SOME (ValueArray ys)) =>
(?zs. (heap_lookup x heap = SOME (RefBlock zs)) /\
EVERY2 (\z y. v_inv conf y (z,f,tf,heap)) zs ys)
| (SOME x, SOME (ByteArray flag bs)) =>
let ws = LENGTH bs DIV (dimindex (:α) DIV 8) + 1 in
(heap_lookup x heap = SOME (Bytes be flag bs (REPLICATE ws (0w:'a word))))
| _ => F
End
(* TODO: MOVE *)
Definition v_all_ts_def:
v_all_ts (Block ts _ xs) = ts :: FLAT (MAP v_all_ts xs)
∧ v_all_ts _ = []
Termination
WF_REL_TAC `measure (v_size)` \\ rpt strip_tac \\ Induct_on `xs`
\\ srw_tac [] [v_size_def] \\ res_tac \\ DECIDE_TAC
End
(* TODO: MOVE *)
Definition all_ts_def:
all_ts refs stack =
let refs_v = {x | ∃n l. sptree$lookup n refs = SOME (ValueArray l) ∧ MEM x l}
in {ts | ∃x. (x ∈ refs_v ∨ MEM x stack) ∧ MEM ts (v_all_ts x)}
End
Definition be_ok_def:
be_ok b1 b2 ⇔ b1 = b2
End
(* THIS IS IMPORTANT *)
Definition bc_stack_ref_inv_def:
bc_stack_ref_inv conf ts stack refs (roots, heap, be) =
?f tf.
INJ (FAPPLY f) (FDOM f) { a | isSomeDataElement (heap_lookup a heap) } /\
FDOM f SUBSET (domain refs) /\
INJ (FAPPLY tf) (FDOM tf) { a | isSomeDataElement (heap_lookup a heap) } /\
FDOM tf SUBSET (all_ts refs stack) /\
FDOM tf SUBSET { n | n < ts } /\ be_ok conf.be be /\
EVERY2 (\v x. v_inv conf v (x,f,tf,heap)) stack roots /\
!n. reachable_refs stack refs n ==> bc_ref_inv conf n refs (f,tf,heap,be)
End
Definition data_up_to_def:
data_up_to a heap =
?h1 h2. heap_split a heap = SOME (h1,h2) /\ EVERY isDataElement h1
End
Definition unused_space_inv_def:
unused_space_inv ptr l heap <=>
(l <> 0 ==> (heap_lookup ptr heap = SOME (Unused (l-1)))) /\
ptr + l <= heap_length heap /\
data_up_to ptr heap
End
Definition isRef_def:
isRef (DataElement ys l (tag,qs)) = (tag = RefTag) /\
isRef _ = F
End
Definition gen_start_ok_def:
gen_start_ok heap refs_start gen_start =
?h1 h2.
heap_split gen_start heap = SOME (h1,h2) /\
!xs l d p e.
MEM (DataElement xs l d) h1 /\ MEM (Pointer p e) xs ==>
p < gen_start \/ refs_start <= p
End
Definition gen_state_ok_def:
gen_state_ok a refs_start heap (GenState _ starts) <=>
EVERY (\s. s <= a) starts /\
EVERY (gen_start_ok heap refs_start) starts
End
Definition gc_kind_inv_def:
gc_kind_inv c a sp sp1 (gens:gen_state) heap <=>
case c.gc_kind of
| None => (sp1 = 0n)
| Simple => (sp1 = 0n)
| Generational sizes =>
gen_state_ok a (a + sp + sp1) heap gens /\
?h1 h2. (heap_split (a + sp + sp1) heap = SOME (h1,h2)) /\
EVERY (\x. ~isRef x) h1 /\ EVERY isRef h2
End
Definition abs_ml_inv_def:
abs_ml_inv conf stack refs (roots,heap,be,a,sp,sp1,gens) limit ts <=>
roots_ok roots heap /\ heap_ok heap limit /\
gc_kind_inv conf a sp sp1 gens heap /\
unused_space_inv a (sp+sp1) heap /\
bc_stack_ref_inv conf ts stack refs (roots,heap,be)
End
(* --- *)
(* TODO: move/reorganise various things in this file *)
Theorem word_list_limit:
EVERY isWord ws ∧ ALL_DISTINCT ws ⇒
LENGTH (ws:'a word_loc list) ≤ dimword(:'a)
Proof
rw[]
\\ `LENGTH ws = CARD (set ws)` by simp[ALL_DISTINCT_CARD_LIST_TO_SET]
\\ pop_assum SUBST_ALL_TAC
\\ CONV_TAC(RAND_CONV(REWR_CONV(GSYM CARD_COUNT)))
\\ CCONTR_TAC
\\ pop_assum (strip_assume_tac o REWRITE_RULE[NOT_LESS_EQUAL])
\\ `FINITE (count (dimword (:'a)))` by simp[]
\\ imp_res_tac PHP
\\ pop_assum mp_tac
\\ pop_assum kall_tac
\\ simp[]
\\ qexists_tac`w2n o theWord`
\\ simp[INJ_DEF] \\ fs[EVERY_MEM,isWord_exists]
\\ rw[] \\ res_tac \\ fs[theWord_def]
\\ metis_tac[w2n_lt]
QED
Theorem MOD_EQ_0_0:
∀n b. 0 < b ⇒ (n MOD b = 0) ⇒ n < b ⇒ (n = 0)
Proof
rw[MOD_EQ_0_DIVISOR] >> Cases_on`d`>>fs[]
QED
Theorem EVERY2_IMP_EVERY:
!xs ys. EVERY2 P xs ys ==> EVERY (\(x,y). P y x) (ZIP(ys,xs))
Proof
Induct \\ Cases_on `ys` \\ full_simp_tac(srw_ss())[]
QED
Theorem EVERY2_IMP_EVERY2:
!xs ys P1 P2.
(!x y. MEM x xs /\ MEM y ys /\ P1 x y ==> P2 x y) ==>
EVERY2 P1 xs ys ==> EVERY2 P2 xs ys
Proof
Induct \\ Cases_on `ys` \\ full_simp_tac (srw_ss()) []
\\ rpt strip_tac \\ metis_tac []
QED
Theorem MEM_EVERY2_IMP:
!l x zs P. MEM x l /\ EVERY2 P zs l ==> ?z. MEM z zs /\ P z x
Proof
Induct \\ Cases_on `zs` \\ full_simp_tac (srw_ss()) [] \\ metis_tac []
QED
val EVERY2_LENGTH = LIST_REL_LENGTH
val EVERY2_IMP_LENGTH = EVERY2_LENGTH
Theorem EVERY2_APPEND_CONS:
!xs y ys zs P. EVERY2 P (xs ++ y::ys) zs ==>
?t1 t t2. (zs = t1 ++ t::t2) /\ (LENGTH t1 = LENGTH xs) /\
EVERY2 P xs t1 /\ P y t /\ EVERY2 P ys t2
Proof
Induct \\ full_simp_tac (srw_ss()) []
\\ Cases_on `zs` \\ full_simp_tac (srw_ss()) []
\\ rpt strip_tac
\\ res_tac \\ full_simp_tac std_ss []
\\ Q.LIST_EXISTS_TAC [`h::t1`,`t'`,`t2`]
\\ full_simp_tac (srw_ss()) []
QED
Theorem EVERY2_SWAP:
!xs ys. EVERY2 P xs ys ==> EVERY2 (\y x. P x y) ys xs
Proof
Induct \\ Cases_on `ys` \\ full_simp_tac (srw_ss()) []
QED
Theorem EVERY2_APPEND_IMP_APPEND:
!xs1 xs2 ys P.
EVERY2 P (xs1 ++ xs2) ys ==>
?ys1 ys2. (ys = ys1 ++ ys2) /\ EVERY2 P xs1 ys1 /\ EVERY2 P xs2 ys2
Proof
Induct \\ Cases_on `ys` \\ full_simp_tac (srw_ss()) [] \\ rpt strip_tac
\\ res_tac \\ full_simp_tac std_ss []
\\ Q.LIST_EXISTS_TAC [`h::ys1`,`ys2`]
\\ full_simp_tac std_ss [APPEND,LIST_REL_def] \\ metis_tac[]
QED
val EVERY2_IMP_APPEND = rich_listTheory.EVERY2_APPEND_suff
val IMP_EVERY2_APPEND = EVERY2_IMP_APPEND
val EVERY2_EQ_EL = LIST_REL_EL_EQN
val EVERY2_IMP_EL = METIS_PROVE[EVERY2_EQ_EL]
``!xs ys P. EVERY2 P xs ys ==> !n. n < LENGTH ys ==> P (EL n xs) (EL n ys)``
Triviality EVERY2_MAP_FST_SND:
!xs. EVERY2 P (MAP FST xs) (MAP SND xs) = EVERY (\(x,y). P x y) xs
Proof
Induct \\ srw_tac [] [LIST_REL_def] \\ Cases_on `h` \\ srw_tac [] []
QED
Theorem fapply_fupdate_update:
$' (f |+ p) = (FST p =+ SND p) ($' f)
Proof
Cases_on`p`>>
simp[FUN_EQ_THM,FAPPLY_FUPDATE_THM,APPLY_UPDATE_THM] >> rw[]
QED
Triviality heap_lookup_APPEND1:
∀h1 z h2.
heap_length h1 ≤ z ⇒
(heap_lookup z (h1 ++ h2) = heap_lookup (z - heap_length h1) h2)
Proof
Induct >>fs[heap_lookup_def,heap_length_def] >> rw[] >> simp[]
>> fsrw_tac[ARITH_ss][] >> Cases_on`h`>>fs[el_length_def]
QED
Triviality heap_lookup_APPEND2:
∀h1 z h2.
z < heap_length h1 ⇒
(heap_lookup z (h1 ++ h2) = heap_lookup z h1)
Proof
Induct >> fs[heap_lookup_def,heap_length_def] >> rw[] >>
simp[]
QED
Theorem heap_lookup_APPEND:
heap_lookup a (h1 ++ h2) =
if a < heap_length h1 then
heap_lookup a h1 else
heap_lookup (a-heap_length h1) h2
Proof
rw[heap_lookup_APPEND2] >>
simp[heap_lookup_APPEND1]
QED
(* Prove refinement is maintained past GC calls *)
Triviality LENGTH_ADDR_MAP:
!xs f. LENGTH (ADDR_MAP f xs) = LENGTH xs
Proof
Induct \\ TRY (Cases_on `h`) \\ srw_tac [] [ADDR_MAP_def]
QED
Triviality MEM_IMP_v_size:
!l a. MEM a l ==> v_size a < 1 + v1_size l
Proof
Induct \\ full_simp_tac std_ss [MEM,v_size_def]
\\ rpt strip_tac \\ full_simp_tac std_ss [] \\ res_tac \\ DECIDE_TAC
QED
Triviality EL_ADDR_MAP:
!xs n f.
n < LENGTH xs ==> (EL n (ADDR_MAP f xs) = ADDR_APPLY f (EL n xs))
Proof
Induct \\ full_simp_tac (srw_ss()) [] \\ Cases_on `n` \\ Cases_on `h`
\\ full_simp_tac (srw_ss()) [ADDR_MAP_def,ADDR_APPLY_def]
QED
val _ = augment_srw_ss [rewrites [LIST_REL_def]];
Triviality v_inv_related:
!w x f tf.
gc_shared$gc_related g heap1 (heap2:'a ml_heap) /\
(!ptr u. (x = Pointer ptr u) ==> ptr IN FDOM g) /\
v_inv conf w (x,f,tf,heap1) ==>
v_inv conf w (ADDR_APPLY (FAPPLY g) x,g f_o_f f,g f_o_f tf,heap2) /\
EVERY (\n. f ' n IN FDOM g) (get_refs w)
Proof
completeInduct_on `v_size w` \\ NTAC 6 strip_tac
\\ fs[PULL_FORALL] \\ Cases_on `w` THEN1
(fs[v_inv_def,get_refs_def,EVERY_DEF]
\\ Cases_on `small_int (:'a) i` \\ fs [] THEN1
(full_simp_tac (srw_ss()) [ADDR_APPLY_def,Bignum_def]
\\ fs[gc_related_def] \\ res_tac
\\ fs[ADDR_MAP_def] \\ fs [])
\\ fs [gc_related_def,ADDR_APPLY_def,Bignum_def]
\\ pairarg_tac \\ fs [] \\ res_tac \\ fs [ADDR_MAP_def])
THEN1
(fs[v_inv_def,get_refs_def,EVERY_DEF]
\\ full_simp_tac (srw_ss()) [ADDR_APPLY_def]
\\ fs[gc_related_def]
\\ first_x_assum drule
\\ qspecl_then[`:'a`,`c`]strip_assume_tac Word64Rep_DataElement
\\ fs[ADDR_MAP_def])
THEN1
(full_simp_tac (srw_ss()) [v_inv_def,ADDR_APPLY_def,BlockRep_def]
\\ Cases_on `l = []` \\ fs[]
THEN1 (full_simp_tac (srw_ss()) [get_refs_def,ADDR_APPLY_def])
\\ full_simp_tac (srw_ss()) [v_inv_def,ADDR_APPLY_def,BlockRep_def]
\\ fs[gc_related_def] \\ res_tac
\\ full_simp_tac (srw_ss()) [] \\ NTAC 2 (POP_ASSUM MP_TAC)
\\ fs[LENGTH_ADDR_MAP] \\ strip_tac
\\ reverse strip_tac THEN1
(fs[get_refs_def,EVERY_MEM,MEM_FLAT,PULL_EXISTS,MEM_MAP]
\\ fs[v_size_def] \\ rpt strip_tac
\\ Q.MATCH_ASSUM_RENAME_TAC `MEM k (get_f a)`
\\ imp_res_tac MEM_IMP_v_size
\\ `v_size a < 1 + (n0 + (n + v1_size l))` by DECIDE_TAC
\\ `?l1 l2. l = l1 ++ a::l2` by metis_tac [MEM_SPLIT]
\\ full_simp_tac std_ss [] \\ imp_res_tac LIST_REL_SPLIT1
\\ fs[] \\ rw[] \\ fs[]
\\ res_tac \\ metis_tac [])
\\ fs[EVERY2_EVERY,LENGTH_ADDR_MAP,EVERY_MEM,FORALL_PROD]
\\ qpat_x_assum `LENGTH l = LENGTH xs` ASSUME_TAC
\\ fs[MEM_ZIP,LENGTH_ADDR_MAP,PULL_EXISTS]
\\ reverse strip_tac
THEN1 (fs [f_o_f_DEF,FLOOKUP_DEF])
\\ strip_tac \\ strip_tac
\\ Q.MATCH_ASSUM_RENAME_TAC `t < LENGTH xs` \\ res_tac
\\ `MEM (EL t l) l` by (fs[MEM_EL] \\ metis_tac [])
\\ `MEM (EL t xs) xs` by (fs[MEM_EL] \\ metis_tac [])
\\ `(!ptr u. (EL t xs = Pointer ptr u) ==> ptr IN FDOM g)` by metis_tac []
\\ `v_size (EL t l) < v_size (Block n0 n l)` by
(fs[v_size_def]
\\ imp_res_tac MEM_IMP_v_size \\ DECIDE_TAC)
\\ res_tac \\ fs[EL_ADDR_MAP]
\\ first_assum match_mp_tac \\ fs [])
THEN1
(full_simp_tac (srw_ss()) [v_inv_def,ADDR_APPLY_def,get_refs_def])
THEN1
(full_simp_tac (srw_ss()) [v_inv_def,ADDR_APPLY_def]
\\ sg `n IN FDOM (g f_o_f f)` \\ asm_simp_tac std_ss []
\\ full_simp_tac (srw_ss()) [f_o_f_DEF,get_refs_def])
QED
Triviality EVERY2_ADDR_MAP:
!zs l. EVERY2 P (ADDR_MAP g zs) l <=>
EVERY2 (\x y. P (ADDR_APPLY g x) y) zs l
Proof
Induct \\ Cases_on `l`
\\ full_simp_tac std_ss [LIST_REL_def,ADDR_MAP_def] \\ Cases
\\ full_simp_tac std_ss [LIST_REL_def,ADDR_MAP_def,ADDR_APPLY_def]
QED
Triviality bc_ref_inv_related:
gc_shared$gc_related g heap1 heap2 /\
bc_ref_inv conf n refs (f,tf,heap1,be) /\ (f ' n) IN FDOM g ==>
bc_ref_inv conf n refs (g f_o_f f,g f_o_f tf,heap2,be)
Proof
full_simp_tac std_ss [bc_ref_inv_def] \\ strip_tac \\ full_simp_tac std_ss []
\\ MP_TAC v_inv_related \\ asm_simp_tac std_ss []
\\ full_simp_tac (srw_ss()) [f_o_f_DEF,gc_related_def,RefBlock_def] \\ res_tac
\\ Cases_on `FLOOKUP f n` \\ full_simp_tac (srw_ss()) []
\\ Cases_on `lookup n refs` \\ full_simp_tac (srw_ss()) []
\\ full_simp_tac (srw_ss()) [FLOOKUP_DEF,f_o_f_DEF]
\\ Cases_on `x'` \\ full_simp_tac (srw_ss()) []
\\ TRY (fs[Bytes_def,LET_THM] >> res_tac >> simp[ADDR_MAP_def]
\\ rw [] \\ qexists_tac `ws` \\ fs [] >> NO_TAC)
\\ res_tac \\ full_simp_tac (srw_ss()) [LENGTH_ADDR_MAP,EVERY2_ADDR_MAP]
\\ rpt strip_tac \\ qpat_x_assum `EVERY2 qqq zs l` MP_TAC
\\ match_mp_tac EVERY2_IMP_EVERY2 \\ simp_tac std_ss [] \\ rpt strip_tac
\\ Cases_on `x'` \\ full_simp_tac (srw_ss()) [ADDR_APPLY_def]
\\ res_tac \\ fs [ADDR_APPLY_def]
QED
Triviality RTC_lemma:
!r n. RTC (ref_edge refs) r n ==>
(!m. RTC (ref_edge refs) r m ==> bc_ref_inv conf m refs (f,tf,heap,be)) /\
gc_shared$gc_related g heap heap2 /\
f ' r IN FDOM g ==> f ' n IN FDOM g
Proof
ho_match_mp_tac RTC_INDUCT \\ full_simp_tac std_ss [] \\ rpt strip_tac
\\ full_simp_tac std_ss []
\\ qpat_x_assum `bb ==> bbb` match_mp_tac \\ full_simp_tac std_ss []
\\ strip_tac THEN1
(rpt strip_tac \\ qpat_x_assum `!x.bb` match_mp_tac \\ metis_tac [RTC_CASES1])
\\ `RTC (ref_edge refs) r r' /\ RTC (ref_edge refs) r r` by metis_tac [RTC_CASES1]
\\ res_tac \\ qpat_x_assum `!x.bb` (K ALL_TAC)
\\ full_simp_tac std_ss [bc_ref_inv_def,RefBlock_def,RTC_REFL]
\\ Cases_on `FLOOKUP f r` \\ full_simp_tac (srw_ss()) []
\\ Cases_on `FLOOKUP f r'` \\ full_simp_tac (srw_ss()) []
\\ Cases_on `lookup r refs` \\ full_simp_tac (srw_ss()) []
\\ Cases_on `lookup r' refs` \\ full_simp_tac (srw_ss()) []
\\ Cases_on `x''` \\ full_simp_tac (srw_ss()) []
\\ Cases_on `x'''` \\ full_simp_tac (srw_ss()) []
\\ imp_res_tac v_inv_related
\\ full_simp_tac std_ss [ref_edge_def]
\\ full_simp_tac std_ss [gc_related_def,INJ_DEF,GSPECIFICATION]
\\ full_simp_tac (srw_ss()) [FLOOKUP_DEF] \\ srw_tac [] []
\\ res_tac \\ full_simp_tac std_ss [get_refs_def] \\ srw_tac [] []
\\ full_simp_tac std_ss [MEM_FLAT,MEM_MAP] \\ srw_tac [] []
\\ full_simp_tac std_ss [ref_edge_def,EVERY_MEM]
\\ full_simp_tac std_ss [PULL_FORALL,AND_IMP_INTRO]
\\ res_tac \\ CCONTR_TAC \\ full_simp_tac std_ss []
\\ srw_tac [] [] \\ POP_ASSUM MP_TAC \\ simp_tac std_ss []
\\ imp_res_tac MEM_EVERY2_IMP \\ fs []
\\ fs [] \\ metis_tac []
QED
Triviality reachable_refs_lemma:
gc_related g heap heap2 /\
EVERY2 (\v x. v_inv conf v (x,f,tf,heap)) stack roots /\
(!n. reachable_refs stack refs n ==> bc_ref_inv conf n refs (f,tf,heap,be)) /\
(!ptr u. MEM (Pointer ptr u) roots ==> ptr IN FDOM g) ==>
(!n. reachable_refs stack refs n ==> n IN FDOM f /\ (f ' n) IN FDOM g)
Proof
NTAC 3 strip_tac \\ full_simp_tac std_ss [reachable_refs_def,PULL_EXISTS]
\\ `?xs1 xs2. stack = xs1 ++ x::xs2` by metis_tac [MEM_SPLIT]
\\ full_simp_tac std_ss [] \\ imp_res_tac LIST_REL_SPLIT1
\\ full_simp_tac std_ss [LIST_REL_CONS1] \\ rveq
\\ full_simp_tac std_ss [MEM,MEM_APPEND,LIST_REL_CONS1]
\\ `EVERY (\n. f ' n IN FDOM g) (get_refs x)` by metis_tac [v_inv_related]
\\ full_simp_tac std_ss [EVERY_MEM] \\ res_tac \\ full_simp_tac std_ss []
\\ `n IN FDOM f` by (CCONTR_TAC
\\ full_simp_tac (srw_ss()) [bc_ref_inv_def,FLOOKUP_DEF])
\\ full_simp_tac std_ss []
\\ `bc_ref_inv conf r refs (f,tf,heap,be)` by metis_tac [RTC_REFL]
\\ `(!m. RTC (ref_edge refs) r m ==>
bc_ref_inv conf m refs (f,tf,heap,be))` by metis_tac [] \\ imp_res_tac RTC_lemma
QED
Triviality bc_stack_ref_inv_related:
gc_related g heap1 heap2 /\
bc_stack_ref_inv conf ts stack refs (roots,heap1,be) /\
(!ptr u. MEM (Pointer ptr u) roots ==> ptr IN FDOM g) ==>
bc_stack_ref_inv conf ts stack refs (ADDR_MAP (FAPPLY g) roots,heap2,be)
Proof
rpt strip_tac \\ full_simp_tac std_ss [bc_stack_ref_inv_def]
\\ qexists_tac `g f_o_f f`
\\ qexists_tac `g f_o_f tf`
\\ rpt strip_tac
THEN1 (full_simp_tac (srw_ss()) [INJ_DEF,gc_related_def,f_o_f_DEF])
THEN1 (full_simp_tac (srw_ss()) [f_o_f_DEF,SUBSET_DEF])
THEN1 (full_simp_tac (srw_ss()) [INJ_DEF,gc_related_def,f_o_f_DEF])
THEN1 (full_simp_tac (srw_ss()) [f_o_f_DEF,SUBSET_DEF])
THEN1 (full_simp_tac (srw_ss()) [f_o_f_DEF,SUBSET_DEF])
THEN1
(full_simp_tac std_ss [ONCE_REWRITE_RULE [CONJ_COMM] EVERY2_EVERY,
LENGTH_ADDR_MAP,EVERY_MEM,MEM_ZIP,PULL_EXISTS] \\ rpt strip_tac \\ res_tac
\\ full_simp_tac std_ss [MEM_ZIP,PULL_EXISTS]
\\ `MEM (EL n roots) roots` by (full_simp_tac std_ss [MEM_EL] \\ metis_tac [])
\\ `(!ptr u. (EL n roots = Pointer ptr u) ==> ptr IN FDOM g)` by metis_tac []
\\ imp_res_tac v_inv_related \\ imp_res_tac EL_ADDR_MAP
\\ full_simp_tac std_ss [])
\\ match_mp_tac bc_ref_inv_related \\ full_simp_tac std_ss []
\\ metis_tac [reachable_refs_lemma]
QED
Theorem data_up_to_APPEND[simp]:
data_up_to (heap_length xs) (xs ++ ys) <=> EVERY isDataElement xs
Proof
fs [data_up_to_def,heap_split_APPEND_if,heap_split_0]
QED
Definition all_reachable_from_roots_def:
all_reachable_from_roots roots heap <=>
!p xs l d.
heap_lookup p heap = SOME (DataElement xs l d) ==>
p IN reachable_addresses roots heap
End
val IN_reachable_addresses =
``x ∈ reachable_addresses roots heap``
|> SIMP_CONV std_ss [Once IN_DEF,reachable_addresses_def]
Theorem reachable_addresses_related:
k ∈ reachable_addresses roots heap /\ gc_related f heap heap2 /\
reachable_addresses roots heap SUBSET FDOM f ==>
f ' k ∈ reachable_addresses (ADDR_MAP ($' f) roots) heap2
Proof
fs [IN_reachable_addresses,PULL_EXISTS]
\\ Cases_on `gc_related f heap heap2` \\ fs [] \\ rw []
\\ qexists_tac `t`
\\ qexists_tac `f ' x`
\\ strip_tac
THEN1 (fs [MEM_SPLIT,ADDR_MAP_APPEND,ADDR_MAP_def] \\ metis_tac [])
\\ `x IN FDOM f` by
(fs [SUBSET_DEF] \\ pop_assum match_mp_tac
\\ fs [IN_reachable_addresses] \\ asm_exists_tac \\ fs [])
\\ pop_assum mp_tac
\\ pop_assum kall_tac
\\ pop_assum mp_tac
\\ qid_spec_tac `k`
\\ qid_spec_tac `x`
\\ ho_match_mp_tac RTC_INDUCT
\\ fs [] \\ rw []
\\ once_rewrite_tac [RTC_CASES1] \\ disj2_tac
\\ fs [gc_related_def]
\\ fs [gc_edge_def,PULL_EXISTS]
\\ first_x_assum drule \\ fs []
\\ rw [] \\ res_tac \\ fs []
\\ once_rewrite_tac [CONJ_COMM]
\\ asm_exists_tac \\ fs []
\\ fs [MEM_SPLIT,ADDR_MAP_APPEND,ADDR_MAP_def] \\ metis_tac []
QED
Theorem IMP_all_reachable_from_roots:
FDOM f = reachable_addresses roots heap /\
FRANGE f = { a | isSomeDataElement (heap_lookup a heap2) } /\
gc_related f heap heap2 ==>
all_reachable_from_roots (ADDR_MAP ($' f) roots) heap2
Proof
fs [all_reachable_from_roots_def,EXTENSION] \\ rw []
\\ `p IN FRANGE f` by fs [isSomeDataElement_def]
\\ pop_assum mp_tac
\\ simp_tac std_ss [IN_FRANGE]
\\ strip_tac \\ rveq
\\ match_mp_tac reachable_addresses_related
\\ res_tac \\ fs [] \\ fs [SUBSET_DEF]
QED
Theorem heap_lookup_expand_eq_SOME:
heap_lookup a (heap ++ heap_expand n) = SOME (DataElement ys l d) <=>
heap_lookup a heap = SOME (DataElement ys l d)
Proof
fs [heap_lookup_APPEND]
\\ Cases_on `heap_lookup a heap` \\ fs [] \\ rw []
\\ imp_res_tac gc_sharedTheory.heap_lookup_LESS \\ fs []
\\ rw [heap_lookup_def,heap_expand_def]
QED
Theorem isSomeDataElement_heap_lookup:
isSomeDataElement (heap_lookup a (heap ++ heap_expand n)) =
isSomeDataElement (heap_lookup a heap)
Proof
fs [isSomeDataElement_def,heap_lookup_expand_eq_SOME]
QED
Theorem gc_related_APPEND_heap_expand:
gc_related f heap (heap2 ++ heap_expand n) = gc_related f heap heap2
Proof
fs [gc_related_def,isSomeDataElement_heap_lookup,heap_lookup_expand_eq_SOME]
QED
Theorem full_gc_thm:
abs_ml_inv conf stack refs (roots,heap,be,a,sp,sp1,gens) limit ts /\
conf.gc_kind = Simple ==>
?roots2 heap2 a2.
(full_gc (roots,heap,limit) = (roots2,heap2,a2,T)) /\
abs_ml_inv conf stack refs
(roots2,heap2 ++ heap_expand (limit - a2),be,
a2,limit - a2,0,gens) limit ts /\
(heap_length heap2 = a2) /\
(heap_length (heap_filter (reachable_addresses roots heap) heap) =
heap_length heap2) /\
all_reachable_from_roots roots2 (heap2 ++ heap_expand (limit - a2)) /\
EVERY isDataElement heap2
Proof
simp_tac std_ss [abs_ml_inv_def,GSYM CONJ_ASSOC]
\\ rpt strip_tac \\ drule full_gc_related
\\ asm_simp_tac std_ss [] \\ strip_tac
\\ qpat_x_assum `heap_length heap2 = _` (assume_tac o GSYM)
\\ `heap_length heap2 = a2` by (imp_res_tac full_gc_LENGTH \\ full_simp_tac std_ss [] \\ metis_tac [])
\\ `unused_space_inv a2 (limit - a2) (heap2 ++ heap_expand (limit - a2))` by
(full_simp_tac std_ss [unused_space_inv_def] \\ rpt strip_tac
\\ full_simp_tac std_ss [heap_expand_def]
\\ imp_res_tac full_gc_IMP_isDataElement
\\ rveq \\ fs [heap_lookup_APPEND,heap_lookup_def,heap_length_APPEND]
\\ rw [heap_length_def,el_length_def])
\\ full_simp_tac std_ss [] \\ simp_tac std_ss [CONJ_ASSOC]
\\ reverse conj_tac THEN1
(drule (GEN_ALL IMP_all_reachable_from_roots)
\\ disch_then match_mp_tac \\ fs [gc_related_APPEND_heap_expand]
\\ fs [isSomeDataElement_heap_lookup])
\\ reverse conj_tac THEN1 metis_tac []
\\ reverse conj_tac THEN1
(match_mp_tac (GEN_ALL bc_stack_ref_inv_related) \\ full_simp_tac std_ss []
\\ qexists_tac `heap` \\ full_simp_tac std_ss []
\\ rw [] \\ fs [] \\ res_tac \\ fs []
\\ fs [reachable_addresses_def,IN_DEF]
\\ asm_exists_tac \\ fs [])
\\ conj_tac THEN1
(qpat_x_assum `full_gc (roots,heap,limit) = xxx` (ASSUME_TAC o GSYM)
\\ imp_res_tac full_gc_ok \\ NTAC 3 (POP_ASSUM (K ALL_TAC))
\\ full_simp_tac std_ss [] \\ metis_tac [])
\\ fs [gc_kind_inv_def] \\ CASE_TAC \\ fs []
QED
Definition make_gc_conf_def:
make_gc_conf limit =
<| limit := limit; isRef := \x. FST x = RefTag |>
: (tag # 'a) gen_gc$gen_gc_conf
End
Triviality gc_move_data_refs_split:
(gen_gc$gc_move cc s x = (x1,s1)) /\ (!t r. (cc.isRef (t,r) <=> t = RefTag))
/\ EVERY isDataElement s.h2 /\(EVERY (λx. ¬isRef x)) s.h2 /\ EVERY isRef s.r4 ==>
EVERY isDataElement s1.h2 /\
(EVERY (λx. ¬isRef x)) s1.h2 /\ EVERY isRef s1.r4
Proof
Cases_on `x` >> fs[gen_gcTheory.gc_move_def]
>> rpt strip_tac >> rveq >> fs[]
>> every_case_tac >> rveq >> fs[]
>> TRY pairarg_tac >> fs[]
>> qpat_x_assum `_ = s1` (assume_tac o GSYM) >> fs[isDataElement_def]
>> Cases_on `b` >> fs[isRef_def] >> metis_tac[]
QED
Triviality gc_move_list_data_refs_split:
!x x1 s s1.
(gen_gc$gc_move_list cc s x = (x1,s1)) /\ (!t r. (cc.isRef (t,r) <=> t = RefTag))
/\ EVERY isDataElement s.h2 /\(EVERY (λx. ¬isRef x)) s.h2 /\ EVERY isRef s.r4 ==>
EVERY isDataElement s1.h2 /\(EVERY (λx. ¬isRef x)) s1.h2 /\ EVERY isRef s1.r4
Proof
Induct >> fs[gen_gcTheory.gc_move_list_def]
>> rpt strip_tac >> rpt(pairarg_tac >> fs[])
>> drule gc_move_data_refs_split >> metis_tac[]
QED
Triviality gc_move_refs_data_refs_split:
!cc s s1.
(gen_gc$gc_move_refs cc s = s1) /\ (!t r. (cc.isRef (t,r) <=> t = RefTag))
/\ EVERY isDataElement (s.h1++s.h2) /\ (EVERY (λx. ¬isRef x)) (s.h1++s.h2) /\
EVERY isRef (s.r1 ++ s.r2 ++ s.r3 ++ s.r4) ==>
EVERY isDataElement (s1.h1++s1.h2) /\
(EVERY (λx. ¬isRef x)) (s1.h1++s1.h2) /\
EVERY isRef (s1.r1 ++ s1.r2 ++ s1.r3 ++ s1.r4)
Proof
recInduct (fetch "gen_gc" "gc_move_refs_ind")
>> rpt strip_tac
>> qpat_x_assum `gc_move_refs _ _ = _` mp_tac
>> simp[Once gen_gcTheory.gc_move_refs_def]
>> strip_tac >> every_case_tac
>> TRY pairarg_tac >> fs[]
>> qpat_x_assum `_ = s1` (assume_tac o GSYM) >> fs[]
>> drule gen_gcTheory.gc_move_list_IMP >> strip_tac >> fs[]
>> drule gc_move_list_data_refs_split >> fs[] >> strip_tac
>> first_x_assum drule >> fs[]
>> Cases_on `b` >> fs[isRef_def]
QED
Triviality gc_move_data_data_refs_split:
!cc s s1.
(gen_gc$gc_move_data cc s = s1) /\ (!t r. (cc.isRef (t,r) <=> t = RefTag))
/\ (EVERY (λx. ¬isRef x)) (s.h1++s.h2) /\
EVERY isDataElement (s.h1++s.h2) /\
EVERY isRef (s.r1 ++ s.r2 ++ s.r3 ++ s.r4) ==>
EVERY isDataElement (s1.h1++s1.h2) /\
(EVERY (λx. ¬isRef x)) (s1.h1++s1.h2) /\
EVERY isRef (s1.r1 ++ s1.r2 ++ s1.r3 ++ s1.r4)
Proof
recInduct (fetch "gen_gc" "gc_move_data_ind")
>> rpt strip_tac >> qpat_x_assum `gc_move_data _ _ = _` mp_tac
>> simp[Once gen_gcTheory.gc_move_data_def]
>> every_case_tac >> fs[] >> rpt strip_tac >> rveq >> fs[]
>> pairarg_tac >> fs[]
>> drule gen_gcTheory.gc_move_list_IMP >> strip_tac >> fs[]
>> drule gc_move_list_data_refs_split >> fs[] >> strip_tac
>> first_x_assum drule >> fs[]
>> Cases_on `b` >> fs[isRef_def]
>> Cases_on `state''.h2` >> fs[] >> rfs[isDataElement_def]
QED
Triviality gc_move_loop_data_refs_split:
!clock cc s s1.
(gen_gc$gc_move_loop cc s clock = s1) /\
(!t r. (cc.isRef (t,r) <=> t = RefTag)) /\
EVERY isDataElement (s.h1++s.h2) /\
(EVERY (λx. ¬isRef x)) (s.h1++s.h2) /\
EVERY isRef (s.r1 ++ s.r2 ++ s.r3 ++ s.r4) ==>
EVERY isDataElement (s1.h1++s1.h2) /\
(EVERY (λx. ¬isRef x)) (s1.h1++s1.h2) /\
EVERY isRef (s1.r1 ++ s1.r2 ++ s1.r3 ++ s1.r4)
Proof
Induct >> rpt strip_tac >> qpat_x_assum `gc_move_loop _ _ _ = _` mp_tac
>> PURE_ONCE_REWRITE_TAC [gen_gcTheory.gc_move_loop_def]
>> every_case_tac >> fs[]
>> rpt strip_tac >> TRY(rveq >> fs[] >> NO_TAC)
>> TRY(rename1 `s.r4 = h1::t1`)
>> `gc_move_refs cc (s with <|r4 := []; r2 := h1::t1|>) =
gc_move_refs cc (s with <|r4 := []; r2 := h1::t1|>)` by fs[]
>> `gc_move_data cc s =
gc_move_data cc s` by fs[]
>> drule gc_move_refs_data_refs_split >> drule gc_move_data_data_refs_split
>> fs[] >> rpt strip_tac
>> qpat_x_assum `_ = s1` (assume_tac o GSYM) >> fs[]
>> rpt strip_tac >> fs[]
QED
Triviality gen_gc_data_refs_split:
!cc roots heap.
(gen_gc cc (roots,heap) = (roots1,s)) /\
(!t r. (cc.isRef (t,r) <=> t = RefTag)) ==>
(EVERY (λx. ¬isRef x)) (s.h1 ++ s.h2) /\
EVERY isDataElement (s.h1 ++ s.h2) /\
EVERY isRef (s.r1 ++ s.r2 ++ s.r3 ++ s.r4)
Proof
rpt strip_tac >> fs[gen_gcTheory.gen_gc_def]
>> rpt (pairarg_tac >> fs[])
>> drule gc_move_list_data_refs_split >> fs[empty_state_def]
>> strip_tac
>> drule gen_gcTheory.gc_move_list_IMP
>> fs[] >> disch_then (assume_tac o GSYM) >> fs[]
>> drule gc_move_loop_data_refs_split
>> fs []
QED
Theorem heap_expand_not_isRef:
EVERY (λx. ¬isRef x) (heap_expand n)
Proof
Induct_on `n` >> fs[isRef_def,heap_expand_def]
QED
Definition reset_gens_def:
reset_gens conf a =
case conf.gc_kind of
| Generational sizes => GenState 0 (MAP (K a) sizes)
| _ => GenState 0 []
End
Theorem gen_state_ok_reset:
heap_ok (h ++ heap_expand n ++ r) l ==>
gen_state_ok (heap_length h) (n + heap_length h)
(h ++ heap_expand n ++ r) (reset_gens conf (heap_length h))
Proof
strip_tac
\\ fs [reset_gens_def] \\ TOP_CASE_TAC \\ fs [gen_state_ok_def,reset_gens_def]
\\ fs [EVERY_MAP] \\ disj2_tac
\\ fs [gen_start_ok_def]
\\ rewrite_tac [GSYM APPEND_ASSOC]
\\ once_rewrite_tac [heap_split_APPEND_if]
\\ fs [heap_split_0]
\\ fs [heap_ok_def]
\\ rw [] \\ res_tac
\\ rpt (qpat_x_assum `!x._` kall_tac)
\\ fs [isSomeDataElement_def]
\\ rfs [heap_lookup_APPEND,heap_length_APPEND,heap_length_heap_expand]
\\ every_case_tac
\\ imp_res_tac heap_lookup_MEM
\\ pop_assum mp_tac \\ fs [heap_expand_def]
QED
Theorem gen_gc_thm:
abs_ml_inv conf stack refs (roots,heap,be,a,sp,sp1,gens) limit ts ==>
?roots2 state2.
(gen_gc (make_gc_conf limit) (roots,heap) = (roots2,state2)) /\
abs_ml_inv conf stack refs
(roots2,state2.h1 ++ heap_expand state2.n ++ state2.r1,be,
state2.a,state2.n,0,reset_gens conf state2.a) limit ts /\ state2.ok /\
(heap_length (state2.h1 ⧺ state2.r1) =
heap_length (heap_filter (reachable_addresses roots heap) heap)) /\
EVERY isDataElement state2.h1 /\
EVERY isDataElement state2.r1 /\
all_reachable_from_roots roots2
(state2.h1 ++ heap_expand state2.n ++ state2.r1)
Proof
simp_tac std_ss [abs_ml_inv_def,GSYM CONJ_ASSOC,make_gc_conf_def]
\\ rpt strip_tac \\ qmatch_goalsub_abbrev_tac `gen_gc cc`
\\ `heap_ok heap cc.limit` by fs [Abbr `cc`]
\\ drule gen_gcTheory.gen_gc_related
\\ disch_then drule \\ strip_tac \\ fs []
\\ drule gen_gcTheory.gen_gc_ok
\\ disch_then drule \\ strip_tac \\ fs [] \\ rveq \\ fs []
\\ `cc.limit = limit` by fs [Abbr`cc`] \\ fs []
\\ reverse (rpt conj_tac)
THEN1 (match_mp_tac IMP_all_reachable_from_roots \\ fs [])
THEN1
(match_mp_tac (GEN_ALL bc_stack_ref_inv_related) \\ full_simp_tac std_ss []
\\ qexists_tac `heap` \\ full_simp_tac std_ss []
\\ rw [] \\ fs [] \\ res_tac \\ fs []
\\ fs [reachable_addresses_def,IN_DEF] \\ asm_exists_tac \\ fs [])
THEN1
(fs [unused_space_inv_def] \\ fs [heap_expand_def]
\\ rewrite_tac [APPEND,GSYM APPEND_ASSOC]
\\ fs [heap_lookup_APPEND] \\ fs [heap_lookup_def]
\\ drule(GEN_ALL gen_gc_data_refs_split) \\ fs[]
\\ fs[] \\ impl_tac THEN1 (unabbrev_all_tac >> fs[]) \\ fs[]