-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreservation.v
2477 lines (2216 loc) · 80.8 KB
/
preservation.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import syntax.
Require Import partial.
Require Import heap.
Require Import classTable.
Require Import sframe.
Require Import reductions.
Require Import typing.
Require Import namesAndTypes.
Require Import wf_env.
Import ConcreteEverything.
Section Preservation.
Variable P: Program.
Definition subtypeP := subtype P.
Definition fldP := fld P.
Definition ftypeP := ftype P.
Definition t_frame1' := t_frame1 P.
Definition WF_Frame' := WF_Frame P.
Definition Reduction_SF' := Reduction_SF P .
Definition fieldsP := fields P.
Definition TypeChecksP := TypeChecksTerm P.
Definition TypeChecksExprP := TypeChecksExpr P.
Definition Heap_okP := Heap_ok P.
Definition Heap_dom_okP := Heap_dom_ok P .
Theorem preservation_light :
forall gamma H H' L L' t t' sigma eff,
Reduction_SF' ( # H, L, t !)
( # H', L', t' !)
->
TypeChecksP gamma eff t sigma ->
{Gamma' : Gamma_type & TypeChecksP Gamma' eff t' sigma}.
intros.
case_eq t; intros; rewrite H0 in * ; clear H0 t; inversion X;
inversion X0;
exists (p_Γ.updatePartFunc gamma v sigma0); auto;
rewrite H9 in *; auto.
Qed.
Local Open Scope type_scope.
Theorem preservation_case_var :
forall H L x y t sigma ann envVar,
WF_Frame' H (ann_frame (sframe L (t_let x <- Var y t_in (t))) ann) sigma ->
p_env.func L y = Some envVar ->
WF_Frame' H (ann_frame (sframe (p_env.updatePartFunc L x envVar) t) ann) sigma.
intros.
rename H0 into L_y_value.
inversion X.
clear X.
clear H4 t0 H5 H1 H2 L0 ann0 sigma0 H0 H3.
(* rename H6 into let_t_is_term. *)
rename X0 into Gamma_type_let.
rename X1 into wf_env_frame.
inversion Gamma_type_let.
clear Gamma_type_let.
clear gamma H0 x0 H3 eff0 H1 t0 H5 H2 tau H4 e.
rename X into Gamma_type_var_y; rename X0 into Gamma'_type_t.
set (Gamma' := (p_Γ.updatePartFunc Gamma x sigma0)).
fold Gamma' in Gamma'_type_t.
(* split. *)
set (L' := (p_env.updatePartFunc L x envVar)).
apply (t_frame1' H Gamma' eff t
L' ann sigma).
exact Gamma'_type_t.
clear Gamma'_type_t.
split.
destruct wf_env_frame.
apply (subset_preserved _ _ _ _ _ g).
intros.
rename H0 into Gamma'_x.
elim (v_eq_dec x x0).
intro; rewrite <- a in *; clear a.
inversion Gamma_type_var_y.
clear H4 H2 H0 H1 sigma2 gamma eff0 Gamma_type_var_y eff.
rename H3 into Gamma_y_value.
set (wf_var_y := snd wf_env_frame y sigma0 Gamma_y_value).
(* 3.
*)
induction envVar.
{
(*
* 3. (a), L(y) = null
*)
apply inl; apply inl.
apply (proj1 (p_env.updatedFuncProp L x envNull x) (eq_refl x)).
}
(* 3. (b), L(y) = o*)
rename r into o.
rename L_y_value into _3_b_i_A.
induction wf_var_y.
{
induction a. (* case L(y) = null in WF-var *)
{
rewrite a in _3_b_i_A; discriminate.
}
{ (* case L(y) = o', H(o') = <C, FM> in WF-var*)
induction b as [[c r ] [x2 [[Ly_value Gamma_y_value' ]
heap_Γ_y_subtype ]]].
rewrite (_3_b_i_A) in *; inversion Ly_value as [H1].
destruct H1.
rename c into C'.
clear Ly_value.
apply inl. apply inr.
exists (C', o).
exists x2.
split.
{
split.
{
apply p_env.updatedFuncProp; apply eq_refl.
}
{
set (lem := proj1 (p_Γ.updatedFuncProp Gamma x sigma0 x)
(eq_refl x)).
fold Gamma' in lem.
rewrite lem in Gamma'_x; inversion Gamma'_x;
rename H1 into sigma01_eq;
rewrite sigma01_eq in *.
rename sigma1 into sigma'; clear sigma01_eq Gamma'_x.
rewrite Gamma_y_value' in Gamma_y_value; inversion Gamma_y_value;
rename H1 into C'_sigma; rewrite <- C'_sigma in *.
clear C'_sigma sigma'. assumption.
}
}
assumption.
}
}
destruct b;
destruct x2;
destruct y0; destruct p as [[L_y_value Gamma_y_value'] heap_sub_c].
rewrite (_3_b_i_A) in *; inversion L_y_value.
(* 3 c, L(y) = b(o)*)
rename L_y_value into _3_c.
rename r into o.
destruct wf_env_frame as [_3_c_i_A _3_c_i_B].
rename Gamma_y_value into _1_b.
rename sigma0 into sigma'.
simpl in wf_var_y.
rename wf_var_y into _3_c_ii.
induction (_3_c_ii).
induction a. (* 3. c. iii. *)
rewrite a in _3_c; discriminate. (* 3. c. iv.*)
induction b; destruct x2;
destruct p as [r_in_H [[L_y_value Gamma_y_value] gamma_heap_y_r_c] ].
rename L_y_value into _3_c_v.
rewrite _3_c_v in _3_c; discriminate. (* 3. c. v. *)
destruct b; destruct x2. destruct y0. destruct p as
[[L_y_value Gamma_y_value] C'_sub_c].
set (C' := (heap_typeof H r x2)); fold C' in C'_sub_c.
rewrite _3_c in L_y_value; inversion L_y_value.
rename x0 into z.
rename sigma1 into tau.
rename H1 into refs_o_r_equal.
(* intro. *)
(* 3 box *)
destruct refs_o_r_equal.
(* rewrite H5 in *. clear H5 o. rename r into o. *)
clear L_y_value.
unfold WF_Var.
rewrite Gamma'_x.
apply inr.
exists (c, o).
exists x2.
split.
simpl. split.
exact (proj1 (p_env.updatedFuncProp L x (envBox o) x) (eq_refl _)).
simpl in Gamma'_x.
rewrite _1_b in Gamma_y_value.
inversion Gamma_y_value.
rename H1 into sigma'_typt_box_c.
symmetry in sigma'_typt_box_c.
destruct sigma'_typt_box_c.
set (lem := (proj1 (p_Γ.updatedFuncProp Gamma x (typt_box c) x) (eq_refl _))).
fold Gamma' in lem.
simpl in lem.
rewrite lem in Gamma'_x.
inversion Gamma'_x.
rename H1 into typt_box_c_tau.
f_equal.
exact C'_sub_c.
clear Gamma_type_var_y eff ann.
(* 4 *)
rename Gamma'_x into Gamma'z.
intro x_neq_x0.
rename x0 into z.
rename sigma1 into tau.
rename sigma0 into sigma'.
assert (p_Γ.func Gamma z = Some tau) as _4_a.
rewrite <- Gamma'z.
symmetry.
apply p_Γ.updatedFuncProp. firstorder.
destruct wf_env_frame as [ _4_c_i _4_c_ii].
set (_4_d := _4_c_ii z tau _4_a).
unfold WF_Var.
rewrite Gamma'z.
Require Import Coq.Lists.List.
assert (In z (p_Γ.domain Gamma)) as _4_ca.
set (lem := p_Γ.fDomainCompat Gamma z).
set (in_or_not := in_dec v_eq_dec z (p_Γ.domain Gamma)).
firstorder; rename H0 into Gamma_z_None;
rewrite Gamma_z_None in _4_a; discriminate.
set (lem''' := _4_c_i z _4_ca).
case_eq (p_env.func L z).
intros envVar' _4_ca_ii.
assert (p_env.func L' z = Some envVar') as _4_cb.
transitivity (p_env.func L z).
apply p_env.updatedFuncProp. firstorder.
exact _4_ca_ii.
unfold WF_Var in _4_d.
rewrite _4_cb in *.
rewrite _4_ca_ii in _4_d.
rewrite _4_a in _4_d.
exact _4_d.
intro L_z_value.
set (lem'''':= proj2 (p_env.fDomainCompat L z ) L_z_value).
firstorder.
Qed.
Theorem preservation_case_null :
forall H L t sigma ann x ,
WF_Frame' H (ann_frame (sframe L t_let x <- Null t_in (t)) ann) sigma ->
WF_Frame' H (ann_frame (sframe (p_env.updatePartFunc L x envNull) t ) ann) sigma.
intros.
rename X into asm1.
inversion asm1.
clear sigma0 ann0 H3 H5 t0 H4 H1 L0 H0 H2.
rename X0 into _3_b.
rename X into _3_a.
inversion _3_a.
clear H2 tau t0 H5 e H4 x0 H3 eff0 H1 H0 gamma.
rename sigma0 into sigma'.
rename X into _4_a.
rename X0 into _4_b.
destruct _3_b as [_6_a _6_b].
apply (t_frame1' H (p_Γ.updatePartFunc Gamma x sigma' )
eff t
(p_env.updatePartFunc L x envNull) ann sigma).
exact _4_b.
unfold WF_Env.
split.
exact (subset_preserved Gamma L x sigma' envNull _6_a).
intros z tau _8.
elim (v_eq_dec x z).
intro x_is_z; rewrite <- x_is_z in *; clear x_is_z.
(* assert (p_Γ.func (p_Γ.updatePartFunc Gamma x sigma') x = Some sigma') as _10_a. *)
(* exact (proj1 (p_Γ.updatedFuncProp Gamma x sigma' x) (eq_refl x)). *)
(* rewrite -> _10_a in _8; inversion _8. rewrite <- H1 in *; clear H1 tau _8. *)
(* unfold WF_Var. *)
apply inl.
apply inl.
exact (proj1 (p_env.updatedFuncProp L x envNull x) (eq_refl x)).
intro x_neq_z.
assert (p_Γ.func Gamma z = Some tau) as new_4_a.
rewrite <- _8.
symmetry.
apply (proj2 (p_Γ.updatedFuncProp Gamma x sigma' z)).
firstorder.
(* set (new__4_d := _6_b z tau _4_a). *)
unfold WF_Var.
(* rewrite H0. *)
(* Require Import Coq.Lists.List. *)
assert (In z (p_Γ.domain Gamma)) as new_4_ca.
set (lem := p_Γ.fDomainCompat Gamma z).
set (in_or_not := in_dec v_eq_dec z (p_Γ.domain Gamma)).
firstorder. rewrite H0 in new_4_a; discriminate.
set (lem''' := _6_a z new_4_ca).
case_eq (p_env.func L z).
intros envVar new__4_ca_ii.
assert (p_env.func (p_env.updatePartFunc L x envNull ) z = Some envVar) as new_4_cb.
transitivity (p_env.func L z).
apply p_env.updatedFuncProp. firstorder.
exact new__4_ca_ii.
set (new_4d := _6_b z tau new_4_a).
unfold WF_Var in new_4d.
rewrite new_4_cb in *.
rewrite new__4_ca_ii in *.
rewrite new_4_a in *.
rewrite _8.
exact new_4d.
intro.
set (lem'''':= proj2 (p_env.fDomainCompat L z ) H0).
firstorder.
Qed.
Notation "[ L , t ] ^ a" := (ann_frame (sframe L t) a) (at level 0).
Notation "( Γ ⊍ x ↦ σ )" := (p_Γ.updatePartFunc
Γ x σ)
(at level 0).
Notation "( p +++ a ↦ b )" := (p_env.updatePartFunc
p a b) (at level 0).
Notation "( H +*+ o ↦ obj )" := (p_heap.updatePartFunc
H o obj)
(at level 0).
Theorem preservation_case_new :
forall H L sigma ann t C x o flds,
WF_Frame' H (ann_frame (sframe L t_let x <- New C t_in (t)) ann) sigma ->
Heap_okP H ->
~ In o (p_heap.domain H) ->
fieldsP C flds ->
WF_Frame'
(p_heap.updatePartFunc H o (obj C (p_FM.newPartFunc flds FM_null)))
(ann_frame (sframe (p_env.updatePartFunc L x (envRef o)) t) ann) sigma.
intros H L σ ann t C x o flds wf_F wf_H o_not_in_H C_fields.
set (F := [L, t_let x <- New C t_in (t)] ^ ann).
fold F in wf_F.
(* 2 *)
inversion_clear wf_F as [dummy1 Γ eff dummy2 dummy3 dummy4
dummy5 t_typ_σ wf_H_Γ_L ].
unfold wf_env.TypeChecksP in t_typ_σ.
(* _2_a := t_typ_sigma
* _2_b := wf_H_Γ_L
*)
(* 3 *)
inversion_clear wf_H_Γ_L as [ΓL_sub wf_vars].
(* ΓL_sub := ΓL_sub
* wf_vars := wf_vars
*)
(* 4 *)
inversion_clear t_typ_σ.
rename sigma into C_type; rename X into typ_newC;
rename X0 into typ_next_frame.
(* 5 *)
inversion typ_newC.
{ (* ocap C *)
rewrite <- H2 in *; rewrite <- H4 in *.
clear H1 H0 C0 H2 H4 H2 eff gamma.
rename H3 into C_is_ocap.
(* section between 5, 6 let's call it half_6 *)
(* This is not in the same order on paper *)
(* split. *)
apply ( t_frame1' _
(p_Γ.updatePartFunc Γ x (typt_class C))
eff_ocap _ _ ann σ typ_next_frame).
assert (gamma_env_subset (Γ ⊍ x ↦ typt_class C)
(L +++ x ↦ envRef o)) as gamma_L_subset.
exact (subset_preserved Γ L x (typt_class C)
envNull ΓL_sub). (* actually, 7 *)
split.
{ (* Γ ⊆ L *) exact gamma_L_subset. }
{ (* wf-var z *)
intros z τ.
case_eq (v_eq_dec x z).
{ (* x = z *)
clear wf_vars typ_newC.
intro x_is_z; rewrite <- x_is_z in *; clear x_is_z z.
intro dummy; clear dummy.
(* Section half 6 on paper here somewhere *)
intro half_6.
set (half_6_a_i := proj1
(p_env.updatedFuncProp L x (envRef o) x)
(eq_refl _)).
assert (In o
(p_heap.domain
(H +*+ o ↦ obj C (p_FM.newPartFunc flds FM_null))
))
as o_witn.
apply p_heap.updatedFuncIn.
set (H'o := proj1
(p_heap.updatedFuncProp
H o (obj C (p_FM.newPartFunc flds FM_null)) o)
(eq_refl _)).
assert ((heap_typeof
(p_heap.updatePartFunc H o
(obj C (p_FM.newPartFunc flds FM_null)))
o o_witn) = C) as half_6_a_ii_first.
{ apply (heap_typeof_same _ _ _ _ H'o). }
assert (subtypeP ( typt_class
(heap_typeof
(H +*+ o ↦ obj C (p_FM.newPartFunc flds FM_null))
o o_witn)) (typt_class C)) as half_6_a_ii.
{
rewrite half_6_a_ii_first.
unfold subtypeP.
apply classSub.
apply subclass_refl. (* admitted (actually not defined) *)
}
set (lem := proj1 (p_Γ.updatedFuncProp
Γ x (typt_class C) x) (eq_refl _)).
rewrite half_6 in lem.
inversion lem.
rewrite H1 in *; clear lem H1 τ.
rename half_6 into half_6_a_iii.
apply inl. apply inr. exists (C, o).
exists o_witn.
split.
{
split.
{ exact half_6_a_i. }
{ exact half_6_a_iii. }
}
{ exact half_6_a_ii. }
}
{ (* x != z *)
(* 6 [THIS starts like #4 from E-Null]*)
intros _6_c dummy _6_a.
clear dummy.
assert (p_Γ.func Γ z = Some τ) as e_vi.
rewrite <- _6_a.
symmetry.
apply (proj2 (p_Γ.updatedFuncProp Γ x (typt_class C) z)).
firstorder.
(* set (new__4_d := _6_b z tau typ_newC). *)
(* unfold WF_Var. *)
(* rewrite H0. *)
assert (In z (p_Γ.domain Γ)) as z_in_dom_Gamma.
set (lem := p_Γ.fDomainCompat Γ z).
set (in_or_not := in_dec v_eq_dec z (p_Γ.domain Γ)).
firstorder. rewrite H0 in e_vi; discriminate.
set (z_in_dom_L := ΓL_sub z z_in_dom_Gamma).
case_eq (p_env.func L z).
{
intros envVar L_z_val.
assert (p_env.func
(p_env.updatePartFunc L x (envRef o) )
z = Some envVar) as _6_bb.
{
transitivity (p_env.func L z).
apply p_env.updatedFuncProp. firstorder.
exact L_z_val.
}
destruct envVar.
{
(* 6 d *)
apply inl. apply inl.
exact _6_bb.
}
(* 6 e *)
{ (* L z = o *)
rename r into o'.
assert ({ C : _ &
{witn : _ &
prod (prod (p_env.func L z = Some (envRef o'))
(p_Γ.func Γ z = Some (typt_class C)))
(subtypeP
(typt_class (heap_typeof H o' witn))
(typt_class C))
}}).
{
elim (wf_vars z τ e_vi).
intro.
destruct a.
{ (* L z = null *)
rewrite -> e in L_z_val; discriminate.
}
{ (* L z = o *)
destruct s.
destruct x0.
destruct y.
destruct p.
destruct p.
rewrite L_z_val in e.
inversion e.
rewrite H1 in *; clear H1 o'; rename r into o'.
clear e.
rewrite e_vi in e0.
inversion e0. rewrite -> H1 in *.
clear τ H1.
exists c. exists x0.
split.
{
split.
{ exact L_z_val. }
{ exact e_vi. }
}
{ exact s. }
}
intro.
destruct b. destruct x0. destruct y. destruct p. destruct p.
exists c.
rewrite L_z_val in e.
inversion e.
}
destruct X. destruct s. destruct p. destruct p.
(* clear H0. *)
rename x0 into C'.
rename x1 into o'_witness.
apply inl. apply inr.
exists (C', o').
exists (p_heap.staysInDomain
H o
(obj C (p_FM.newPartFunc flds FM_null)) o' o'_witness).
split.
{
split.
{ exact _6_bb. }
{
rewrite <- e0.
apply (p_Γ.updatedFuncProp). firstorder.
}
}
{ (* L z = o *)
set (H' := (p_heap.updatePartFunc
H o (obj C (p_FM.newPartFunc flds FM_null)))).
apply classSub.
inversion s.
assert (p_heap.func H o' = p_heap.func H' o') as _6_e_ii.
{ apply (p_heap.freshProp _ _ _ o_not_in_H _ o'_witness). }
assert ((heap_typeof
H' o'
(p_heap.staysInDomain
H o (obj C (p_FM.newPartFunc flds FM_null)) o'
o'_witness))
= (heap_typeof H o' o'_witness))
as _6_e_iii.
{
case_eq (p_heap.func H o').
{
intros. destruct b.
{
set (stays_witn := (p_heap.staysInDomain
H o
(obj C
(p_FM.newPartFunc flds FM_null)) o'
o'_witness)).
fold stays_witn.
rewrite <- H0 in *.
rewrite _6_e_ii in H3.
assert (c = C0).
{
symmetry in H0.
set (lem := heap_typeof_impl _ _ _ _ H0).
destruct lem.
rewrite H3 in _6_e_ii.
rewrite e1 in _6_e_ii.
inversion _6_e_ii.
reflexivity.
}
rewrite <- H4.
apply (heap_typeof_same _ _ _ _ H3).
}
}
(* None *)
{
intro is_none;
induction (proj2 (p_heap.fDomainCompat _ _)
is_none o'_witness).
}
}
rewrite _6_e_iii.
exact H2.
}
}
{ (* L z = b(o) *)
rename r into o'.
assert ({ C : _ &
{witn : _ &
prod (prod
(p_env.func L z = Some (envBox o'))
(p_Γ.func Γ z = Some
(typt_box C)))
(subtypeP
(typt_class (heap_typeof H o' witn))
(typt_class C))
}}).
{
elim (wf_vars z τ e_vi).
intro.
destruct a.
{ (* L z = null *)
rewrite -> e in L_z_val; discriminate.
}
{ (* L z = o *)
destruct s.
destruct x0.
destruct y.
destruct p.
destruct p.
rewrite L_z_val in e.
inversion e.
}
{
intro.
destruct b. destruct x0. destruct y. destruct p. destruct p.
rewrite L_z_val in e.
inversion e.
rewrite H1 in *; clear H1 o'; rename r into o'.
clear e.
rewrite e_vi in e0.
inversion e0. rewrite -> H1 in *.
clear τ H1.
exists c. exists x0.
split.
{
split.
{ exact L_z_val. }
{ exact e_vi. }
}
{ exact s. }
}
}
destruct X. destruct s. destruct p. destruct p.
(* clear H0. *)
rename x0 into C'.
rename x1 into o'_witness.
apply inr.
exists (C', o').
exists (p_heap.staysInDomain
H o
(obj C (p_FM.newPartFunc flds FM_null)) o' o'_witness).
split.
{
split.
{ exact _6_bb. }
{
rewrite <- e0.
apply (p_Γ.updatedFuncProp). firstorder.
}
}
{ (* L z = o *)
set (H' := (p_heap.updatePartFunc
H o (obj C (p_FM.newPartFunc flds FM_null)))).
apply classSub.
inversion s.
assert (p_heap.func H o' = p_heap.func H' o') as _6_e_ii.
{ apply (p_heap.freshProp _ _ _ o_not_in_H _ o'_witness). }
assert ((heap_typeof
H' o'
(p_heap.staysInDomain
H o (obj C (p_FM.newPartFunc flds FM_null)) o'
o'_witness))
= (heap_typeof H o' o'_witness))
as _6_e_iii.
{
case_eq (p_heap.func H o').
{
intros. destruct b.
{
set (stays_witn := (p_heap.staysInDomain
H o
(obj C
(p_FM.newPartFunc flds FM_null)) o'
o'_witness)).
fold stays_witn.
rewrite <- H0 in *.
rewrite _6_e_ii in H3.
assert (c = C0).
{
symmetry in H0.
set (lem := heap_typeof_impl _ _ _ _ H0).
destruct lem.
rewrite H3 in _6_e_ii.
rewrite e1 in _6_e_ii.
inversion _6_e_ii.
reflexivity.
}
rewrite <- H4.
apply (heap_typeof_same _ _ _ _ H3).
}
}
(* None *)
{
intro is_none;
induction (proj2 (p_heap.fDomainCompat _ _)
is_none o'_witness).
}
}
rewrite _6_e_iii.
exact H2.
}
}
}
{
intro L_z_is_none;
induction (proj2 (p_env.fDomainCompat _ _) L_z_is_none).
auto.
}
}
}
}
{ (* ocap C *)
rewrite <- H1 in *. rewrite <- H2 in *.
clear H1 H0 C0 H3 H2 eff gamma.
(* section between 5, 6 let's call it half_6 *)
(* This is not in the same order on paper *)
(* split. *)
apply ( t_frame1' _
(p_Γ.updatePartFunc Γ x (typt_class C))
eff_epsilon _ _ ann σ typ_next_frame).
assert (gamma_env_subset (Γ ⊍ x ↦ typt_class C)
(L +++ x ↦ envRef o)) as gamma_L_subset.
exact (subset_preserved Γ L x (typt_class C)
envNull ΓL_sub). (* actually, 7 *)
split.
{ (* Γ ⊆ L *) exact gamma_L_subset. }
{ (* wf-var z *)
intros z τ.
case_eq (v_eq_dec x z).
{ (* x = z *)
clear wf_vars typ_newC.
intro x_is_z; rewrite <- x_is_z in *; clear x_is_z z.
intro dummy; clear dummy.
(* Section half 6 on paper here somewhere *)
intro half_6.
set (half_6_a_i := proj1
(p_env.updatedFuncProp L x (envRef o) x)
(eq_refl _)).
assert (In o
(p_heap.domain
(H +*+ o ↦ obj C (p_FM.newPartFunc flds FM_null))
))
as o_witn.
apply p_heap.updatedFuncIn.
set (H'o := proj1
(p_heap.updatedFuncProp
H o (obj C (p_FM.newPartFunc flds FM_null)) o)
(eq_refl _)).
assert ((heap_typeof
(p_heap.updatePartFunc H o
(obj C (p_FM.newPartFunc flds FM_null)))
o o_witn) = C) as half_6_a_ii_first.
{ apply (heap_typeof_same _ _ _ _ H'o). }
assert (subtypeP ( typt_class
(heap_typeof
(H +*+ o ↦ obj C (p_FM.newPartFunc flds FM_null))
o o_witn)) (typt_class C)) as half_6_a_ii.
{
rewrite half_6_a_ii_first.
unfold subtypeP.
apply classSub.
apply subclass_refl. (* admitted (actually not defined) *)
}
set (lem := proj1 (p_Γ.updatedFuncProp
Γ x (typt_class C) x) (eq_refl _)).
rewrite half_6 in lem.
inversion lem.
rewrite H1 in *; clear lem H1 τ.
rename half_6 into half_6_a_iii.
apply inl. apply inr. exists (C, o).
exists o_witn.
split.
{
split.
{ exact half_6_a_i. }
{ exact half_6_a_iii. }
}
{ exact half_6_a_ii. }
}
{ (* x != z *)
(* 6 [THIS starts like #4 from E-Null]*)
intros _6_c dummy _6_a.
clear dummy.
assert (p_Γ.func Γ z = Some τ) as e_vi.
rewrite <- _6_a.
symmetry.
apply (proj2 (p_Γ.updatedFuncProp Γ x (typt_class C) z)).
firstorder.
(* set (new__4_d := _6_b z tau typ_newC). *)
(* unfold WF_Var. *)
(* rewrite H0. *)
assert (In z (p_Γ.domain Γ)) as z_in_dom_Gamma.
set (lem := p_Γ.fDomainCompat Γ z).
set (in_or_not := in_dec v_eq_dec z (p_Γ.domain Γ)).
firstorder. rewrite H0 in e_vi; discriminate.
set (z_in_dom_L := ΓL_sub z z_in_dom_Gamma).
case_eq (p_env.func L z).
{
intros envVar L_z_val.
assert (p_env.func
(p_env.updatePartFunc L x (envRef o) )
z = Some envVar) as _6_bb.
{
transitivity (p_env.func L z).
apply p_env.updatedFuncProp. firstorder.
exact L_z_val.
}
destruct envVar.
{
(* 6 d *)
apply inl. apply inl.
exact _6_bb.
}
(* 6 e *)
{ (* L z = o *)
rename r into o'.
assert ({ C : _ &
{witn : _ &
prod (prod (p_env.func L z = Some (envRef o'))
(p_Γ.func Γ z = Some (typt_class C)))
(subtypeP
(typt_class (heap_typeof H o' witn))
(typt_class C))
}}).
{
elim (wf_vars z τ e_vi).
intro.
destruct a.
{ (* L z = null *)
rewrite -> e in L_z_val; discriminate.
}
{ (* L z = o *)
destruct s.
destruct x0.
destruct y.
destruct p.
destruct p.
rewrite L_z_val in e.
inversion e.
rewrite H1 in *; clear H1 o'; rename r into o'.
clear e.
rewrite e_vi in e0.
inversion e0. rewrite -> H1 in *.
clear τ H1.
exists c. exists x0.
split.
{
split.
{ exact L_z_val. }
{ exact e_vi. }
}
{ exact s. }
}
intro.
destruct b. destruct x0. destruct y. destruct p. destruct p.
exists c.
rewrite L_z_val in e.
inversion e.
}
destruct X. destruct s. destruct p. destruct p.
(* clear H0. *)
rename x0 into C'.
rename x1 into o'_witness.
apply inl. apply inr.
exists (C', o').
exists (p_heap.staysInDomain
H o
(obj C (p_FM.newPartFunc flds FM_null)) o' o'_witness).
split.
{
split.
{ exact _6_bb. }
{
rewrite <- e0.
apply (p_Γ.updatedFuncProp). firstorder.
}
}
{ (* L z = o *)
set (H' := (p_heap.updatePartFunc
H o (obj C (p_FM.newPartFunc flds FM_null)))).
apply classSub.
inversion s.
assert (p_heap.func H o' = p_heap.func H' o') as _6_e_ii.
{ apply (p_heap.freshProp _ _ _ o_not_in_H _ o'_witness). }
assert ((heap_typeof
H' o'
(p_heap.staysInDomain
H o (obj C (p_FM.newPartFunc flds FM_null)) o'
o'_witness))
= (heap_typeof H o' o'_witness))
as _6_e_iii.
{
case_eq (p_heap.func H o').
{
intros. destruct b.
{
set (stays_witn := (p_heap.staysInDomain
H o
(obj C
(p_FM.newPartFunc flds FM_null)) o'
o'_witness)).
fold stays_witn.
rewrite <- H0 in *.
rewrite _6_e_ii in H3.
assert (c = C0).
{
symmetry in H0.
set (lem := heap_typeof_impl _ _ _ _ H0).
destruct lem.
rewrite H3 in _6_e_ii.
rewrite e1 in _6_e_ii.
inversion _6_e_ii.
reflexivity.
}
rewrite <- H4.
apply (heap_typeof_same _ _ _ _ H3).
}
}
(* None *)
{
intro is_none;
induction (proj2 (p_heap.fDomainCompat _ _)
is_none o'_witness).
}
}
rewrite _6_e_iii.
exact H2.
}
}
{ (* L z = b(o) *)
rename r into o'.
assert ({ C : _ &
{witn : _ &
prod (prod
(p_env.func L z = Some (envBox o'))
(p_Γ.func Γ z = Some
(typt_box C)))
(subtypeP
(typt_class (heap_typeof H o' witn))
(typt_class C))
}}).
{
elim (wf_vars z τ e_vi).
intro.
destruct a.
{ (* L z = null *)
rewrite -> e in L_z_val; discriminate.
}
{ (* L z = o *)
destruct s.
destruct x0.