-
Notifications
You must be signed in to change notification settings - Fork 85
/
repl_typesScript.sml
1190 lines (1147 loc) · 40 KB
/
repl_typesScript.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
(*
Proofs about how the REPL uses types and the type inferencer
*)
open preamble
open semanticsPropsTheory evaluateTheory semanticPrimitivesTheory
open inferTheory inferSoundTheory typeSoundTheory semanticsTheory
envRelTheory primSemEnvTheory typeSoundInvariantsTheory
namespacePropsTheory inferPropsTheory repl_check_and_tweakTheory
open ml_progTheory evaluate_skipTheory evaluate_initTheory
val _ = new_theory "repl_types";
Datatype:
simple_type = Bool | Str | Exn
End
Definition to_type_def:
to_type Bool = Infer_Tapp [] Tbool_num ∧
to_type Str = Infer_Tapp [] Tstring_num ∧
to_type Exn = Infer_Tapp [] Texn_num
End
Definition check_ref_types_def:
check_ref_types types (env :semanticPrimitives$v sem_env) (name,ty,loc) ⇔
nsLookup types.inf_v name = SOME (0,Infer_Tapp [to_type ty] Tref_num) ∧
nsLookup env.v name = SOME (Loc T loc)
End
Definition roll_back_def:
roll_back (old_ienv:inf_env, old_next_id:num)
(new_ienv:inf_env, new_next_id:num) =
(old_ienv, new_next_id)
End
Theorem FST_roll_back[simp]:
FST (roll_back x y) = FST x
Proof
Cases_on`x` \\ Cases_on`y` \\ rw[roll_back_def]
QED
Theorem SND_roll_back[simp]:
SND (roll_back x y) = SND y
Proof
Cases_on`x` \\ Cases_on`y` \\ rw[roll_back_def]
QED
Inductive repl_types:
[repl_types_init:]
(∀ffi rs decs types (s:'ffi semanticPrimitives$state) env ck b.
infertype_prog_inc (init_config, start_type_id) decs = Success types ∧
evaluate$evaluate_decs (init_state ffi with clock := ck) init_env decs = (s,Rval env) ∧
EVERY (check_ref_types (FST types) (extend_dec_env env init_env)) rs ⇒
repl_types b (ffi,rs) (types,s,extend_dec_env env init_env))
[repl_types_skip:]
(∀ffi rs types junk ck t e (s:'ffi semanticPrimitives$state) env.
repl_types T (ffi,rs) (types,s,env) ⇒
repl_types T (ffi,rs) (types,s with <| refs := s.refs ++ junk ;
clock := s.clock - ck ;
next_type_stamp := s.next_type_stamp + t ;
next_exn_stamp := s.next_exn_stamp + e |>,env))
[repl_types_eval:]
(∀ffi rs decs types new_types (s:'ffi semanticPrimitives$state) env new_env new_s b.
repl_types b (ffi,rs) (types,s,env) ∧
infertype_prog_inc types decs = Success new_types ∧
evaluate$evaluate_decs s env decs = (new_s,Rval new_env) ⇒
repl_types b (ffi,rs) (new_types,new_s,extend_dec_env new_env env))
[repl_types_exn:]
(∀ffi rs decs types new_types (s:'ffi semanticPrimitives$state) env e new_s b.
repl_types b (ffi,rs) (types,s,env) ∧
infertype_prog_inc types decs = Success new_types ∧
evaluate$evaluate_decs s env decs = (new_s,Rerr (Rraise e)) ⇒
repl_types b (ffi,rs) (roll_back types new_types,new_s,env))
[repl_types_exn_assign:]
(∀ffi rs decs types new_types (s:'ffi semanticPrimitives$state) env e
new_s name loc new_store b.
repl_types b (ffi,rs) (types,s,env) ∧
infertype_prog_inc types decs = Success new_types ∧
evaluate$evaluate_decs s env decs = (new_s,Rerr (Rraise e)) ∧
MEM (name,Exn,loc) rs ∧
store_assign loc (Refv e) new_s.refs = SOME new_store ⇒
repl_types b (ffi,rs) (roll_back types new_types,new_s with refs := new_store,env))
[repl_types_str_assign:]
(∀ffi rs types (s:'ffi semanticPrimitives$state) env t name loc new_store b.
repl_types b (ffi,rs) (types,s,env) ∧
MEM (name,Str,loc) rs ∧
store_assign loc (Refv (Litv (StrLit t))) s.refs = SOME new_store ⇒
repl_types b (ffi,rs) (types,s with refs := new_store,env))
End
(* Mirror definitions for repl_types using the type system directly *)
Definition to_type_TS_def:
to_type_TS Bool = Tapp [] Tbool_num ∧
to_type_TS Str = Tapp [] Tstring_num ∧
to_type_TS Exn = Tapp [] Texn_num
End
Definition check_ref_types_TS_def:
check_ref_types_TS types (env :semanticPrimitives$v sem_env) (name,ty,loc) ⇔
nsLookup types.v name = SOME (0,Tapp [to_type_TS ty] Tref_num) ∧
nsLookup env.v name = SOME (Loc T loc)
End
Inductive repl_types_TS:
[repl_types_TS_init:]
(∀ffi rs decs tids tenv (s:'ffi semanticPrimitives$state) env ck.
type_ds T prim_tenv decs tids tenv ∧
DISJOINT tids {Tlist_num; Tbool_num; Texn_num} ∧
evaluate$evaluate_decs (init_state ffi with clock := ck) init_env decs = (s,Rval env) ∧
EVERY (check_ref_types_TS (extend_dec_tenv tenv prim_tenv) (extend_dec_env env init_env)) rs ⇒
repl_types_TS (ffi,rs) (tids,extend_dec_tenv tenv prim_tenv,s,extend_dec_env env init_env))
[repl_types_TS_eval:]
(∀ffi rs decs tids tenv (s:'ffi semanticPrimitives$state) env
new_tids new_tenv new_env new_s.
repl_types_TS (ffi,rs) (tids,tenv,s,env) ∧
type_ds T tenv decs new_tids new_tenv ∧
DISJOINT tids new_tids ∧
evaluate$evaluate_decs s env decs = (new_s,Rval new_env) ⇒
repl_types_TS (ffi,rs) (tids ∪ new_tids,extend_dec_tenv new_tenv tenv,new_s,extend_dec_env new_env env))
[repl_types_TS_exn:]
(∀ffi rs decs tids tenv (s:'ffi semanticPrimitives$state) env
new_tids new_tenv new_s e.
repl_types_TS (ffi,rs) (tids,tenv,s,env) ∧
type_ds T tenv decs new_tids new_tenv ∧
DISJOINT tids new_tids ∧
evaluate$evaluate_decs s env decs = (new_s,Rerr (Rraise e)) ⇒
repl_types_TS (ffi,rs) (tids ∪ new_tids,tenv,new_s,env))
[repl_types_TS_exn_assign:]
(∀ffi rs decs tids tenv (s:'ffi semanticPrimitives$state) env
new_tids new_tenv new_s e name loc new_store.
repl_types_TS (ffi,rs) (tids,tenv,s,env) ∧
type_ds T tenv decs new_tids new_tenv ∧
DISJOINT tids new_tids ∧
evaluate$evaluate_decs s env decs = (new_s,Rerr (Rraise e)) ∧
MEM (name,Exn,loc) rs ∧
store_assign loc (Refv e) new_s.refs = SOME new_store ⇒
repl_types_TS (ffi,rs) (tids ∪ new_tids,tenv,new_s with refs := new_store,env))
[repl_types_TS_str_assign:]
(∀ffi rs tids tenv (s:'ffi semanticPrimitives$state) env t name loc new_store.
repl_types_TS (ffi,rs) (tids,tenv,s,env) ∧
MEM (name,Str,loc) rs ∧
store_assign loc (Refv (Litv (StrLit t))) s.refs = SOME new_store ⇒
repl_types_TS (ffi,rs) (tids,tenv,s with refs := new_store,env))
End
Theorem init_config_tenv_to_ienv:
init_config = tenv_to_ienv prim_tenv
Proof
rw[init_config_def, tenv_to_ienv_def]
\\ EVAL_TAC
QED
Theorem ienv_to_tenv_init_config:
ienv_to_tenv init_config = prim_tenv
Proof
EVAL_TAC
QED
Theorem tenv_ok_prim_tenv[simp]:
tenv_ok prim_tenv
Proof
EVAL_TAC \\ rw[]
\\ Cases_on`id`
\\ fs[namespaceTheory.nsLookup_def]
\\ pop_assum mp_tac
\\ rw[] \\ rw[]
\\ EVAL_TAC
QED
Theorem env_rel_init_config:
env_rel prim_tenv init_config
Proof
simp[init_config_tenv_to_ienv]
\\ irule env_rel_tenv_to_ienv
\\ simp[]
QED
Theorem inf_set_tids_ienv_init_config[simp]:
inf_set_tids_ienv (count start_type_id) init_config
Proof
EVAL_TAC
\\ rpt conj_tac
\\ Cases \\ simp[namespaceTheory.nsLookup_def]
\\ rw[] \\ simp[]
\\ EVAL_TAC \\ simp[]
QED
Theorem ienv_ok_init_config:
ienv_ok {} init_config
Proof
EVAL_TAC>>
CONJ_TAC>- (
Induct>>
simp[namespaceTheory.nsLookup_def])>>
CONJ_TAC>- (
Induct>>
simp[namespaceTheory.nsLookup_def]>>
rw[]>>EVAL_TAC)>>
Induct>>
simp[namespaceTheory.nsLookup_def]>>
rw[]>>EVAL_TAC
QED
Theorem repl_types_ienv_ok:
∀b (ffi:'ffi ffi_state) rs types s env.
repl_types b (ffi,rs) (types,s,env) ⇒
ienv_ok {} (FST types)
Proof
Induct_on`repl_types`
\\ rw[infertype_prog_inc_def, CaseEq"exc"]
\\ fs[PULL_EXISTS]
>- (
every_case_tac
\\ fs[]
\\ drule (CONJUNCT2 infer_d_check)
\\ rw[]
\\ match_mp_tac ienv_ok_extend_dec_ienv
\\ fs[ienv_ok_init_config])
>- (
rename1`_ tys decs = Success _`
\\ Cases_on`tys` \\ fs[infertype_prog_inc_def]
\\ every_case_tac \\ fs[]
\\ drule (CONJUNCT2 infer_d_check)
\\ rw[]
\\ match_mp_tac ienv_ok_extend_dec_ienv
\\ metis_tac[])
QED
Theorem repl_types_next_id:
∀b (ffi:'ffi ffi_state) rs types s env.
repl_types b (ffi,rs) (types,s,env) ⇒
start_type_id ≤ SND types
Proof
Induct_on`repl_types`
\\ rw[infertype_prog_inc_def, CaseEq"exc"]
\\ fs[PULL_EXISTS]
>- (
every_case_tac
\\ fs[]
\\ drule (CONJUNCT2 infer_d_next_id_mono)
\\ rw[init_infer_state_def])
\\ (
rename1`_ tys decs = Success _`
\\ Cases_on`tys` \\ fs[infertype_prog_inc_def]
\\ fs[CaseEqs["infer$exc","prod"]] \\ fs[]
\\ drule (CONJUNCT2 infer_d_next_id_mono)
\\ simp[init_infer_state_def]
\\ rw[])
QED
Theorem convert_t_to_type:
convert_t(to_type t) = to_type_TS t
Proof
Cases_on`t`>>EVAL_TAC
QED
Theorem check_ref_types_check_ref_types_TS:
check_ref_types ienv env x ⇒
check_ref_types_TS (ienv_to_tenv ienv) env x
Proof
PairCases_on`x`>>
rw[check_ref_types_TS_def,check_ref_types_def]>>
fs[ienv_to_tenv_def,nsLookup_nsMap]>>
EVAL_TAC>>
fs[convert_t_to_type]
QED
Definition ref_lookup_ok_def:
ref_lookup_ok refs (name:(string,string) id,ty,loc) =
∃v:semanticPrimitives$v.
store_lookup loc refs = SOME (Refv v) ∧
(ty = Bool ⇒ v = Boolv T ∨ v = Boolv F) ∧
(ty = Str ⇒ ∃t. v = Litv (StrLit t)) ∧
(ty = Exn ⇒ ∃s ls. v = Conv (SOME (ExnStamp s)) ls)
End
Theorem type_d_tids_disjoint:
(!b tenv d tids tenv'.
type_d b tenv d tids tenv' ⇒
DISJOINT tids (set (Tlist_num::Tbool_num::prim_type_nums))) ∧
(!b tenv ds tids tenv'.
type_ds b tenv ds tids tenv' ⇒
DISJOINT tids (set (Tlist_num::Tbool_num::prim_type_nums)))
Proof
ho_match_mp_tac typeSystemTheory.type_d_ind \\ rw[]
QED
Theorem ref_lookup_ok_store_assign:
EVERY (ref_lookup_ok store) rs ∧
MEM (n,Str,loc) rs ∧
store_assign loc (Refv (Litv (StrLit t))) store = SOME new_store ⇒
EVERY (ref_lookup_ok new_store) rs
Proof
simp[store_assign_def]>>
simp[EVERY_MEM,FORALL_PROD] >>
rw[]>>fs[ref_lookup_ok_def]>>
first_assum drule>>
pop_assum mp_tac>>
first_x_assum drule>>
rw[]>>
fs[store_lookup_def,EL_LUPDATE]>>
IF_CASES_TAC
>- (
rw[]>>fs[Boolv_def] >>
CCONTR_TAC >> gs[]
)>>
metis_tac[]
QED
Theorem type_v_invert_strlit:
∀n ct tenv l ty.
l = Litv (StrLit t) ∧
type_v n ct tenv l ty ⇒
ty = Tstring
Proof
Induct_on`type_v` \\ rw[]
QED
Theorem ref_lookup_ok_store_assign_exn:
EVERY (ref_lookup_ok store) rs ∧
MEM (n,Exn,loc) rs ∧
type_v 0 ctMap tenvS e (Tapp [] Texn_num) ∧ ctMap_ok ctMap ∧
store_assign loc (Refv e) store = SOME new_store ⇒
EVERY (ref_lookup_ok new_store) rs
Proof
simp[store_assign_def]>>
simp[EVERY_MEM,FORALL_PROD] >>
rw[]>>fs[ref_lookup_ok_def]>>
first_assum drule>>
pop_assum mp_tac>>
first_x_assum drule>>
rw[]>>
fs[store_lookup_def,EL_LUPDATE]>>
reverse IF_CASES_TAC >- metis_tac[]
\\ rw[]>>fs[Boolv_def] >> rw[]
\\ fs[Once type_v_cases]
\\ TRY(qpat_x_assum`Texn_num = _`mp_tac \\ EVAL_TAC)
\\ TRY ( drule_then drule typeSysPropsTheory.type_funs_Tfn \\ rw[] )
\\ fs[ctMap_ok_def]
\\ Cases_on`stamp` \\ fs[]
\\ res_tac
\\ pop_assum mp_tac
\\ EVAL_TAC
QED
Theorem type_v_invert_exn:
∀n ct tenv l ty.
l = Conv (SOME (ExnStamp s)) ls ∧
ctMap_ok ct ∧
type_v n ct tenv l ty ⇒
ty = Tapp [] Texn_num
Proof
Induct_on`type_v` \\ rw[]
\\ fs[ctMap_ok_def]
\\ last_x_assum drule \\ rw[] \\ gs[]
QED
Theorem type_s_store_assign_StrLit:
type_s ctMap st tenvS ∧
EVERY (ref_lookup_ok st) rs ∧
MEM (n,Str,loc) rs ∧
store_assign loc (Refv (Litv (StrLit t))) st = SOME new_st ⇒
type_s ctMap new_st tenvS
Proof
simp[store_assign_def]
\\ strip_tac
\\ fs[EVERY_MEM]
\\ first_x_assum drule
\\ simp[ref_lookup_ok_def]
\\ strip_tac
\\ fs[type_s_def,store_assign_def,type_sv_def]
\\ rw[]
\\ fs[store_lookup_def]
\\ fs[EL_LUPDATE]
\\ pop_assum mp_tac \\ rw[]
>- (
`type_sv ctMap tenvS (EL l st) st'` by metis_tac[]
\\ qpat_x_assum`EL l st = _` SUBST_ALL_TAC
\\ Cases_on`st'`\\fs[type_sv_def]
\\ metis_tac[type_v_invert_strlit,type_v_cases] )
\\ metis_tac[]
QED
Theorem type_s_store_assign_exn:
type_s ctMap st tenvS ∧
EVERY (ref_lookup_ok st) rs ∧
MEM (n,Exn,loc) rs ∧
ctMap_ok ctMap ∧
type_v 0 ctMap tenvS e (Tapp [] Texn_num) ∧
store_assign loc (Refv e) st = SOME new_st ⇒
type_s ctMap new_st tenvS
Proof
simp[store_assign_def]
\\ strip_tac
\\ fs[EVERY_MEM]
\\ first_x_assum drule
\\ simp[ref_lookup_ok_def]
\\ strip_tac
\\ fs[type_s_def,store_assign_def,type_sv_def]
\\ rw[] \\ fs[store_lookup_def]
\\ fs[EL_LUPDATE]
\\ pop_assum mp_tac \\ rw[]
>- (
`type_sv ctMap tenvS (EL l st) st'` by metis_tac[]
\\ qpat_x_assum`EL l st = _` SUBST_ALL_TAC
\\ Cases_on`st'`\\fs[type_sv_def]
\\ imp_res_tac type_v_invert_exn \\ fs[])
\\ metis_tac[]
QED
val ref_ok_tac =
fs[EVERY_MEM, FORALL_PROD] \\ rw[]
\\ first_x_assum drule
\\ rw[ref_lookup_ok_def]
\\ fs[type_sound_invariant_def]
\\ fs[type_s_def]
\\ qmatch_asmsub_rename_tac`store_lookup l s.refs`
\\ last_x_assum(qspec_then`l`mp_tac) \\ simp[]
\\ strip_tac \\ gs[]
\\ first_x_assum(qspec_then`l`mp_tac) \\ simp[]
\\ fs[store_type_extension_def]
\\ simp[FLOOKUP_FUNION]
\\ first_x_assum(qspec_then`l`mp_tac) \\ simp[]
\\ rpt strip_tac \\ gs[]
\\ qhdtm_x_assum`type_sv`mp_tac
\\ qhdtm_x_assum`type_sv`mp_tac
\\ Cases_on`st` \\ simp[type_sv_def]
\\ qmatch_asmsub_rename_tac`store_lookup l new_s.refs = SOME sv`
\\ Cases_on`sv` \\ simp[type_sv_def]
\\ ntac 4 strip_tac
>- (
first_x_assum drule \\ rveq
\\ reverse(Cases_on`∃b. v = Boolv b`) >- gvs[] \\ fs[]
\\ rveq
\\ ntac 2 (pop_assum mp_tac)
\\ `Boolv b = Conv
(SOME (TypeStamp (if b then "True" else "False")
bool_type_num)) []` by rw[Boolv_def]
\\ pop_assum SUBST_ALL_TAC
\\ simp[Once type_v_cases]
\\ strip_tac \\ rveq
\\ simp[Once type_v_cases]
\\ fs[good_ctMap_def, ctMap_has_bools_def]
\\ `ti = Tbool_num` by ( Cases_on`b` \\ fs[] )
\\ simp[Once type_v_cases]
\\ strip_tac \\ TRY (qpat_x_assum`Tbool_num = _`mp_tac \\ EVAL_TAC \\ NO_TAC)
\\ TRY (
drule_then drule typeSysPropsTheory.type_funs_Tfn
\\ EVAL_TAC \\ rw[] \\ NO_TAC)
\\ rveq
\\ qhdtm_x_assum`ctMap_ok`mp_tac
\\ simp[ctMap_ok_def]
\\ rpt strip_tac
\\ reverse(Cases_on`stamp`)
>- ( res_tac \\ pop_assum mp_tac \\ EVAL_TAC )
\\ qmatch_asmsub_rename_tac`TypeStamp cn n`
\\ `same_type (TypeStamp "True" bool_type_num) (TypeStamp cn n)`
by ( first_x_assum irule \\ simp[] )
\\ pop_assum mp_tac
\\ simp[same_type_def]
\\ strip_tac \\ rveq
\\ `cn = "True" ∨ cn = "False"` by metis_tac[NOT_SOME_NONE]
\\ rveq
\\ rpt(qhdtm_x_assum`FLOOKUP`mp_tac)
\\ simp_tac(srw_ss())[]
\\ rpt strip_tac \\ rveq
\\ qhdtm_x_assum`LIST_REL`mp_tac
\\ EVAL_TAC
\\ simp[])
>- (
strip_tac
\\ fs[] \\ rveq
\\ imp_res_tac type_v_invert_strlit \\ fs[]
\\ qhdtm_x_assum`type_v`mp_tac
\\ simp[Once type_v_cases]
\\ strip_tac \\ TRY (qpat_x_assum`Tstring_num = _`mp_tac \\ EVAL_TAC \\ NO_TAC)
\\ TRY (
drule_then drule typeSysPropsTheory.type_funs_Tfn
\\ EVAL_TAC \\ rw[] \\ NO_TAC)
\\ rw[]
\\ fs[good_ctMap_def]
\\ qhdtm_x_assum`ctMap_ok`mp_tac
\\ simp[ctMap_ok_def]
\\ spose_not_then strip_assume_tac
\\ reverse(Cases_on`stamp`)
>- ( res_tac \\ pop_assum mp_tac \\ EVAL_TAC )
\\ res_tac
\\ ntac 2 (pop_assum mp_tac)
\\ EVAL_TAC)
\\ (
strip_tac
\\ fs[] \\ rveq
\\ imp_res_tac type_v_invert_exn \\ gs[good_ctMap_def]
\\ qhdtm_x_assum`type_v`mp_tac
\\ simp[Once type_v_cases]
\\ strip_tac\\ TRY (qpat_x_assum`Texn_num = _`mp_tac \\ EVAL_TAC \\ NO_TAC)
\\ TRY (
drule_then drule typeSysPropsTheory.type_funs_Tfn
\\ EVAL_TAC \\ rw[] \\ NO_TAC)
\\ rw[]
\\ fs[good_ctMap_def]
\\ qhdtm_x_assum`ctMap_ok`mp_tac
\\ simp[ctMap_ok_def]
\\ spose_not_then strip_assume_tac
\\ reverse(Cases_on`stamp`)
>- metis_tac[]
\\ res_tac
\\ ntac 2 (pop_assum mp_tac)
\\ EVAL_TAC);
Theorem repl_types_TS_thm:
∀(ffi:'ffi ffi_state) rs tids tenv s env.
repl_types_TS (ffi,rs) (tids,tenv,s,env) ⇒
(* Probably keep more information about ctMap tenvS *)
(∃ctMap tenvS.
FRANGE ((SND o SND) o_f ctMap) ⊆ tids ∪ prim_type_ids ∧
type_sound_invariant s env ctMap tenvS {} tenv) ∧
EVERY (ref_lookup_ok s.refs) rs ∧
∀decs new_tids new_tenv new_s res.
type_ds T tenv decs new_tids new_tenv ∧
DISJOINT tids new_tids ∧
evaluate_decs s env decs = (new_s,res) ⇒
res ≠ Rerr (Rabort Rtype_error)
Proof
Induct_on`repl_types_TS`
\\ CONJ_TAC
>- (
rpt gen_tac \\ strip_tac \\ simp[]
\\ drule_then drule decs_type_sound \\ simp[]
\\ resolve_then Any (qspecl_then[`tids`,`ffi`]mp_tac)
(GSYM init_state_env_thm)
prim_type_sound_invariants
\\ impl_tac >- fs[]
\\ strip_tac \\ strip_tac
\\ ‘type_sound_invariant (init_state ffi with clock := ck)
init_env ctMap FEMPTY tids prim_tenv’ by
fs [type_sound_invariant_def,consistent_ctMap_def,SF SFY_ss]
\\ first_x_assum drule \\ strip_tac
\\ conj_tac >- (
first_assum $ irule_at Any \\ simp[]
\\ fs[SUBSET_DEF]
\\ metis_tac[] )
\\ conj_tac
>- (
fs[EVERY_MEM, FORALL_PROD] \\ rw[]
\\ first_x_assum drule
\\ rw[check_ref_types_TS_def, ref_lookup_ok_def]
\\ fs[type_sound_invariant_def]
\\ fs[type_s_def]
\\ qmatch_goalsub_rename_tac`store_lookup l s.refs`
\\ first_x_assum(qspec_then`l`mp_tac)
\\ fs[type_all_env_def]
\\ drule_then drule nsAll2_nsLookup1
\\ fs[typeSystemTheory.extend_dec_tenv_def]
\\ simp[Once type_v_cases]
\\ simp[EVAL``Tref_num = Tarray_num``]
\\ strip_tac \\ strip_tac
\\ first_x_assum drule
\\ Cases_on`v` \\ simp[type_sv_def]
\\ fs[good_ctMap_def, ctMap_has_bools_def]
\\ rw[] \\ fs[to_type_TS_def]
\\ pop_assum mp_tac
\\ simp[Once type_v_cases]
\\ rw[] \\ TRY (ntac 4 (pop_assum mp_tac) \\ EVAL_TAC \\ NO_TAC)
\\ TRY (drule_then drule typeSysPropsTheory.type_funs_Tfn \\ rw[])
>- (
qhdtm_x_assum`ctMap_ok`mp_tac
\\ simp[ctMap_ok_def]
\\ rpt strip_tac
\\ reverse(Cases_on`stamp`)
>- ( res_tac \\ pop_assum mp_tac \\ EVAL_TAC )
\\ qmatch_asmsub_rename_tac`TypeStamp cn n`
\\ `same_type (TypeStamp "True" bool_type_num) (TypeStamp cn n)`
by ( first_x_assum irule \\ simp[] )
\\ pop_assum mp_tac
\\ simp[same_type_def]
\\ strip_tac \\ rw[]
\\ `cn = "True" ∨ cn = "False"` by metis_tac[NOT_SOME_NONE]
\\ rveq
\\ EVAL_TAC
\\ qhdtm_x_assum`FLOOKUP`mp_tac
\\ qhdtm_x_assum`FLOOKUP`mp_tac
\\ qhdtm_x_assum`FLOOKUP`mp_tac
\\ simp[]
\\ rpt strip_tac
\\ rveq
\\ qhdtm_x_assum`LIST_REL`mp_tac
\\ simp[])
>- (
qhdtm_x_assum`ctMap_ok`mp_tac
\\ simp[ctMap_ok_def]
\\ spose_not_then strip_assume_tac
\\ reverse(Cases_on`stamp`)
>- ( res_tac \\ pop_assum mp_tac \\ EVAL_TAC )
\\ res_tac
\\ ntac 2 (pop_assum mp_tac)
\\ EVAL_TAC)
\\
qhdtm_x_assum`ctMap_ok`mp_tac
\\ simp[ctMap_ok_def]
\\ rpt strip_tac
\\ Cases_on`stamp`
>- (
res_tac \\
ntac 2 (pop_assum mp_tac) \\ EVAL_TAC)
\\ metis_tac[])
\\ rpt gen_tac \\ strip_tac
\\ CCONTR_TAC \\ fs[]
\\ drule_then drule decs_type_sound
\\ simp[]
\\ fs[type_sound_invariant_def, consistent_ctMap_def]
\\ first_assum $ irule_at Any \\ simp[]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC )
\\ CONJ_TAC >- (
rpt gen_tac \\ strip_tac \\ simp[]
\\ drule_then drule decs_type_sound \\ simp[]
\\ fs[]
\\ disch_then (qspecl_then[`ctMap`,`tenvS`] mp_tac)
\\ impl_tac >- (
fs[type_sound_invariant_def,consistent_ctMap_def]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC )
\\ strip_tac
\\ conj_tac >- (
first_assum $ irule_at Any
\\ fs[SUBSET_DEF]
\\ metis_tac[] )
\\ conj_tac>- ref_ok_tac
\\ rpt gen_tac \\ strip_tac
\\ CCONTR_TAC \\ fs[]
\\ drule_then drule decs_type_sound
\\ simp[]
\\ fs[type_sound_invariant_def, consistent_ctMap_def]
\\ first_assum $ irule_at Any \\ simp[]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC)
\\ CONJ_TAC >- (
rpt gen_tac \\ strip_tac \\ simp[]
\\ drule_then drule decs_type_sound \\ simp[]
\\ fs[]
\\ disch_then (qspecl_then[`ctMap`,`tenvS`] mp_tac)
\\ impl_tac >- (
fs[type_sound_invariant_def,consistent_ctMap_def]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC )
\\ strip_tac
\\ conj_tac >- (
first_assum $ irule_at Any
\\ fs[SUBSET_DEF]
\\ metis_tac[] )
\\ conj_tac>- ref_ok_tac
\\ rpt gen_tac \\ strip_tac
\\ CCONTR_TAC \\ fs[]
\\ drule_then drule decs_type_sound
\\ simp[]
\\ fs[type_sound_invariant_def, consistent_ctMap_def]
\\ first_assum $ irule_at Any \\ simp[]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC)
\\ CONJ_TAC >- (
rpt gen_tac \\ strip_tac \\ simp[]
\\ drule_then drule decs_type_sound \\ simp[]
\\ fs[]
\\ disch_then (qspecl_then[`ctMap`,`tenvS`] mp_tac)
\\ impl_tac >- (
fs[type_sound_invariant_def,consistent_ctMap_def]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC )
\\ strip_tac
\\ `EVERY (ref_lookup_ok new_s.refs) rs` by ref_ok_tac
\\ `type_s ctMap' new_store tenvS'` by (
match_mp_tac (GEN_ALL type_s_store_assign_exn)
\\ fs[type_sound_invariant_def,good_ctMap_def]
\\ metis_tac[])
\\ conj_tac >- (
fs[type_sound_invariant_def, consistent_ctMap_def]
\\ first_assum $ irule_at (Pat `type_all_env`)
\\ simp[SF SFY_ss]
\\ fs[SUBSET_DEF] \\ metis_tac[])
\\ conj_tac >- (
fs[type_sound_invariant_def, good_ctMap_def]
\\ metis_tac[GEN_ALL ref_lookup_ok_store_assign_exn])
\\ rpt gen_tac \\ strip_tac
\\ CCONTR_TAC \\ fs[]
\\ drule_then drule decs_type_sound
\\ simp[]
\\ fs[type_sound_invariant_def, consistent_ctMap_def]
\\ first_assum $ irule_at Any \\ simp[]
\\ reverse conj_tac >- metis_tac[]
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC)
\\ (
rpt gen_tac \\ strip_tac \\ fs[]
\\ CONJ_TAC >- (
fs[type_sound_invariant_def]
\\ first_assum $ irule_at Any
\\ CONJ_TAC>- (
fs[consistent_ctMap_def]
\\ metis_tac[])
\\ fs[consistent_ctMap_def]
\\ CONJ_TAC >- metis_tac[]
\\ metis_tac[type_s_store_assign_StrLit])
\\ CONJ_TAC >- metis_tac[ref_lookup_ok_store_assign]
\\ rpt gen_tac \\ strip_tac
\\ CCONTR_TAC \\ fs[]
\\ drule_then drule decs_type_sound
\\ simp[]
\\ fs[type_sound_invariant_def, consistent_ctMap_def]
\\ first_assum $ irule_at Any \\ simp[]
\\ reverse conj_tac >- (
conj_tac >- metis_tac[]
\\ metis_tac[type_s_store_assign_StrLit])
\\ fs[IN_DISJOINT, SUBSET_DEF]
\\ strip_tac \\ spose_not_then strip_assume_tac
\\ `x NOTIN tids` by metis_tac[]
\\ `x IN FRANGE ((SND o SND) o_f ctMap)` by metis_tac[]
\\ `x IN prim_type_ids` by metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP, FLOOKUP_o_f, CaseEq"option"]
\\ rveq \\ PairCases_on`v` \\ fs[] \\ rveq
\\ drule (CONJUNCT2 type_d_tids_disjoint)
\\ simp[IN_DISJOINT]
\\ first_assum $ irule_at Any
\\ pop_assum mp_tac
\\ EVAL_TAC)
QED
Theorem DISJOINT_set_ids:
tids ⊆ count id ⇒
DISJOINT tids (set_ids id id')
Proof
rw[set_ids_def,count_def,DISJOINT_DEF,EXTENSION,SUBSET_DEF]>>
CCONTR_TAC>>
fs[]>>
first_x_assum drule>>
fs[]
QED
Theorem set_ids_SUBSET[simp]:
set_ids id id' ⊆ count id'
Proof
rw[set_ids_def,count_def,SUBSET_DEF]
QED
Theorem count_id_MORE:
tids ⊆ count id ∧ id ≤ id' ⇒ tids ⊆ count id'
Proof
rw[count_def,SUBSET_DEF]>>
first_x_assum drule>>
fs[]
QED
Theorem set_ids_UNION:
id ≤ id' ∧ sid ≤ id ⇒
set_ids sid id' = set_ids sid id ∪ set_ids id id'
Proof
rw[set_ids_def,EXTENSION,EQ_IMP_THM]
QED
Theorem repl_types_F_repl_types_TS:
∀(ffi:'ffi ffi_state) rs types s env.
repl_types F (ffi,rs) (types,s,env) ⇒
repl_types_TS (ffi,rs) (set_ids start_type_id (SND types),ienv_to_tenv (FST types),s,env)
Proof
Induct_on`repl_types`
\\ rw[infertype_prog_inc_def, CaseEq"exc", init_infer_state_def]
\\ fs[PULL_EXISTS]
>- (
every_case_tac \\ fs[]
\\ drule (CONJUNCT2 infer_d_sound)
\\ disch_then (resolve_then Any mp_tac env_rel_init_config)
\\ impl_tac>- simp[]
\\ strip_tac
\\ rveq
\\ simp[ienv_to_tenv_extend,ienv_to_tenv_init_config]
\\ irule_at Any repl_types_TS_init
\\ simp[]
\\ rpt (CONJ_TAC >- EVAL_TAC)
\\ reverse CONJ_TAC >-
(asm_exists_tac >> fs[])
\\ qpat_x_assum`_ _ rs` mp_tac
\\ match_mp_tac EVERY_MONOTONIC
\\ rw[]
\\ simp[GSYM ienv_to_tenv_init_config, GSYM ienv_to_tenv_extend]
\\ match_mp_tac check_ref_types_check_ref_types_TS
\\ metis_tac[])
>- (
rename1`_ A decs = Success _`
\\ `∃tys id. A = (tys,id)` by metis_tac[PAIR]
\\ rw[] \\ fs[infertype_prog_inc_def]
\\ every_case_tac \\ fs[]
\\ drule (CONJUNCT2 infer_d_sound)
\\ disch_then(qspec_then `ienv_to_tenv tys` mp_tac)
\\ impl_tac >- (
drule repl_types_next_id
\\ simp[init_infer_state_def]
\\ metis_tac[repl_types_ienv_ok, env_rel_ienv_to_tenv,FST])
\\ strip_tac
\\ imp_res_tac (CONJUNCT2 infer_d_next_id_mono)
\\ drule repl_types_next_id
\\ rveq \\ fs[init_infer_state_def]
\\ strip_tac
\\ drule_then drule set_ids_UNION
\\ disch_then SUBST_ALL_TAC
\\ simp[ienv_to_tenv_extend]
\\ irule_at Any repl_types_TS_eval
\\ CONJ_TAC >-
(match_mp_tac DISJOINT_set_ids>>simp[init_infer_state_def])
\\ asm_exists_tac \\ simp[])
>- (
rename1`_ A decs = Success _`
\\ `∃tys id. A = (tys,id)` by metis_tac[PAIR]
\\ rw[] \\ fs[infertype_prog_inc_def]
\\ fs[CaseEqs["infer$exc","prod"]] \\ rveq
\\ drule (CONJUNCT2 infer_d_sound)
\\ disch_then(qspec_then `ienv_to_tenv tys` mp_tac)
\\ impl_tac >- (
drule repl_types_next_id
\\ simp[init_infer_state_def]
\\ metis_tac[repl_types_ienv_ok, env_rel_ienv_to_tenv,FST])
\\ strip_tac
\\ imp_res_tac (CONJUNCT2 infer_d_next_id_mono)
\\ drule repl_types_next_id
\\ rveq \\ fs[init_infer_state_def]
\\ strip_tac
\\ drule_then drule set_ids_UNION
\\ disch_then SUBST_ALL_TAC
\\ simp[ienv_to_tenv_extend]
\\ irule_at Any repl_types_TS_exn
\\ CONJ_TAC >-
(match_mp_tac DISJOINT_set_ids>>simp[init_infer_state_def])
\\ asm_exists_tac \\ simp[]
\\ metis_tac[])
>- (
rename1`_ A decs = Success _`
\\ `∃tys id. A = (tys,id)` by metis_tac[PAIR]
\\ rw[] \\ fs[infertype_prog_inc_def]
\\ fs[CaseEqs["infer$exc","prod"]] \\ rveq
\\ drule (CONJUNCT2 infer_d_sound)
\\ disch_then(qspec_then `ienv_to_tenv tys` mp_tac)
\\ impl_tac >- (
drule repl_types_next_id
\\ simp[init_infer_state_def]
\\ metis_tac[repl_types_ienv_ok, env_rel_ienv_to_tenv,FST])
\\ strip_tac
\\ simp[ienv_to_tenv_extend]
\\ drule_then drule repl_types_TS_exn_assign
\\ simp[init_infer_state_def]
\\ imp_res_tac (CONJUNCT2 infer_d_next_id_mono)
\\ drule repl_types_next_id
\\ fs[init_infer_state_def] \\ strip_tac
\\ simp[GSYM set_ids_UNION]
\\ disch_then irule
\\ CONJ_TAC >-
(match_mp_tac DISJOINT_set_ids>>simp[])
\\ asm_exists_tac \\ simp[]
\\ metis_tac[])
>>
metis_tac[repl_types_TS_str_assign]
QED
Theorem repl_types_F_thm:
∀(ffi:'ffi ffi_state) rs types s env.
repl_types F (ffi,rs) (types,s,env) ⇒
EVERY (ref_lookup_ok s.refs) rs ∧
∀decs new_t new_s res.
infertype_prog_inc types decs = Success new_t ∧
evaluate_decs s env decs = (new_s,res) ⇒
res ≠ Rerr (Rabort Rtype_error)
Proof
rpt gen_tac
\\ strip_tac
\\ imp_res_tac repl_types_F_repl_types_TS
\\ drule repl_types_TS_thm
\\ strip_tac
\\ rw[]
\\ rename1`_ A decs = Success _`
\\ `∃tys id. A = (tys,id)` by metis_tac[PAIR]
\\ qpat_x_assum`_ = Success _` mp_tac
\\ simp[infertype_prog_inc_def]
\\ every_case_tac \\ simp[]
\\ drule (CONJUNCT2 infer_d_sound)
\\ disch_then(qspec_then `ienv_to_tenv tys` mp_tac)
\\ impl_tac >- (
drule repl_types_next_id
\\ simp[init_infer_state_def]
\\ metis_tac[repl_types_ienv_ok, env_rel_ienv_to_tenv,FST])
\\ strip_tac
\\ strip_tac
\\ `FST A = tys` by fs[]
\\ pop_assum SUBST_ALL_TAC
\\ first_x_assum drule
\\ disch_then match_mp_tac
\\ fs[init_infer_state_def]
\\ match_mp_tac DISJOINT_set_ids
\\ simp[set_ids_SUBSET]
QED
Theorem repl_types_skip_alt:
repl_types T (ffi,rs) (t,s,env) ∧
s.ffi = s1.ffi ∧
s.refs ≼ s1.refs ∧
s1.clock ≤ s.clock ∧
s.eval_state = s1.eval_state ∧
s.next_type_stamp ≤ s1.next_type_stamp ∧
s.next_exn_stamp ≤ s1.next_exn_stamp ∧
s.fp_state = s1.fp_state ⇒
repl_types T (ffi,rs) (t,s1,env)
Proof
rw [] \\ gvs [LESS_EQ_EXISTS,rich_listTheory.IS_PREFIX_APPEND]
\\ drule repl_types_skip
\\ disch_then (qspecl_then [‘l’,‘p’,‘p'’,‘p''’] mp_tac)
\\ match_mp_tac (METIS_PROVE [] “b = c ⇒ b ⇒ c”)
\\ rpt (AP_TERM_TAC ORELSE AP_THM_TAC)
\\ fs [semanticPrimitivesTheory.state_component_equality]
QED
Theorem repl_types_set_clock:
∀b ffi rs t s env.
repl_types b (ffi,rs) (t,s,env) ⇒
∀ck. repl_types b (ffi,rs) (t,s with clock := ck,env)
Proof
Induct_on ‘repl_types’ \\ rpt conj_tac \\ rpt gen_tac \\ rw []
>- (* init *)
(drule evaluatePropsTheory.evaluate_decs_set_clock \\ fs []