-
Notifications
You must be signed in to change notification settings - Fork 4
/
preservation.v
1526 lines (1494 loc) · 46.7 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 mimperative mlattice language types mmemory id_and_loc Arith LibTactics tactics decision Coq.Program.Equality augmented low_equivalence List Coq.Program.Tactics.
Module Preservation (L : Lattice) (M : Memory L).
Module LowEq := LowEquivalence L M.
Import LowEq B Aug Imp TDefs M T MemProp LatProp Lang L.
Ltac invert_var_typing :=
match goal with
[H: expr_has_type _ (Var _) _ |- _] =>
inverts H
end.
Lemma array_type_is_not_recursive:
forall t l ℓ,
SecType (Array t ℓ) l = t -> False.
Proof.
apply (sectype_mut (fun t => forall l ℓ, Array (SecType t l) ℓ = t -> False)
(fun sect => forall l ℓ, SecType (Array sect ℓ) l = sect -> False)).
- intros.
discriminate.
- intros.
injects.
eauto.
- intros.
injects.
eauto.
Qed.
Lemma lookup_in_bounds_extend:
forall x m h loc l n v H1 H2,
(forall loc', v = ValLoc loc' -> reach m h loc') ->
~ reach m h loc ->
dangling_pointer_free m h ->
lookup_in_bounds m h ->
lookup_in_bounds (extend_memory x (ValLoc loc) m) (h [loc → (n × v, l), H1, H2]).
Proof.
intros.
unfolds.
intros.
destruct (decide (loc0 = loc)); subst.
- rewrite -> length_of_extend_eq in *.
rewrite_inj.
apply_heap_lookup_extend_eq.
rewrite_inj.
eauto.
- rewrite -> length_of_extend_neq in * by solve[eauto].
rewrite -> heap_lookup_extend_neq in * by solve[eauto 2].
rewrite_inj.
assert (reach m h loc0) by eauto 2 using reach_extend_implies_reach_if.
eauto.
Qed.
Lemma wf_stenv_subset:
forall Σ h1 h2 H,
wf_stenv Σ ([h1 ⊎ h2, H]) -> wf_stenv Σ h1.
Proof.
intros.
unfold wf_stenv in *.
intros.
super_destruct'.
splits*.
Qed.
Hint Resolve wf_stenv_subset.
Lemma reach_supset:
forall m h1 h2 loc H,
reach m h1 loc ->
reach m ([h1 ⊎ h2, H]) loc.
Proof.
intros.
induction H0; eauto.
Unshelve.
- repeat constructor.
Qed.
Hint Resolve reach_supset.
Lemma reach_supset':
forall m h1 h2 loc H,
reach m h2 loc ->
reach m ([h1 ⊎ h2, H]) loc.
Proof.
intros.
induction H0; eauto.
specialize (IHreach H).
assert (heap_lookup loc ([h1 ⊎ h, H]) = Some (ℓ, μ)).
{
rewrite -> disjoint_union_sym.
eauto.
}
eauto.
Unshelve.
- repeat constructor.
Qed.
Hint Resolve reach_supset'.
Lemma consistent_subset_helper:
forall m h1 h2 Γ Σ H,
consistent m ([h1 ⊎ h2, H]) Γ Σ ->
consistent m h1 Γ Σ /\ consistent m h2 Γ Σ.
Proof.
intros.
destruct_consistent.
splits*.
- unfolds.
splits*.
- unfolds.
splits*.
intros.
eapply H1.
+ eauto.
+ eauto.
+ rewrite -> disjoint_union_sym by eauto.
eauto.
+ eauto.
Qed.
Hint Resolve consistent_subset_helper.
Lemma consistent_subset:
forall m h1 h2 Γ Σ H,
consistent m ([h1 ⊎ h2, H]) Γ Σ ->
consistent m h1 Γ Σ.
Proof.
intros.
edestruct consistent_subset_helper; eauto.
Qed.
Hint Resolve consistent_subset.
Lemma dangling_pointer_free_subset:
forall m h1 h2 H,
dangling_pointer_free m ([h1 ⊎ h2, H]) ->
(forall loc ℓ μ,
heap_lookup loc h2 = Some (ℓ, μ) -> ~ reach m ([h1 ⊎ h2, H]) loc) ->
dangling_pointer_free m h1.
Proof.
intros.
unfolds.
intros.
assert (exists ℓ μ, heap_lookup loc ([h1 ⊎ h2, H]) = Some (ℓ, μ)) by eauto.
super_destruct.
exists ℓ μ.
destruct (disjoint_union_heap_lookup2 h1 h2 loc ℓ μ _ H3).
- eauto.
- assert (~ reach m ([h1 ⊎ h2, H]) loc) by eauto.
assert (reach m ([h1 ⊎ h2, H]) loc) by eauto using reach_supset.
contradiction.
Qed.
Hint Resolve dangling_pointer_free_subset.
Lemma lookup_in_bounds_subset:
forall m h1 h2 H,
dangling_pointer_free m h1 ->
lookup_in_bounds m ([h1 ⊎ h2, H]) ->
(forall loc ℓ μ,
heap_lookup loc h2 = Some (ℓ, μ) -> ~ reach m ([h1 ⊎ h2, H]) loc) ->
lookup_in_bounds m h1.
Proof.
intros.
unfold lookup_in_bounds in *.
intros.
assert (exists ν, heap_lookup loc ([h1 ⊎ h2, H]) = Some (ℓ, ν)) by eauto.
super_destruct.
assert (exists v, lookup ν n = Some v) by eauto.
super_destruct.
exists v.
super_destruct.
destruct_disjoint_heap_lookup.
+ congruence.
+ assert (heap_lookup loc h1 = None).
{
eapply disjoint_union_heap_lookup3.
- rewrite -> disjoint_union_sym.
erewrite -> disjoint_union_proof_irrelevance.
eauto.
Unshelve.
eauto.
- eauto.
}
match goal with
[H: dangling_pointer_free _ _,
H2: reach _ _ _ |- _] =>
unfolds in H;
specialize (H loc H2)
end.
destruct_exists.
rewrite_inj.
discriminate.
Qed.
Hint Resolve lookup_in_bounds_subset.
Lemma heap_level_bound_subset:
forall m h1 h2 Γ Σ H,
heap_level_bound Γ m ([h1 ⊎ h2, H]) Σ ->
heap_level_bound Γ m h1 Σ.
Proof.
intros.
splits*.
Qed.
Hint Resolve heap_level_bound_subset.
Lemma reach_from_supset:
forall x m h1 h2 loc H,
reach_from x m h1 loc ->
reach_from x m ([h1 ⊎ h2, H]) loc.
Proof.
intros.
unfold reach_from in *.
super_destruct.
eexists.
dependent induction H0; eauto.
Qed.
Hint Resolve reach_from_supset.
Lemma gc_preserves_wf:
forall c pc pc' m h1 h2 h3 t Γ Σ δ H1 H2 H3,
([h1 ⊎ h3, H1]) ⇝ (m, δ) h1 ->
disjoint ([h1 ⊎ h2, H2]) h3 ->
(forall loc ℓ μ, heap_lookup loc h3 = Some (ℓ, μ) -> ~ reach m ([([h1 ⊎ h2, H2]) ⊎ h3, H3]) loc) ->
wellformed_aux Γ Σ ⟨ c, pc, m, [([h1 ⊎ h2, H2]) ⊎ h3, H3], t ⟩ pc' ->
wellformed_aux Γ Σ ⟨ c, pc, m, [h1 ⊎ h2, H2], t + δ ⟩ pc'.
Proof.
intros.
induction c; constructor; invert_wf_aux; eauto.
Qed.
Hint Resolve gc_preserves_wf.
Lemma location_is_from_lookup_simple:
forall Γ level m e loc,
wf_tenv Γ m ->
{{Γ ⊢ e : level}} ->
eval m e = Some (ValLoc loc) ->
exists x,
memory_lookup m x = Some (ValLoc loc) /\ e = Var x.
Proof.
intros.
assert (exists x, e = Var x) by eauto using location_is_from_lookup.
super_destruct; subst.
exists x.
splits*.
Qed.
Hint Resolve location_is_from_lookup_simple.
Lemma var_exp_has_type_is_env_lookup:
forall Γ x t,
{{Γ ⊢ Var x : t}} ->
Γ x = Some t.
Proof.
intros.
inverts H; eauto.
Qed.
Hint Resolve var_exp_has_type_is_env_lookup.
Lemma reach_update_with_num:
forall m h loc1 loc2 n k,
reach m (update_heap loc1 n (ValNum k) h) loc2 ->
reach m h loc2.
Proof.
intros.
dependent induction H.
- eauto.
- destruct (decide (loc1 = loc)); subst.
+ assert (exists ν, heap_lookup loc h = Some (ℓ, ν) /\ μ = update_lookup ν n (ValNum k)) by eauto.
super_destruct; subst.
destruct (decide (n = n0)); subst.
* rewrite -> lookup_update_eq in *.
discriminate.
* rewrite -> lookup_update_neq in * by solve[eauto].
eauto.
+ rewrite -> heap_lookup_update_neq in * by solve[eauto].
eauto.
Unshelve.
* constructor; eauto.
* repeat constructor; eauto.
Qed.
Lemma reach_by_update_implies_reach_if:
forall m h l n loc1 loc2,
reach m (update_heap l n (ValLoc loc1) h) loc2 ->
reach m h loc1 ->
reach m h loc2.
Proof.
intros.
dependent induction H.
- eauto.
- specialize_gen.
destruct (decide (loc = l)); subst.
+ assert (exists ν, heap_lookup l h = Some (ℓ, ν) /\ μ = update_lookup ν n (ValLoc loc1))
by eauto.
super_destruct; subst.
destruct (decide (n = n0)); subst.
* rewrite -> lookup_update_eq in *.
rewrite_inj.
eauto.
* rewrite -> lookup_update_neq in * by solve[eauto].
eauto.
+ rewrite -> heap_lookup_update_neq in * by solve[eauto].
eauto.
Unshelve.
* constructor; eauto.
* repeat constructor; eauto.
Qed.
Lemma reach_extend2:
forall m h x loc1 loc2 loc3 n ℓ μ,
heap_lookup loc1 h = Some (ℓ, μ) ->
lookup μ n = Some (ValLoc loc2) ->
reach m h loc1 ->
reach (extend_memory x (ValLoc loc2) m) h loc3 -> reach m h loc3.
Proof.
intros.
dependent induction H2.
- destruct (decide (x = x0)); subst.
* rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
eauto.
* rewrite -> extend_memory_lookup_neq in * by solve[eauto].
eauto.
- assert (reach m h loc) by eauto.
eauto.
Unshelve.
+ constructor; eauto.
+ repeat constructor; eauto.
+ constructor; eauto.
Qed.
Lemma reach_from_implies_array_type:
forall Γ x t l m h loc,
wf_tenv Γ m ->
Γ x = Some (SecType t l) ->
reach_from x m h loc ->
exists s ℓ, t = Array s ℓ.
Proof.
intros.
unfold reach_from in *.
super_destruct.
revert loc H1.
induction k; intros; subst.
- inverts H0.
inverts H1.
destruct t; eauto.
assert (exists n, ValLoc loc = ValNum n) by eauto.
super_destruct; discriminate.
- inverts H1.
eauto.
Qed.
Hint Resolve reach_from_implies_array_type.
Lemma no_backat_implies_wt_aux_mono:
forall Γ pc c pc',
~ contains_backat c ->
wt_aux Γ pc c pc' ->
pc = pc'.
Proof.
intros.
dependent induction H0; eauto 2.
- firstorder.
congruence.
- exfalso; eauto 2.
Qed.
Hint Resolve no_backat_implies_wt_aux_mono.
Lemma preservation:
forall tenv stenv stenv' c1 pc1 m1 h1 t1 c2 pc2 m2 h2 t2 pc',
wellformed_aux tenv stenv (Config c1 pc1 m1 h1 t1) pc' ->
step (Config c1 pc1 m1 h1 t1) (Config c2 pc2 m2 h2 t2) tenv stenv stenv' ->
wellformed_aux tenv stenv' (Config c2 pc2 m2 h2 t2) pc'.
Proof.
intros tenv stenv stenv' c1 pc1 m1 h1 t1.
intros c2 pc2 m2 h2 t2 pc' H_wf H_step.
revert pc' c2 pc2 m2 h2 t2 H_wf H_step.
induction c1; intros; invert_step; subst; invert_wf_aux; subst.
(* Skip *)
- apply WellformedAux; intros; auto || (exfalso; eauto).
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
- eauto.
(* Assign *)
- assert ((i ::= e) <> Stop) by (intro H_absurd; discriminate H_absurd).
do 2 specialize_gen.
invert_wt_cmd.
apply WellformedAux; eauto.
+ invert_lifted.
rewrite_inj.
eapply wf_tenv_extend with (t := σ); intros; (repeat subst); eauto.
+ unfolds.
splits*.
{ intros.
destruct (decide (i = x)); subst.
- rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc) /\ e = Var x) by eauto 2.
super_destruct'; subst.
invert_var_typing.
invert_lifted.
eauto.
- rewrite -> extend_memory_lookup_neq in * by solve[eauto].
eauto 2.
}
{
intros.
destruct_consistent.
destruct v.
{
assert (reach m1 h2 loc1) by eauto 2 using reach_extend_with_num.
eauto.
}
{
destruct (decide (l0 = loc1)); subst.
- assert (exists x, memory_lookup m1 x = Some (ValLoc loc1) /\ e = Var x) by eauto.
super_destruct; subst.
eauto.
- assert (exists x, memory_lookup m1 x = Some (ValLoc l0) /\ e = Var x) by eauto.
super_destruct; subst.
eauto.
}
}
+ intros; exfalso; eauto.
+ (* Show: New memory is free of dangling pointers *)
unfolds.
intros.
invert_lifted.
rewrite_inj.
invert_reach.
* destruct (decide (i = x)); subst.
{
rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
match goal with
[H: eval _ ?e = Some (ValLoc _) |- _] => destruct e
end.
- discriminate.
- eauto.
- assert (exists n, ValLoc loc = ValNum n)
by eauto using eval_binop_is_num.
destruct_exists.
discriminate.
}
{
rewrite -> extend_memory_lookup_neq in * by solve[eauto].
eauto.
}
* unfold dangling_pointer_free in *.
inverts H1.
{
destruct (decide (i = x)); subst.
- rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc0) /\ e = Var x) by eauto.
super_destruct; subst.
eauto.
- rewrite -> extend_memory_lookup_neq in * by solve[eauto].
eauto.
}
{
destruct v.
- assert (reach m1 h2 loc) by eauto using reach_extend_with_num.
eauto.
- assert (exists x, memory_lookup m1 x = Some (ValLoc l) /\ e = Var x) by eauto.
super_destruct; subst.
destruct (decide (loc1 = l)); subst.
+ eauto.
+ assert (reach m1 h2 l) by eauto.
eauto using reach_extend.
}
+ invert_lifted.
rewrite_inj.
unfolds.
intros.
destruct v.
* assert (reach m1 h2 loc) by eauto using reach_extend_with_num.
eauto.
* assert (exists x, memory_lookup m1 x = Some (ValLoc l) /\ e = Var x) by eauto.
super_destruct; subst.
destruct (decide (loc = l)); subst; eauto using reach_extend.
+ unfolds.
splits; eauto 2.
intros.
invert_lifted.
rewrite_inj.
destruct (decide (i = x)); subst.
* rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc) /\ e = Var x) by eauto.
super_destruct'; subst.
invert_var_typing.
eauto 2.
* rewrite -> extend_memory_lookup_neq in * by solve[eauto].
eauto 2.
* intros.
invert_lifted.
destruct σ.
{ assert (exists n, v = ValNum n) by eauto.
super_destruct'; subst.
eauto using reach_extend_with_num.
}
{ assert (exists loc, v = ValLoc loc) by eauto.
super_destruct'; subst.
destruct (decide (loc0 = loc)); subst.
- assert (exists x, memory_lookup m1 x = Some (ValLoc loc) /\ e = Var x) by eauto.
super_destruct; subst.
eauto.
- rewrite_inj.
assert (reach m1 h2 loc).
{
eapply reach_extend.
- eapply H0.
- assert (exists x, memory_lookup m1 x = Some (ValLoc loc0) /\ e = Var x) by eauto.
super_destruct; subst.
eauto.
}
eauto 3.
}
* intros.
invert_lifted.
rewrite_inj.
destruct σ.
{
assert (exists n, v = ValNum n) by eauto.
super_destruct; subst.
assert (reach m1 h2 loc1) by eauto 3 using reach_extend_with_num.
eauto.
}
{
assert (exists loc, v = ValLoc loc) by eauto.
super_destruct; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc) /\ e = Var x) by eauto.
super_destruct; subst.
assert (reach m1 h2 loc1).
{
eapply reach_extend.
- eapply H0.
- eauto.
}
eauto.
}
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
- (* If *)
assert ((If e c1_1 c2) <> Stop) by congruence.
assert ((If e c1_1 c2) <> TimeOut) by congruence.
do 2 specialize_gen.
invert_wt_cmd.
apply WellformedAux; intros; eauto.
- assert ((If e c2 c1_2) <> Stop) by congruence.
assert ((If e c2 c1_2) <> TimeOut) by congruence.
do 2 specialize_gen.
invert_wt_cmd.
apply WellformedAux; intros; eauto.
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto 2.
- (* While *)
assert ((While e c1) <> Stop) by congruence.
assert ((While e c1) <> TimeOut) by congruence.
do 2 specialize_gen.
invert_wt_cmd.
apply WellformedAux; try assumption.
intros; exfalso; eauto.
- assert ((While e c1) <> Stop) by congruence.
assert ((While e c1) <> TimeOut) by congruence.
do 2 specialize_gen.
invert_wt_cmd.
apply WellformedAux; intros; try assumption.
apply (wt_aux_seq tenv pc' pc' pc'); eauto.
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
(* Sequencing *)
- assert ((c1_1;; c2) <> Stop) by congruence.
assert ((c1_1;; c2) <> TimeOut) by congruence.
do 2 specialize_gen.
invert_wt_cmd.
assert (pc2 = pc'0).
{
eauto 3 using wt_aux_soundness.
}
subst.
assert (exists pc1', wellformed_aux tenv stenv ⟨c1_1, pc1, m1, h1, t1⟩ pc1') by eauto.
super_destruct; subst.
assert (wellformed_aux tenv stenv' ⟨STOP, pc'0, m2, h2, t2⟩ pc1') by eauto.
destruct_exists.
invert_wf_aux.
apply WellformedAux; intros; eauto.
- assert ((c1_1 ;; c1_2) <> Stop) by congruence.
assert ((c1_1 ;; c1_2) <> TimeOut) by congruence.
do 2 specialize_gen.
clear H.
invert_wt_cmd.
assert (wellformed_aux tenv stenv ⟨c1_1, pc1, m1, h1, t1⟩ pc'0) by eauto.
assert (wellformed_aux tenv stenv' ⟨c1', pc2, m2, h2, t2⟩ pc'0) by eauto.
destruct_exists.
invert_wf_aux.
apply WellformedAux; intros; try assumption.
+ repeat specialize_gen.
eapply wt_aux_seq; eauto.
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
(* At *)
- apply WellformedAux; intros; try assumption.
assert (At pc2 e c1 <> Stop) by congruence.
assert (At pc2 e c1 <> TimeOut) by congruence.
do 2 specialize_gen.
invert_wt_cmd.
eapply wt_aux_seq.
+ eauto.
+ assert (pc2 = ℓ'') by eauto 2 using no_backat_implies_wt_aux_mono.
subst.
constructors; eauto 2 using flowsto_refl.
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
(* Backat with wait *)
- apply WellformedAux; eauto.
(* Backat with progress *)
- assert (BackAt pc2 t1 <> Stop) by congruence.
assert (BackAt pc2 t1 <> TimeOut) by congruence.
do 2 specialize_gen.
clear H.
invert_wt_cmd.
apply WellformedAux; eauto.
intro; exfalso; eauto.
- assert (BackAt pc2 t1 <> Stop) by congruence.
assert (BackAt pc2 t1 <> TimeOut) by congruence.
do 2 specialize_gen.
constructor; eauto 2.
intros.
exfalso; eauto 2.
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
(* new *)
- let H1 := fresh in let H2 := fresh in
assert (NewArr i l e e0 <> Stop) as H1 by congruence;
assert (NewArr i l e e0 <> TimeOut) as H2 by congruence;
do 2 specialize_gen;
clear H1; clear H2.
invert_wt_cmd.
rewrite_inj.
apply WellformedAux; eauto.
+ destruct τ0 as [σ ℓ].
eapply wf_tenv_extend; eauto.
intro; discriminate.
+ destruct τ0 as [σ ℓ].
eapply wf_stenv_extend; intros; subst; eauto.
+ unfolds.
splits.
* intros.
destruct (decide (i = x)); subst.
{
rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
unfold extend_stenv.
rewrite -> eq_loc.
rewrite_inj.
reflexivity.
}
{
rewrite -> extend_memory_lookup_neq in * by solve[eauto].
destruct (decide (l1 = loc)); subst.
- invert_dang_free; eauto.
assert (exists ℓ μ, heap_lookup loc h1 = Some (ℓ, μ)) by eauto.
destruct_exists.
rewrite_inj.
discriminate.
- unfold extend_stenv.
rewrite -> neq_loc by eauto.
destruct_consistent.
eauto.
}
* intros.
destruct (decide (loc1 = l1)); subst.
{
rewrite -> extend_stenv_lookup_eq in *.
apply_heap_lookup_extend_eq.
assert (v = ValLoc loc2).
{
match goal with
[H1: forall _, lookup _ _ = Some _,
H2: lookup _ ?n = Some _ |- _] =>
specialize (H1 n)
end.
rewrite_inj.
reflexivity.
}
subst.
rewrite_inj.
assert (exists y, memory_lookup m1 y = Some (ValLoc loc2) /\ e0 = Var y) by eauto.
super_destruct; subst.
assert (exists ℓ μ, heap_lookup loc2 h1 = Some (ℓ, μ)) by eauto.
super_destruct.
rewrite_inj.
assert (l1 <> loc2).
{
intro.
subst.
rewrite_inj.
discriminate.
}
rewrite -> extend_stenv_lookup_neq by solve[eauto].
eauto.
}
{
rewrite -> extend_stenv_lookup_neq in * by solve[eauto].
rewrite -> heap_lookup_extend_neq in * by solve[eauto 2].
destruct (decide (l1 = loc2)); subst.
- assert (~ reach m1 h1 loc2).
{
intro.
assert (exists ℓ μ, heap_lookup loc2 h1 = Some (ℓ, μ)) by eauto.
super_destruct.
rewrite_inj.
discriminate.
}
assert (~ reach m1 h1 loc1).
{
intro.
eauto.
}
assert (forall loc' : loc, v = ValLoc loc' -> reach m1 h1 loc').
{
intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc') /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
}
match goal with
[H: ~ reach _ _ loc1 |- _] =>
contradict H
end.
eauto 2 using reach_extend_implies_reach_if.
- rewrite -> extend_stenv_lookup_neq by solve[eauto].
destruct_consistent.
assert (forall loc' : loc, v = ValLoc loc' -> reach m1 h1 loc').
{
intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc') /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
}
assert (~ reach m1 h1 l1).
{
intro.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; subst.
rewrite_inj.
discriminate.
}
assert (reach m1 h1 loc1) by eauto 2 using reach_extend_implies_reach_if.
eauto.
}
+ (* Show: Stop is Welltyped *)
intro.
exfalso; eauto.
+ (* Show: Dangling free memory and heap *)
unfolds.
intros.
destruct (decide (l1 = loc)); subst.
* assert (exists μ,
heap_lookup loc (h1 [loc → (n × v, l), H1, H2]) = Some (l, μ) /\
(forall n0 : nat, lookup μ n0 = Some v)) by eauto.
super_destruct; subst.
eauto.
* assert (forall loc' : id_and_loc.loc, v = ValLoc loc' -> reach m1 h1 loc').
{
intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc') /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
}
assert (loc <> l1) by eauto.
assert (~ reach m1 h1 l1).
{
intro.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; subst.
rewrite_inj.
discriminate.
}
assert (reach m1 h1 loc) by eauto 2 using reach_extend_implies_reach_if.
destruct_consistent.
rewrite -> heap_lookup_extend_neq by solve[eauto].
eauto.
+ eapply lookup_in_bounds_extend; eauto 2.
* intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc') /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
* intro.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; subst.
rewrite_inj.
discriminate.
+ unfolds.
splits.
* intros.
destruct (decide (i = x)); subst.
{
rewrite -> extend_memory_lookup_eq in *.
rewrite_inj.
apply_heap_lookup_extend_eq.
rewrite_inj.
reflexivity.
}
{
rewrite -> extend_memory_lookup_neq in * by solve[eauto].
destruct (decide (loc = l1)); subst.
- edestruct (heap_lookup_extend_eq l1 l n v h1); eauto 2.
super_destruct.
rewrite_inj.
invert_dang_free.
assert (exists ℓ μ, heap_lookup l1 h1 = Some (ℓ, μ)) by eauto.
destruct_exists.
rewrite_inj.
discriminate.
- rewrite -> heap_lookup_extend_neq in * by solve[eauto].
eauto 2.
}
* intros.
destruct (decide (loc = l1)); subst.
{
rewrite -> extend_stenv_lookup_eq in *.
rewrite_inj.
apply_heap_lookup_extend_eq.
rewrite_inj.
destruct (decide (loc' = l1)); subst.
- rewrite_inj.
assert (v = ValLoc l1) by congruence.
subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc l1) /\ e0 = Var x) by eauto.
super_destruct'; subst.
assert (reach m1 h1 l1) by eauto.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; subst.
congruence.
- rewrite -> heap_lookup_extend_neq in * by solve[eauto].
assert (exists loc, v = ValLoc loc) by eauto.
super_destruct'; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc) /\ e0 = Var x) by eauto.
super_destruct; subst.
invert_var_typing.
assert (loc = loc') by congruence; subst.
symmetry.
eauto 2.
}
{
rewrite -> heap_lookup_extend_neq in * by solve[eauto].
rewrite -> extend_stenv_lookup_neq in * by solve[eauto].
destruct (decide (loc' = l1)); subst.
- apply_heap_lookup_extend_eq.
rewrite_inj.
assert (~ reach m1 h1 l1).
{
intro.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; congruence.
}
assert (reach m1 h1 loc).
{
assert (forall loc', v = ValLoc loc' -> reach m1 h1 loc').
{
intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc') /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
}
eapply reach_extend_implies_reach_if; eauto.
}
assert (reach m1 h1 l1) by eauto 2.
contradiction.
- rewrite -> heap_lookup_extend_neq in * by solve[eauto].
assert (~ reach m1 h1 l1).
{
intro.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; congruence.
}
assert (reach m1 h1 loc).
{
assert (forall loc', v = ValLoc loc' -> reach m1 h1 loc').
{
intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc'0) /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
}
eapply reach_extend_implies_reach_if; eauto.
}
eauto 2.
}
* intros.
destruct (decide (loc1 = l1)); subst.
{
apply_heap_lookup_extend_eq.
rewrite_inj.
destruct (decide (loc2 = l1)); subst.
- rewrite_inj.
eapply flowsto_refl.
- rewrite -> heap_lookup_extend_neq in * by solve[eauto].
assert (wf_type bot (SecType (Array τ0 l) (ℓ_x, ∘))) by eauto.
invert_wf_type.
assert (v = ValLoc loc2) by congruence; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc2) /\ e0 = Var x) by eauto.
super_destruct; subst.
invert_var_typing.
destruct τ0 as [τ ε].
assert (exists t, τ = Array t ℓ2).
{
destruct τ.
- assert (exists n, ValLoc loc2 = ValNum n) by eauto.
super_destruct; congruence.
- exists s.
eapply f_equal2; eauto 2.
}
super_destruct'; subst.
invert_wf_type.
eauto.
}
{
rewrite -> heap_lookup_extend_neq in * by solve[eauto].
assert (reach m1 h1 loc1).
{
assert (~ reach m1 h1 l1).
{
intro.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; congruence.
}
assert (forall loc' : loc, v = ValLoc loc' -> reach m1 h1 loc').
{
intros; subst.
assert (exists x, memory_lookup m1 x = Some (ValLoc loc') /\ e0 = Var x) by eauto.
super_destruct; subst.
eauto.
}
eapply reach_extend_implies_reach_if; eauto.
}
destruct (decide (loc2 = l1)); subst.
- apply_heap_lookup_extend_eq.
rewrite_inj.
assert (reach m1 h1 l1) by eauto 2.
assert (exists l μ, heap_lookup l1 h1 = Some (l, μ)) by eauto.
super_destruct; subst.
congruence.
- rewrite -> heap_lookup_extend_neq in * by solve[eauto].
eauto 2.
}
- eapply gc_preserves_wf.
+ eauto.
+ eauto.
+ eauto.
+ erewrite -> disjoint_union_proof_irrelevance; eauto.
(* Set array *)
- let H1 := fresh in let H2 := fresh in
assert (SetArr i e e0 <> Stop) as H1 by congruence;
assert (SetArr i e e0 <> TimeOut) as H2 by congruence;
do 2 specialize_gen;
clear H1; clear H2.
apply WellformedAux; eauto.
+ unfolds.
intros.
splits~.
* intros.
destruct (decide (loc = l0)); subst.
{
_apply heap_lookup_update_eq2 in *.
super_destruct; subst.
destruct (decide (n0 = n)); subst.
- rewrite -> lookup_update_eq in *.
rewrite_inj.
invert_wt_cmd.
invert_lifted.
assert (σ = Int).
{
match goal with
[H: consistent _ _ _ _,
H2: stenv' _ = Some _ |- _] =>
destruct H as [H _];
erewrite -> H in H2; eauto