-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_sem.v
1919 lines (1718 loc) · 85.5 KB
/
space_sem.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
(* Space semantics for L6. Part of the CertiCoq project.
* Author: Zoe Paraskevopoulou, 2016
*)
From Coq Require Import NArith.BinNat Relations.Relations MSets.MSets
MSets.MSetRBT Lists.List omega.Omega Sets.Ensembles Relations.Relations
Classes.Morphisms NArith.Ndist.
From SFS Require Import cps ctx cps_util List_util Ensembles_util functions
identifiers tactics set_util map_util.
From SFS Require Import heap heap_defs heap_equiv GC.
From SFS Require Import Coqlib.
Import ListNotations.
Module SpaceSem (H : Heap).
Module GC := GC H.
Parameter (cloTag : cTag).
Import H GC.Equiv.Defs GC.Equiv.Defs.HL GC.Equiv GC.
(* The cost of evaluating the head constructor before CC *)
Definition cost (e : exp) : nat :=
match e with
| Econstr x t ys e => 1 + length ys
| Ecase y cl => 1
| Eproj x t n y e => 1
| Efun B e => 1 + PS.cardinal (fundefs_fv B)
| Eapp f t ys => 1 + length ys
| Eprim x p ys e => 1 + length ys
| Ehalt x => 1
end.
(* The cost of evaluating the head constructor after CC *)
Definition cost_cc (e : exp) : nat :=
match e with
| Econstr x t ys e => 1 + length ys
| Ecase y cl => 1
| Eproj x t n y e => 1
| Efun B e => 1
| Eapp f t ys => 1 + length ys
| Eprim x p ys e => 1 + length ys
| Ehalt x => 1
end.
(** Deterministic semantics with garbage collection upon function entry. *)
Inductive big_step_GC :
heap block -> (* The heap. Maps locations to values *)
env -> (* The environment. Maps variables to locations *)
exp -> (* The expression to be evaluated *)
ans -> (* The final result, which is a pair of a location an a heap *)
nat -> (* Upper bound for the number of the evaluation steps *)
nat -> (* The maximum space required for the evaluation *)
Prop :=
| Eval_oot_gc :
forall (H : heap block) (rho : env) (e : exp) (c m : nat)
(Hcost : c < cost e)
(Hsize : size_heap H = m),
(big_step_GC H rho e OOT c m)
| Eval_constr_gc :
forall (H H' : heap block) (rho : env) (x : var) (t : cTag)
(ys : list var) (e : exp) (vs : list value) (l : loc) (r : ans)
(c m : nat)
(Hcost : c >= cost (Econstr x t ys e))
(Hget : getlist ys rho = Some vs)
(Halloc : alloc (Constr t vs) H = (l, H'))
(Hbs : big_step_GC H' (M.set x (Loc l) rho) e r (c - cost (Econstr x t ys e)) m),
big_step_GC H rho (Econstr x t ys e) r c m
| Eval_proj_gc : (* XXX Tag annotation in projections is redundant in this semantics *)
forall (H : heap block) (rho : env) (x : var) (t t' : cTag) (n : N)
(y : var) (e : exp) (l : loc) (v : value) (vs : list value)
(r : ans) (c m : nat)
(Hcost : c >= cost (Eproj x t n y e))
(Hgety : M.get y rho = Some (Loc l))
(Hgetl : get l H = Some (Constr t' vs))
(Hnth : nthN vs n = Some v)
(Hbs : big_step_GC H (M.set x v rho) e r (c - cost (Eproj x t n y e)) m),
big_step_GC H rho (Eproj x t n y e) r c m
| Eval_case_gc :
forall (H : heap block) (rho : env) (y : var) (cl : list (cTag * exp))
(l : loc) (t : cTag) (vs : list value) (e : exp) (r : ans) (c m : nat)
(Hcost : c >= cost (Ecase y cl))
(Hgety : M.get y rho = Some (Loc l))
(Hgetl : get l H = Some (Constr t vs))
(Htag : findtag cl t = Some e)
(Hbs : big_step_GC H rho e r (c - cost (Ecase y cl)) m),
big_step_GC H rho (Ecase y cl) r c m
| Eval_fun_gc :
forall (H H' H'' : heap block) (rho rho_clo rho' : env) lenv (B : fundefs)
(e : exp) (r : ans) (c : nat) (m : nat)
(Hcost : c >= cost (Efun B e))
(* find the closure environment *)
(Hres : restrict_env (fundefs_fv B) rho = rho_clo)
(Ha : alloc (Env rho_clo) H = (lenv, H'))
(* allocate the closures *)
(Hfuns : def_closures B B rho H' (Loc lenv) = (H'', rho'))
(Hbs : big_step_GC H'' rho' e r (c - cost (Efun B e)) m),
big_step_GC H rho (Efun B e) r c m
| Eval_app_gc :
forall (H H' H'' : heap block) lenv (rho_clo rho rho_clo1 rho_clo2 : env) (B : fundefs)
(f f' : var) (t : cTag) (xs : list var) (e : exp) (l : loc) b
(vs : list value) (ys : list var) (r : ans) (c : nat) (m m' : nat)
(Hcost : c >= cost (Eapp f t ys))
(Hgetf : M.get f rho = Some (Loc l))
(* Look up the closure *)
(Hgetl : get l H = Some (Clos (FunPtr B f') (Loc lenv)))
(* Find the code *)
(Hfind : find_def f' B = Some (t, xs, e))
(Hgetenv : get lenv H = Some (Env rho_clo))
(* Look up the actual parameters *)
(Hargs : getlist ys rho = Some vs)
(* Allocate mutually defined closures *)
(Hredef : def_closures B B rho_clo H (Loc lenv) = (H', rho_clo1))
(Hset : setlist xs vs rho_clo1 = Some rho_clo2)
(* collect H' *)
(Hgc : live' ((env_locs rho_clo2) (occurs_free e)) H' H'' b)
(Hsize : size_heap H' = m')
(Hbs : big_step_GC H'' (subst_env b rho_clo2)
e r (c - cost (Eapp f t ys)) m),
big_step_GC H rho (Eapp f t ys) r c (max m m')
| Eval_halt_gc :
forall H rho x l c m
(Hcost : c >= cost (Ehalt x))
(Hget : M.get x rho = Some l)
(Hsize : size_heap H = m),
big_step_GC H rho (Ehalt x) (Res (l, H)) c m.
(** Deterministic semantics with reachable space profiling *)
Inductive big_step :
heap block -> (* The heap. Maps locations to values *)
env -> (* The environment. Maps variables to locations *)
exp -> (* The expression to be evaluated *)
ans -> (* The final result, which is a pair of a location an a heap *)
nat -> (* Upper bound for the number of the evaluation steps *)
nat -> (* The maximum amount of reachable space during execution *)
Prop :=
| Eval_oot :
forall (H : heap block) (rho : env) (e : exp) (c : nat)
(Hcost : c < cost e),
big_step H rho e OOT c (reach_size H rho e)
| Eval_constr :
forall (H H' : heap block) (rho rho' : env) (x : var) (t : cTag)
(ys : list var) (e : exp) (vs : list value) (l : loc) (r : ans)
(c m : nat)
(Hcost : c >= cost (Econstr x t ys e))
(Hget : getlist ys rho = Some vs)
(Halloc : alloc (Constr t vs) H = (l, H'))
(Hbs : big_step H' (M.set x (Loc l) rho) e r (c - cost (Econstr x t ys e)) m),
big_step H rho (Econstr x t ys e) r c (max (reach_size H rho (Econstr x t ys e)) m)
| Eval_proj : (* XXX Tag annotation in projections is redundant in this semantics *)
forall (H : heap block) (rho : env) (x : var) (t t' : cTag) (n : N)
(y : var) (e : exp) (l : loc) (v : value) (vs : list value)
(r : ans) (c m : nat)
(Hcost : c >= cost (Eproj x t n y e))
(Hgety : M.get y rho = Some (Loc l))
(Hgetl : get l H = Some (Constr t' vs))
(Hnth : nthN vs n = Some v)
(Hbs : big_step H (M.set x v rho) e r (c - cost (Eproj x t n y e)) m),
big_step H rho (Eproj x t n y e) r c (max (reach_size H rho (Eproj x t n y e)) m)
| Eval_case :
forall (H : heap block) (rho : env) (y : var) (cl : list (cTag * exp))
(l : loc) (t : cTag) (vs : list value) (e : exp) (r : ans) (c m : nat)
(Hcost : c >= cost (Ecase y cl))
(Hgety : M.get y rho = Some (Loc l))
(Hgetl : get l H = Some (Constr t vs))
(Htag : findtag cl t = Some e)
(Hbs : big_step H rho e r (c - cost (Ecase y cl)) m),
big_step H rho (Ecase y cl) r c (max (reach_size H rho (Ecase y cl)) m)
| Eval_fun :
forall (H H' H'' : heap block) (rho rho_clo rho' : env) lenv (B : fundefs)
(e : exp) (r : ans) (c : nat) (m : nat)
(Hcost : c >= cost (Efun B e))
(* find the closure environment *)
(Hres : restrict_env (fundefs_fv B) rho = rho_clo)
(Ha : alloc (Env rho_clo) H = (lenv, H'))
(* allocate the closures *)
(Hfuns : def_closures B B rho H' (Loc lenv) = (H'', rho'))
(Hbs : big_step H'' rho' e r (c - cost (Efun B e)) m),
big_step H rho (Efun B e) r c (max (reach_size H rho (Efun B e)) m)
| Eval_app :
forall (H H' : heap block) lenv (rho_clo rho rho_clo1 rho_clo2 : env) (B : fundefs)
(f f' : var) (t : cTag) (xs : list var) (e : exp) (l : loc)
(vs : list value) (ys : list var) (r : ans) (c : nat) (m : nat)
(Hcost : c >= cost (Eapp f t ys))
(Hgetf : M.get f rho = Some (Loc l))
(* Look up the closure *)
(Hgetl : get l H = Some (Clos (FunPtr B f') (Loc lenv)))
(* Find the code *)
(Hfind : find_def f' B = Some (t, xs, e))
(Hgetenv : get lenv H = Some (Env rho_clo))
(* Look up the actual parameters *)
(Hargs : getlist ys rho = Some vs)
(* Allocate mutually defined closures *)
(Hredef : def_closures B B rho_clo H (Loc lenv) = (H', rho_clo1))
(Hset : setlist xs vs rho_clo1 = Some rho_clo2)
(Hbs : big_step H' rho_clo2
e r (c - cost (Eapp f t ys)) m),
big_step H rho (Eapp f t ys) r c (max (reach_size H rho (Eapp f t ys)) m)
| Eval_halt :
forall H rho x l c
(Hcost : c >= cost (Ehalt x))
(Hget : M.get x rho = Some l),
big_step H rho (Ehalt x) (Res (l, H)) c (reach_size H rho (Ehalt x)).
(** A program will not get stuck for any fuel amount *)
(* This is used to exclude programs that may timeout for low fuel,
but they might get stuck later *)
Definition not_stuck (H : heap block) (rho : env) (e : exp) :=
forall c, exists r m, big_step H rho e r c m.
(* Diverging programs *)
(* Least upper bound for sets of natural numbers *)
Definition lub (m : natinf) (S : Ensemble nat) : Prop :=
(forall x, x \in S -> ni_le (ni x) m) /\
(forall y, (forall x, x \in S -> ni_le (ni x) y) -> ni_le m y).
Definition div_src (H : heap block) (rho : env) (e : exp) (m : natinf) :=
(forall i, exists m', big_step H rho e OOT i m' /\ ni_le (ni m') m).
Definition div_src' (H : heap block) (rho : env) (e : exp) (m : natinf) :=
(forall i, exists m, big_step H rho e OOT i m) /\
lub m [ set m : nat | exists r c, big_step H rho e r c m ].
(** Deterministic semantics with garbage collection, for closure converted code
* The execution time cost model does not account for the cost of GC *)
Inductive big_step_GC_cc :
heap block -> (* The heap. Maps locations to values *)
env -> (* The environment. Maps variables to locations *)
exp -> (* The expression to be evaluated *)
ans -> (* The final result, which is a pair of a location an a heap *)
nat -> (* Upper bound for the number of the evaluation steps *)
nat -> (* The maximum space required for the evaluation *)
Prop :=
| Eval_oot_per_cc :
forall (H : heap block) (rho : env) (e : exp) (c m : nat)
(Hcost : c < cost_cc e)
(Hsize : size_heap H = m),
(big_step_GC_cc H rho e OOT c m)
| Eval_constr_per_cc :
forall (H H' : heap block) (rho : env) (x : var) (t : cTag)
(ys :list var) (e : exp) (vs : list value) (l : loc) (r : ans)
(c m : nat)
(Hcost : c >= cost_cc (Econstr x t ys e))
(Hget : getlist ys rho = Some vs)
(Halloc : alloc (Constr t vs) H = (l, H'))
(Hbs : big_step_GC_cc H' (M.set x (Loc l) rho) e r (c - cost_cc (Econstr x t ys e)) m),
big_step_GC_cc H rho (Econstr x t ys e) r c m
| Eval_proj_per_cc : (* XXX Tag annotation in projections is redundant in this semantics *)
forall (H : heap block) (rho : env) (x : var) (t t' : cTag) (n : N)
(y : var) (e : exp) (l : loc) (v : value) (vs : list value)
(r : ans) (c m : nat)
(Hcost : c >= cost_cc (Eproj x t n y e))
(Hgety : M.get y rho = Some (Loc l))
(Hgetl : get l H = Some (Constr t' vs))
(Hnth : nthN vs n = Some v)
(Hbs : big_step_GC_cc H (M.set x v rho) e r (c - cost_cc (Eproj x t n y e)) m),
big_step_GC_cc H rho (Eproj x t n y e) r c m
| Eval_case_per_cc :
forall (H : heap block) (rho : env) (y : var) (cl : list (cTag * exp))
(l : loc) (t : cTag) (vs : list value) (e : exp) (r : ans) (c m : nat)
(Hcost : c >= cost_cc (Ecase y cl))
(Hgety : M.get y rho = Some (Loc l))
(Hgetl : get l H = Some (Constr t vs))
(Htag : findtag cl t = Some e)
(Hbs : big_step_GC_cc H rho e r (c - cost_cc (Ecase y cl)) m),
big_step_GC_cc H rho (Ecase y cl) r c m
| Eval_fun_per_cc :
forall (H : heap block) (rho rho' : env) (B : fundefs)
(e : exp) (r : ans) (c : nat) (m : nat)
(Hcost : c >= cost_cc (Efun B e))
(* add the functions in the environment *)
(Hfuns : def_funs B B rho = rho')
(Hbs : big_step_GC_cc H rho' e r (c - cost_cc (Efun B e)) m),
big_step_GC_cc H rho (Efun B e) r c m
| Eval_app_per_cc :
forall (H H' : heap block) (rho rho_clo : env) (B : fundefs)
(f f' : var) (ct : cTag) (xs : list var) (e : exp) b
(vs : list value) (ys : list var) (r : ans) (c : nat) (m m' : nat)
(Hcost : c >= cost_cc (Eapp f ct ys))
(Hgetf : M.get f rho = Some (FunPtr B f'))
(* Find the code *)
(Hfind : find_def f' B = Some (ct, xs, e))
(* Look up the actual parameters *)
(Hargs : getlist ys rho = Some vs)
(Hset : setlist xs vs (def_funs B B (M.empty _)) = Some rho_clo)
(* collect H' *)
(Hgc : live' ((env_locs rho_clo) (occurs_free e)) H H' b)
(Hsize : size_heap H = m')
(Hbs : big_step_GC_cc H' (subst_env b rho_clo) e r (c - cost_cc (Eapp f ct ys)) m),
big_step_GC_cc H rho (Eapp f ct ys) r c (max m m')
| Eval_halt_per_cc :
forall H rho x l c m
(Hcost : c >= cost_cc (Ehalt x))
(Hget : M.get x rho = Some l)
(Hsize : size_heap H = m),
big_step_GC_cc H rho (Ehalt x) (Res (l, H)) c m.
Definition not_stuck_cc (H : heap block) (rho : env) (e : exp) :=
forall c, exists r m, big_step_GC_cc H rho e r c m.
Definition div_trg (H : heap block) (rho : env) (e : exp) (m : natinf) :=
(forall i, exists m', big_step_GC_cc H rho e OOT i m' /\ ni_le (ni m') m).
Definition div_trg' (H : heap block) (rho : env) (e : exp) (m : natinf) :=
(forall i, exists m, big_step_GC_cc H rho e OOT i m) /\
lub m [ set m : nat | exists r c, big_step_GC_cc H rho e r c m ].
Definition is_res (r : ans) : Prop :=
match r with
| Res _ => True
| _ => False
end.
Lemma big_step_mem_cost_leq H rho e r c m :
big_step H rho e r c m ->
reach_size H rho e <= m.
Proof.
intros Hbs.
inv Hbs; eauto;
now eapply Nat_as_OT.le_max_l.
Qed.
(* not used *)
Lemma big_step_gc_heap_env_equiv_l H1 H2 β rho1 rho2 e (r : ans) c m :
big_step_GC H1 rho1 e r c m ->
(occurs_free e) |- (H1, rho1) ⩪_(β, id) (H2, rho2) ->
injective_subdomain (reach' H1 (env_locs rho1 (occurs_free e))) β ->
(exists r' m' β', big_step_GC H2 rho2 e r' c m' /\
injective_subdomain (reach_ans r') β' /\
ans_equiv β' r id r').
Abort.
Lemma big_step_reach_leq H1 rho1 e1 res c m :
big_step H1 rho1 e1 res c m ->
reach_size H1 rho1 e1 <= m.
Proof.
intros Hbs. inversion Hbs; eauto; try now eapply Nat_as_OT.le_max_l.
Qed.
(** Semantics commutes with heap equivalence *)
Lemma big_step_heap_env_equiv_r H1 H2 b1 rho1 rho2 e (r : ans) c m :
closed (reach' H1 (env_locs rho1 (occurs_free e))) H1 ->
big_step H1 rho1 e r c m ->
(occurs_free e) |- (H1, rho1) ⩪_(b1, id) (H2, rho2) ->
injective_subdomain (reach' H1 (env_locs rho1 (occurs_free e))) b1 ->
(exists r' b1' b2', big_step H2 rho2 e r' c m /\
injective_subdomain (reach_ans r) b1' /\
injective_subdomain (reach_ans r') b2' /\
ans_equiv b1' r b2' r').
Proof with (now eauto with Ensembles_DB).
revert H1 H2 b1 rho1 rho2 e r m.
induction c as [k IHk] using lt_wf_rec1.
intros H1 H2 b1 rho1 rho2 e r m Hclo Hbs Heq Hinj1.
destruct Hbs; subst.
- (* case OOT *)
eexists OOT. eexists id, id.
repeat split; eauto.
erewrite heap_env_equiv_reach_size. econstructor.
eassumption. eassumption. eassumption.
now eapply injective_subdomain_Empty_set.
now eapply injective_subdomain_Empty_set.
- edestruct heap_env_equiv_env_getlist as [vs' [Hlst Hall]]; try eassumption.
simpl. normalize_occurs_free...
destruct (alloc (Constr t vs') H2) as [l2 H2'] eqn:Halloc'.
assert (Hlt : c - cost (Econstr x t ys e) < c) by (simpl in *; omega).
specialize (IHk (c - cost (Econstr x t ys e)) Hlt
H' H2' (b1 {l ~> l2}) (M.set x (Loc l) rho)
(M.set x (Loc l2) rho2)).
edestruct IHk as (r2 & b1' & b2' & Hstep' & Hinj1' & Hinj2' & Hres).
+ eapply closed_set_alloc; [ | eassumption ].
rewrite occurs_free_Econstr in Hclo. simpl.
rewrite env_locs_Union in Hclo.
rewrite <- env_locs_FromList; [| eassumption ].
eassumption.
+ eassumption.
+ eapply heap_env_equiv_alloc with (b1 := (Constr t vs));
[ | | | | | | | | now apply Halloc' | | ].
* eassumption.
* eapply heap_env_equiv_preserves_closed; eassumption.
* eapply Included_trans; [| now eapply reach'_extensive ].
simpl. normalize_occurs_free.
eapply env_locs_monotonic...
* eapply Included_trans; [| now eapply reach'_extensive ].
simpl. normalize_occurs_free.
eapply env_locs_monotonic...
* simpl.
eapply Included_trans; [| now eapply reach'_extensive ].
normalize_occurs_free. rewrite env_locs_Union.
eapply Included_Union_preserv_l. rewrite env_locs_FromList.
reflexivity. eassumption.
* simpl.
eapply Included_trans; [| now eapply reach'_extensive ].
normalize_occurs_free. rewrite env_locs_Union.
eapply Included_Union_preserv_l. rewrite env_locs_FromList.
reflexivity. eassumption.
* eapply heap_env_equiv_antimon.
eapply heap_env_equiv_rename_ext. eassumption.
eapply f_eq_subdomain_extend_not_In_S_r.
intros Hc. eapply reachable_in_dom in Hc.
destruct Hc as [vc Hgetc].
erewrite alloc_fresh in Hgetc; eauto. congruence.
eapply well_formed'_closed. eassumption.
eapply Included_trans. eapply reach'_extensive.
eapply env_locs_closed. eassumption.
reflexivity. reflexivity. normalize_occurs_free...
* eassumption.
* rewrite extend_gss. reflexivity.
* split. reflexivity.
eapply Forall2_monotonic_strong; try eassumption.
intros x1 x2 Hin1 Hin2 Heq'.
eapply res_equiv_rename_ext. eapply Heq'.
eapply f_eq_subdomain_extend_not_In_S_r.
intros Hc. eapply reachable_in_dom in Hc.
destruct Hc as [vc Hgetc].
erewrite alloc_fresh in Hgetc; eauto. congruence.
eapply well_formed_antimon; [| eapply well_formed'_closed; eassumption ].
eapply reach'_set_monotonic.
normalize_occurs_free. rewrite env_locs_Union. eapply Included_Union_preserv_l.
rewrite env_locs_FromList.
eapply In_Union_list. eapply in_map. eassumption.
eassumption.
eapply Included_trans; [| eapply env_locs_closed; eassumption ].
eapply Included_trans; [| eapply reach'_extensive ].
normalize_occurs_free. rewrite env_locs_Union. eapply Included_Union_preserv_l.
rewrite env_locs_FromList.
eapply In_Union_list. eapply in_map. eassumption.
eassumption.
reflexivity. reflexivity.
+ eapply injective_subdomain_antimon.
eapply injective_subdomain_extend. eassumption.
intros Hc. eapply image_monotonic in Hc; [| now eapply Setminus_Included ].
eapply heap_env_equiv_image_reach in Hc; try (symmetry; eassumption).
destruct Hc as [l2' [Hin Heq2]].
unfold id in *; subst.
eapply reachable_in_dom in Hin; try eassumption. destruct Hin as [v1' Hgetv1'].
erewrite alloc_fresh in Hgetv1'; try eassumption. congruence.
eapply well_formed_respects_heap_env_equiv.
eapply well_formed'_closed. eassumption.
eassumption.
eapply env_locs_in_dom. eassumption.
eapply Included_trans; [| eapply env_locs_closed; eassumption ].
eapply reach'_extensive.
eapply Included_trans. eapply reach'_set_monotonic. eapply env_locs_monotonic.
eapply occurs_free_Econstr_Included.
eapply reach'_alloc_set; [| eassumption ].
eapply Included_trans; [| eapply reach'_extensive ].
simpl. normalize_occurs_free. rewrite env_locs_Union.
eapply Included_Union_preserv_l.
rewrite env_locs_FromList. reflexivity.
eassumption.
+ do 3 eexists. split; eauto.
erewrite heap_env_equiv_reach_size; [| eassumption | eassumption ].
eapply Eval_constr; [| | | | eassumption ]; eassumption.
- (* case Eproj *)
assert (Hgety' := Hgety). eapply Heq in Hgety; [| now constructor ].
destruct Hgety as [l' [Hget' Heql]].
rewrite res_equiv_eq in Heql. destruct l' as [l' |]; try contradiction.
destruct Heql as [Hbeq Heql].
simpl in Heql. unfold id in *; subst. rewrite Hgetl in Heql.
destruct (get (b1 l) H2) eqn:Hgetl'; try contradiction.
destruct b as [c' vs'| | ]; try contradiction.
destruct Heql as [Heqt Hall]; subst.
edestruct (Forall2_nthN _ vs vs' _ _ Hall Hnth) as [v' [Hnth' Hv]].
assert (Hlt : c - cost (Eproj x t n y e) < c) by (simpl in *; omega).
specialize (IHk (c - cost (Eproj x t n y e)) Hlt
H H2 b1 (M.set x v rho)
(M.set x v' rho2) e).
edestruct IHk as (r2 & b1' & b2' & Hstep' & Hinj1' & Hinj2' & Hres).
+ eapply reach'_closed.
eapply well_formed_antimon; [| eapply well_formed'_closed; eassumption ].
rewrite (reach'_idempotent H (env_locs rho _)). eapply reach'_set_monotonic.
eapply Included_trans. eapply env_locs_set_Inlcuded'.
normalize_occurs_free. rewrite env_locs_Union, reach'_Union. eapply Included_Union_compat.
rewrite env_locs_Singleton; [| eassumption ]. simpl.
rewrite reach_unfold. rewrite post_Singleton; [| eassumption ].
eapply Included_Union_preserv_r. eapply Included_trans; [| eapply reach'_extensive ].
eapply In_Union_list. eapply in_map.
eapply nthN_In; eassumption.
now eapply reach'_extensive.
eapply Included_trans; [| eapply env_locs_closed; eassumption ].
eapply Included_trans. eapply env_locs_set_Inlcuded'.
normalize_occurs_free. rewrite env_locs_Union, reach'_Union. eapply Included_Union_compat.
rewrite env_locs_Singleton; [| eassumption ]. simpl.
rewrite reach_unfold. rewrite post_Singleton; [| eassumption ].
eapply Included_Union_preserv_r. eapply Included_trans; [| eapply reach'_extensive ].
eapply In_Union_list. eapply in_map.
eapply nthN_In; eassumption.
now eapply reach'_extensive.
+ eassumption.
+ eapply heap_env_equiv_set; try eassumption.
eapply heap_env_equiv_antimon. eassumption.
simpl. normalize_occurs_free...
+ eapply injective_subdomain_antimon. eassumption.
simpl. normalize_occurs_free.
rewrite env_locs_Union, reach'_Union.
eapply Included_trans.
eapply reach'_set_monotonic. eapply env_locs_set_Inlcuded'.
rewrite reach'_Union.
eapply Included_Union_compat; [| reflexivity ].
rewrite (reach_unfold H (env_locs rho [set y])).
eapply Included_Union_preserv_r.
eapply reach'_set_monotonic.
rewrite env_locs_Singleton; try eassumption.
simpl. rewrite post_Singleton; try eassumption.
simpl.
eapply In_Union_list. eapply in_map.
eapply nthN_In; eassumption.
+ do 3 eexists. split; eauto.
erewrite heap_env_equiv_reach_size; [| eassumption | eassumption ].
econstructor; eauto.
- (* case Ecase *)
assert (Hgety' := Hgety). eapply Heq in Hgety; [| now constructor ].
destruct Hgety as [l' [Hget' Heql]].
rewrite res_equiv_eq in Heql. destruct l' as [l' |]; try contradiction.
destruct Heql as [Hbeq Heql].
simpl in Heql. unfold id in *; subst. rewrite Hgetl in Heql.
destruct (get (b1 l) H2) eqn:Hgetl'; try contradiction.
destruct b as [c' vs'| | ]; try contradiction.
destruct Heql as [Heqt Hall]; subst.
(* edestruct (Forall2_nthN _ vs vs' _ _ Hall Hnth) as [v' [Hnth' Hv]]. *)
assert (Hlt : c - cost (Ecase y cl) < c) by (simpl in *; omega).
specialize (IHk (c - (cost (Ecase y cl))) Hlt
H H2 b1 rho rho2 e).
edestruct IHk as (r2 & b1' & b2' & Hstep' & Hinj1' & Hinj2' & Hres).
+ eapply reach'_closed.
eapply well_formed_antimon; [| eapply well_formed'_closed; eassumption ].
eapply reach'_set_monotonic. eapply env_locs_monotonic.
eapply occurs_free_Ecase_Included. eapply findtag_In. eassumption.
eapply Included_trans; [| eapply env_locs_closed; eassumption ].
eapply Included_trans; [| eapply reach'_extensive ].
eapply env_locs_monotonic.
eapply occurs_free_Ecase_Included. eapply findtag_In. eassumption.
+ eassumption.
+ eapply heap_env_equiv_antimon. eassumption.
eapply occurs_free_Ecase_Included. eapply findtag_In. eassumption.
+ eapply injective_subdomain_antimon. eassumption.
eapply reach'_set_monotonic. eapply env_locs_monotonic.
eapply occurs_free_Ecase_Included. eapply findtag_In. eassumption.
+ do 3 eexists. split; eauto.
erewrite heap_env_equiv_reach_size; [| eassumption | eassumption ].
econstructor; eauto.
- (* case Efun *)
destruct (alloc (Env (restrict_env (fundefs_fv B) rho2)) H2) as [lenv2 H2'] eqn:Ha'.
destruct (def_closures B B rho2 H2' (Loc lenv2)) as [H2'' rho2'] eqn:Hdef.
assert (Hlocs : locs (Env (restrict_env (fundefs_fv B) rho)) \subset reach' H (env_locs rho (occurs_free (Efun B e)))).
{ simpl. eapply Included_trans. eapply restrict_env_env_locs.
eapply restrict_env_correct. reflexivity.
eapply Included_trans; [| eapply reach'_extensive ].
eapply env_locs_monotonic. normalize_occurs_free. eapply Included_Union_preserv_l.
rewrite fundefs_fv_correct. reflexivity. }
assert (Hca : closed (reach' H' (env_locs rho (occurs_free (Efun B e)))) H').
{ rewrite reach'_alloc; [| eassumption | eassumption ].
eapply closed_alloc'; eassumption. }
assert (Heqa : (occurs_free (Efun B e)) |- (H', rho) ⩪_(b1 {lenv ~> lenv2}, id) (H2', rho2)).
{ eapply heap_env_equiv_weaking'. now eapply Hclo.
eapply heap_env_equiv_preserves_closed. eassumption. eassumption.
now eapply reach'_extensive.
now eapply reach'_extensive.
eapply heap_env_equiv_rename_ext. eassumption.
eapply f_eq_subdomain_extend_not_In_S_r.
intros Hc. eapply reachable_in_dom in Hc.
destruct Hc as [vc Hgetc].
erewrite alloc_fresh in Hgetc; eauto. congruence.
eapply well_formed'_closed. eassumption.
eapply Included_trans. eapply reach'_extensive.
eapply env_locs_closed. eassumption.
reflexivity. reflexivity.
eapply HL.alloc_subheap. eassumption.
eapply HL.alloc_subheap. eassumption. }
edestruct (heap_env_equiv_def_funs_strong_left (name_in_fundefs B :|: occurs_free (Efun B e))
(b1 {lenv ~> lenv2}) H' H2')
as [d1 [Hequiv Hlet]].
+ eapply well_formed_antimon; [| eapply well_formed'_closed; eassumption ].
eapply reach'_set_monotonic. eapply env_locs_monotonic.
now eauto with Ensembles_DB.
+ eapply Included_trans; [| eapply dom_subheap; eapply HL.alloc_subheap; eassumption ].
eapply Included_trans; [| eapply env_locs_closed; eassumption ].
eapply Included_trans; [| eapply reach'_extensive ]. eapply env_locs_monotonic.
now eauto with Ensembles_DB.
+ erewrite gas. reflexivity. eassumption.
+ erewrite gas. reflexivity. eassumption.
+ eapply Included_trans. eapply restrict_env_env_locs.
eapply restrict_env_correct. reflexivity.
eapply Included_trans; [| eapply reach'_extensive ].
eapply env_locs_monotonic. normalize_occurs_free. rewrite !Setminus_Union_distr.
eapply Included_Union_preserv_r. eapply Included_Union_preserv_l. rewrite <- Included_Setminus_Disjoint.
rewrite fundefs_fv_correct. reflexivity.
eapply Disjoint_sym. eapply occurs_free_fundefs_name_in_fundefs_Disjoint.
+ eapply Included_trans. eapply restrict_env_env_locs.
eapply restrict_env_correct. reflexivity.
eapply Included_trans; [| eapply reach'_extensive ].
eapply env_locs_monotonic. normalize_occurs_free. rewrite !Setminus_Union_distr.
eapply Included_Union_preserv_r. eapply Included_Union_preserv_l. rewrite <- Included_Setminus_Disjoint.
rewrite fundefs_fv_correct. reflexivity.
eapply Disjoint_sym. eapply occurs_free_fundefs_name_in_fundefs_Disjoint.
+ normalize_occurs_free. rewrite !Setminus_Union_distr.
eapply Included_Union_preserv_r. eapply Included_Union_preserv_l. rewrite <- Included_Setminus_Disjoint.
reflexivity.
eapply Disjoint_sym. eapply occurs_free_fundefs_name_in_fundefs_Disjoint.
+ rewrite res_equiv_eq. split.
rewrite extend_gss. reflexivity.
do 2 (erewrite gas; eauto). simpl.
eapply heap_env_equiv_restrict_env.
eassumption. normalize_occurs_free. eapply Included_Union_preserv_l.
now eapply fundefs_fv_correct.
eapply restrict_env_correct. reflexivity.
eapply restrict_env_correct. reflexivity.
+ rewrite reach'_alloc; [| eassumption |].
eapply injective_subdomain_extend.
eapply injective_subdomain_antimon. eassumption.
eapply reach'_set_monotonic. eapply env_locs_monotonic...
intros Hc.
eapply image_monotonic in Hc. eapply heap_env_equiv_image_reach in Hc; try (symmetry; eassumption).
rewrite image_id in Hc. eapply reachable_in_dom in Hc.
destruct Hc as [vc Hgetc].
erewrite alloc_fresh in Hgetc; eauto. congruence.
eapply well_formed'_closed.
eapply heap_env_equiv_preserves_closed; eassumption.
eapply Included_trans. eapply reach'_extensive.
eapply env_locs_closed.
eapply heap_env_equiv_preserves_closed; eassumption.
eapply Setminus_Included_preserv. eapply reach'_set_monotonic.
eapply env_locs_monotonic...
simpl.
eapply Included_trans. eapply restrict_env_env_locs.
eapply restrict_env_correct. reflexivity.
eapply Included_trans; [| eapply reach'_extensive ].
eapply env_locs_monotonic. normalize_occurs_free. rewrite !Setminus_Union_distr.
eapply Included_Union_preserv_r. eapply Included_Union_preserv_l.
rewrite <- Included_Setminus_Disjoint.
rewrite fundefs_fv_correct. reflexivity.
eapply Disjoint_sym. eapply occurs_free_fundefs_name_in_fundefs_Disjoint.
+ eapply heap_env_equiv_antimon...
+ rewrite Hfuns, Hdef in Hlet.
destruct Hlet as (Hwf1 & Hwf2 & Hl1 & Hl2 & Hinj).
assert (Hlt : c - cost (Efun B e) < c) by (simpl in *; omega).
specialize (IHk (c - cost (Efun B e)) Hlt
H'' H2'' d1 rho' rho2' e).
edestruct IHk as (r2 & b1' & b2' & Hstep' & Hinj1' & Hinj2' & Hres).
* eapply reach'_closed.
eapply well_formed_antimon; [| eassumption ].
eapply reach'_set_monotonic. eapply env_locs_monotonic.
normalize_occurs_free. rewrite !Union_assoc.
now rewrite Union_Setminus_Included; eauto with Ensembles_DB typeclass_instances.
eapply Included_trans; [| eassumption ].
eapply env_locs_monotonic.
normalize_occurs_free. rewrite !Union_assoc.
now rewrite Union_Setminus_Included; eauto with Ensembles_DB typeclass_instances.
* eassumption.
* rewrite Hdef, Hfuns in Hequiv.
eapply heap_env_equiv_antimon. eassumption.
normalize_occurs_free. rewrite !Union_assoc.
now rewrite Union_Setminus_Included; eauto with Ensembles_DB typeclass_instances.
* eapply injective_subdomain_antimon. eassumption. normalize_occurs_free.
eapply Included_Union_preserv_r. eapply reach'_set_monotonic.
eapply env_locs_monotonic.
rewrite !Union_assoc.
now rewrite Union_Setminus_Included; eauto with Ensembles_DB typeclass_instances.
* do 3 eexists. repeat split; eauto.
erewrite heap_env_equiv_reach_size; [| eassumption | eassumption ].
econstructor; eauto.
- (* case Eapp *)
edestruct heap_env_equiv_env_getlist as [vs' [Hlst Hall]]; try eassumption.
simpl. normalize_occurs_free...
edestruct heap_env_equiv_env_get as [lf [Hgetf' Heqf]]. eassumption.
eassumption. normalize_occurs_free...
destruct lf as [l' |]; [| rewrite res_equiv_eq in Heqf; contradiction ].
assert (Hlt : c - cost (Eapp f t ys) < c) by (simpl in *; omega).
assert (Heqf' := Heqf).
rewrite res_equiv_eq in Heqf. destruct Heqf as [Hbeq Hres].
rewrite Hgetl in Hres.
destruct (get l' H2) as [b2 |] eqn:Hgetl'; try contradiction.
simpl in Hres. destruct b2 as [| v1' v2' |]; try contradiction.
destruct Hres as [Hres1 Hres2].
rewrite res_equiv_eq in Hres1. destruct v1'; try contradiction. simpl in Hres1.
destruct Hres1; subst.
rewrite res_equiv_eq in Hres2. destruct v2'; try contradiction. simpl in Hres2.
destruct Hres2 as [Heq2 Hres2]; unfold id in *; subst.
rewrite Hgetenv in Hres2.
destruct (get (b1 lenv) H2) as [b2 |] eqn:Hgetenv'; try contradiction.
destruct b2 as [| | rho_clo' ]; try contradiction.
assert (Hincl1 : env_locs rho_clo (Full_set _) \subset
reach' H (env_locs rho (occurs_free (Eapp f t ys)))).
{ normalize_occurs_free. rewrite env_locs_Union, reach'_Union.
rewrite env_locs_Singleton; eauto. simpl. eapply Included_Union_preserv_r.
rewrite reach_unfold. eapply Included_Union_preserv_r.
rewrite post_Singleton; eauto. simpl. rewrite Union_Empty_set_neut_l.
rewrite reach_unfold. eapply Included_Union_preserv_r.
rewrite post_Singleton; eauto. simpl.
now eapply reach'_extensive. }
assert (Hincl1' : env_locs rho_clo (FromList ys :|: occurs_free_fundefs f0 \\ name_in_fundefs f0) \subset
reach' H (env_locs rho (occurs_free (Eapp f t ys)))).
{ eapply Included_trans; [| eassumption ]. eapply env_locs_monotonic... }
assert (Hincl2 : env_locs rho_clo' (Full_set _) \subset
reach' H2 (env_locs rho2 (occurs_free (Eapp f t ys)))).
{ normalize_occurs_free. rewrite env_locs_Union, reach'_Union.
rewrite env_locs_Singleton; eauto. simpl. eapply Included_Union_preserv_r.
rewrite reach_unfold. eapply Included_Union_preserv_r.
rewrite post_Singleton; eauto. simpl. rewrite Union_Empty_set_neut_l.
rewrite reach_unfold. eapply Included_Union_preserv_r.
rewrite post_Singleton; eauto. simpl.
now eapply reach'_extensive. }
edestruct (heap_env_equiv_def_funs_strong_left_alt (Full_set _)
b1 H H2 rho_clo rho_clo')
as [d1 [Hequiv Hlet]].
+ eapply well_formed_antimon; [| eapply well_formed'_closed; eassumption ].
rewrite (reach'_idempotent H (env_locs rho _)). eapply reach'_set_monotonic.
eassumption.
+ eapply Included_trans; [| eapply env_locs_closed; eassumption ]; eassumption.
+ eassumption.
+ eassumption.
+ eapply reach'_extensive.
+ eapply reach'_extensive.
+ now eauto with Ensembles_DB.
+ rewrite res_equiv_eq. split.
reflexivity. rewrite Hgetenv, Hgetenv'. simpl. eassumption.
+ eapply injective_subdomain_antimon. eassumption.
eapply Union_Included.
* eapply Singleton_Included. eexists 1. split.
now constructor.
simpl. eexists. eexists. split.
eapply get_In_env_locs. normalize_occurs_free. now right.
eassumption. reflexivity.
split; eauto. now right.
* rewrite (reach'_idempotent H (env_locs rho _)). eapply reach'_set_monotonic.
eassumption.
+ eapply heap_env_equiv_antimon; [ eassumption |]...
+ rewrite Hredef in Hlet.
destruct (def_closures f0 f0 rho_clo' H2 (Loc (b1 lenv))) as [H2' rho2'] eqn:Hredef'.
destruct (setlist_length3 rho2' xs vs') as [rho2'' Hset''].
erewrite setlist_length_eq; try eassumption.
eapply Forall2_length. eassumption.
destruct Hlet as (Hfeq & Hwf1 & Hwf2 & Hl1 & Hl2 & Hinj).
rewrite Hredef in Hequiv.
assert (Hequiv' := Hequiv).
symmetry in Hequiv. eapply heap_env_approx_heap_equiv in Hequiv.
eapply heap_equiv_symm in Hequiv.
assert (Himeq := heap_env_equiv_image_post_n _ _ _ _ _ _ _ 0 Hequiv').
rewrite image_id in Himeq. simpl in Himeq.
assert (Heqset : occurs_free e |- (H', rho_clo2) ⩪_(d1, id) (H2', rho2'')).
{ eapply heap_env_equiv_setlist; try eassumption.
- eapply heap_env_equiv_antimon. eassumption.
rewrite Union_Same_set; now eauto with Ensembles_DB.
- eapply Forall2_monotonic_strong; [| eassumption ]. simpl.
intros x1 x2 Hinx1 Hinx2 Hreseq. eapply res_equiv_weakening.
now eapply Hclo. eapply heap_env_equiv_preserves_closed; [| now eapply Hclo ].
eassumption.
eapply res_equiv_rename_ext. eassumption.
eapply f_eq_subdomain_antimon; [| eassumption ].
eapply Included_trans; [| eapply env_locs_closed; eassumption ].
eapply reach'_set_monotonic. normalize_occurs_free. rewrite env_locs_Union.
eapply Included_Union_preserv_l. rewrite env_locs_FromList; [| eassumption ].
eapply In_Union_list. eapply in_map. eassumption.
reflexivity.
eapply def_funs_subheap. now eauto.
eapply def_funs_subheap. now eauto.
normalize_occurs_free. rewrite env_locs_Union, reach'_Union. eapply Included_Union_preserv_l.
rewrite env_locs_FromList; [| eassumption ].
eapply Included_trans; [| eapply reach'_extensive ].
eapply In_Union_list. eapply in_map. eassumption.
normalize_occurs_free. rewrite env_locs_Union, reach'_Union. eapply Included_Union_preserv_l.
rewrite env_locs_FromList; [| eassumption ].
eapply Included_trans; [| eapply reach'_extensive ].
eapply In_Union_list. eapply in_map. eassumption. }
specialize (IHk (c - cost (Eapp f t ys)) Hlt H' H2' d1 rho_clo2 rho2'' e).
edestruct IHk as (r2 & b1' & b2' & Hstep' & Hinj1' & Hinj2' & Hres).
* { eapply reach'_closed.
-
eapply well_formed_antimon.
eapply Included_trans. eapply reach'_set_monotonic.
eapply env_locs_monotonic.
eapply occurs_free_in_fun. eapply find_def_correct. eassumption.
reflexivity.
rewrite Union_commut.
eapply well_formed_reach_setlist; try eassumption.
+ eapply well_formed_antimon; [| eassumption ]. eapply reach'_set_monotonic.
eapply env_locs_monotonic; eapply Included_Union_compat...
+ eapply well_formed_subheap.
rewrite <- well_formed_reach_subheap_same.
eapply well_formed_antimon; [| eapply well_formed'_closed; now eapply Hclo ].
eapply reach'_set_monotonic.
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free...
eapply well_formed_antimon; [| eapply well_formed'_closed; now eapply Hclo ].
eapply reach'_set_monotonic.
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free...
eapply Included_trans; [| eapply env_locs_closed; now eapply Hclo ].
eapply Included_trans; [| now eapply reach'_extensive ].
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free...
eapply def_funs_subheap. now eauto.
rewrite <- well_formed_reach_subheap_same.
eapply Included_trans; [| eapply env_locs_closed; now eapply Hclo ].
eapply reach'_set_monotonic.
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free...
eapply well_formed_antimon; [| eapply well_formed'_closed; now eapply Hclo ].
eapply reach'_set_monotonic.
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free...
eapply Included_trans; [| eapply env_locs_closed; now eapply Hclo ].
eapply Included_trans; [| now eapply reach'_extensive ].
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free...
eapply def_funs_subheap. now eauto.
eapply def_funs_subheap. now eauto.
- eapply Included_trans. eapply env_locs_monotonic.
eapply occurs_free_in_fun. eapply find_def_correct. eassumption.
eapply Included_trans.
rewrite Union_commut. eapply env_locs_setlist_Included.
eassumption.
eapply Union_Included.
+ eapply Included_trans; [| eassumption ]. eapply env_locs_monotonic.
eapply Included_Union_compat...
+ eapply Included_trans; [| eapply dom_subheap; eapply def_funs_subheap; now eauto ].
eapply Included_trans; [| eapply env_locs_closed; now eapply Hclo ].
eapply Included_trans; [| now eapply reach'_extensive ].
rewrite <- env_locs_FromList; [| eassumption ].
eapply env_locs_monotonic. normalize_occurs_free... }
* eassumption.
* eassumption.
* assert (Hincl : reach' H
(lenv
|: (env_locs rho_clo1 (occurs_free_fundefs f0 \\ name_in_fundefs f0)
:|: Union_list (map val_loc vs))) \subset
reach' H (env_locs rho (occurs_free (Eapp f t ys)))).
{ rewrite !reach'_Union. eapply Union_Included; [| eapply Union_Included ].
* normalize_occurs_free. rewrite !env_locs_Union, reach'_Union.
rewrite env_locs_Singleton; eauto. eapply Included_Union_preserv_r.
rewrite (reach_unfold H (val_loc _)).
eapply Included_Union_preserv_r.
simpl. rewrite post_Singleton; eauto. eapply reach'_set_monotonic...
* rewrite (reach'_idempotent H (env_locs rho (occurs_free (Eapp f t ys)))).
eapply reach'_set_monotonic. eapply Included_trans.
eapply env_locs_def_funs. reflexivity. now eauto.
eapply Included_trans. eapply env_locs_monotonic with (S2 := Full_set _)...
eassumption.
* rewrite <- env_locs_FromList; [| eassumption ].
apply reach'_set_monotonic. eapply env_locs_monotonic. normalize_occurs_free... }
{ eapply injective_subdomain_antimon;
[| eapply reach'_set_monotonic; eapply env_locs_monotonic;
eapply occurs_free_in_fun; eapply find_def_correct; eassumption ].
rewrite Union_commut.
eapply injective_subdomain_antimon;
[| eapply reach'_set_monotonic; eapply env_locs_setlist_Included; try eassumption ].
rewrite reach'_Union. rewrite <- (Union_Setminus_Included (name_in_fundefs f0)); [| | reflexivity ]; tci.
rewrite !env_locs_Union, !reach'_Union, <- !Union_assoc. rewrite reach_unfold.
eapply injective_subdomain_antimon;
[| eapply Included_Union_compat; [| reflexivity ];
eapply Included_Union_compat; [ reflexivity | eapply reach'_set_monotonic;
eapply def_closures_post; eauto ] ].
rewrite <- Union_assoc, <- !reach'_Union. simpl.
rewrite <- well_formed_reach_subheap_same; [ | | | eapply def_funs_subheap; now eauto ].
eapply injective_subdomain_Union.
- eapply injective_subdomain_antimon. eassumption.
eapply Included_Union_preserv_r.
eapply Included_trans; [| eapply reach'_extensive ].
eapply env_locs_monotonic...
- eapply injective_subdomain_f_eq_subdomain.
+ eapply injective_subdomain_antimon. now eapply Hinj1. eassumption.
+ eapply f_eq_subdomain_antimon; [| eassumption ].
eapply reachable_in_dom.
* eapply well_formed_antimon; [| eapply well_formed'_closed; now eapply Hclo ].
eassumption.
* eapply Included_trans; [| eapply env_locs_closed; now eapply Hclo ].
eapply Included_trans. eapply reach'_extensive. eassumption.
- eapply Disjoint_Included_r. eapply image_monotonic. eassumption.
rewrite (image_f_eq_subdomain d1 b1 (reach' H (env_locs rho (occurs_free (Eapp f t ys))))).
rewrite heap_env_equiv_image_reach; [| eassumption ]. rewrite image_id.
assert (Himeq1 := heap_env_equiv_image_post_n (name_in_fundefs f0) d1 id H' H2' rho_clo1 rho2' 0).
simpl in Himeq1. rewrite image_id in Himeq1. rewrite Himeq1.
eapply Disjoint_Included_r; [| eapply def_closures_env_locs_Disjoint; now eauto ].
eapply reachable_in_dom.
+ eapply well_formed'_closed.
eapply heap_env_equiv_preserves_closed; eassumption.
+ eapply Included_trans. eapply reach'_extensive. eapply env_locs_closed.
eapply heap_env_equiv_preserves_closed; eassumption.
+ eapply heap_env_equiv_antimon; [ eassumption |]...
+ eapply f_eq_subdomain_antimon; [| symmetry; eassumption ].
eapply in_dom_closed. eassumption.
- eapply well_formed_antimon. eassumption.
eapply well_formed'_closed. eassumption.
- eapply Included_trans. eapply reach'_extensive.
eapply Included_trans. eassumption.
eapply in_dom_closed. eassumption. }
* do 3 eexists. split; [| split; [| split ]; eassumption ].
erewrite heap_env_equiv_reach_size; [| eassumption | eassumption ].
eapply Eval_app; eassumption.