-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFm_Immutability.v
895 lines (855 loc) · 36.4 KB
/
Fm_Immutability.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
(** Lemmas on re-sealing and typing and single-step immutability safety
Authors: Edward Lee, Ondrej Lhotak
This work is based off the POPL'08 Coq tutorial
authored by: Brian Aydemir and Arthur Chargu\'eraud, with help from
Aaron Bohannon, Jeffrey Vaughan, and Dimitrios Vytiniotis.
This file contains the main proofs concerning results around
immutability -- namely, when if a term is well-typed,
subterms which are typed readonly can be sealed to no ill effect.
- #<a href="##lemma_5.1">Lemma 5.1</a>#
- #<a href="##lemma_5.5">Lemma 5.5</a>#
- #<a href="##lemma_5.6">Lemma 5.6</a>#
- #<a href="##lemma_5.7">Lemma 5.7</a>#
- #<a href="##lemma_5.11">Lemma 5.11</a>#
*)
Require Export Fsub.Fm_Soundness.
(** #<a name="lemma_5.1"></a># Lemma 5.1: Terms can be transparently sealed without affecting typing. *)
Lemma readonly_term_can_be_sealed_transparently : forall E R e T,
typing E R e (typ_mut mut_readonly T) ->
typing E R (exp_seal e) (typ_mut mut_readonly T).
Proof with simpl in *; autorewrite with core in *; eauto 4 using sub_reflexivity;
repeat (fold merge_mutability in *; fold normal_form_typing in *).
intros * Typ.
apply typing_seal in Typ.
eapply typing_sub...
eapply sub_denormalize...
apply sub_reflexivity...
apply wf_typ_merge_mutability...
Qed.
(** #<a name="lemma_5.11"></a># Lemma 5.11: Seals can be transparently removed without affecting typing as well. *)
Lemma term_can_be_given_same_type_as_seal : forall E R e T,
typing E R (exp_seal e) T ->
typing E R e T.
Proof with eauto using sub_reflexivity.
intros * Typ.
dependent induction Typ; subst...
Qed.
(**
We need a notion of store consistency to prove that reduction
takes the same steps; all locations must be the same even
if they do not store the same values.
*)
Definition consistent_store (s s' : store) :=
forall l, (LabelMapImpl.In l s) <-> (LabelMapImpl.In l s').
Lemma consistent_store_symmetric : forall s s',
consistent_store s s' <-> consistent_store s' s.
Proof with eauto.
intros. unfold consistent_store... intuition;
destruct (H l)...
Qed.
#[export] Hint Resolve consistent_store_symmetric : core.
(**
...as we need to show that after reduction if two stores
were consistent they still are consistent as the
fresh label generated for both was the same label.
*)
Lemma consistent_fresh_label_for_store : forall s ns,
consistent_store s ns ->
fresh_label_for_store s = fresh_label_for_store ns.
Proof with eauto.
intros * InEquiv; unfold consistent_store in InEquiv.
assert (forall l, In l (List.map fst (LabelMapImpl.elements s)) <->
In l (List.map fst (LabelMapImpl.elements ns))) as Equiv.
intros; repeat rewrite <- label_map_in_iff_keys in *...
unfold fresh_label_for_store, exists_fresh_label_for_store; simpl.
apply Label.fresh_permute...
Qed.
(* ********************************************************************** *)
(** * #<a name="sealcomp"></a># Properties of [sealcomp] *)
Lemma sealcomp_reflexive : forall e,
sealcomp e e
with sealcomp_rec_comp_reflexive : forall r,
sealcomp_rec_comp r r.
Proof with eauto.
------
clear sealcomp_reflexive.
induction e...
------
clear sealcomp_rec_comp_reflexive.
induction r...
Qed.
#[export] Hint Resolve sealcomp_reflexive : core.
Lemma sealcomp_transitive : forall e f g,
sealcomp e f ->
sealcomp f g ->
sealcomp e g
with sealcomp_rec_comp_transitive : forall e f g,
sealcomp_rec_comp e f ->
sealcomp_rec_comp f g ->
sealcomp_rec_comp e g.
Proof with eauto.
------
clear sealcomp_transitive.
intros * eLf fLg.
dependent induction e; dependent induction f; dependent induction g;
try solve [inversion eLf; inversion fLg; eauto 4].
all : inversion fLg; subst; econstructor...
------
clear sealcomp_rec_comp_transitive.
intros * eLf fLg.
dependent induction e; dependent induction f; dependent induction g;
try solve [inversion eLf; inversion fLg; eauto 4].
Qed.
Lemma sealcomp_inversion : forall e f,
sealcomp (exp_seal e) f ->
sealcomp e f.
Proof with eauto.
intros * Seal.
dependent induction Seal...
Qed.
#[export] Hint Resolve sealcomp_inversion : core.
(* ********************************************************************** *)
(** * #<a name="sealcomp_open"></a># Properties of [sealcomp] under opening *)
Lemma sealcomp_open_ee_rec : forall k e1 e2 v1 v2,
sealcomp e1 e2 ->
sealcomp v1 v2 ->
sealcomp (open_ee_rec k v1 e1) (open_ee_rec k v2 e2)
with sealcomp_rec_comp_open_ee_rec : forall k e1 e2 v1 v2,
sealcomp_rec_comp e1 e2 ->
sealcomp v1 v2 ->
sealcomp_rec_comp (open_ee_record_rec k v1 e1) (open_ee_record_rec k v2 e2).
Proof with eauto.
------
clear sealcomp_open_ee_rec.
intros * e1Le2 v1Lv2.
generalize dependent k.
dependent induction e1Le2; intros; simpl...
+ destruct (k == n)...
------
clear sealcomp_rec_comp_open_ee_rec.
intros * e1Le2 v1Lv2.
generalize dependent k.
dependent induction e1Le2; intros...
+ econstructor...
+ econstructor...
Qed.
#[export] Hint Resolve sealcomp_open_ee_rec : core.
Lemma sealcomp_open_ee : forall e1 e2 v1 v2,
sealcomp e1 e2 ->
sealcomp v1 v2 ->
sealcomp (open_ee e1 v1) (open_ee e2 v2).
Proof with eauto.
intros... apply sealcomp_open_ee_rec...
Qed.
#[export] Hint Resolve sealcomp_open_ee : core.
Lemma sealcomp_open_te_rec : forall k e1 e2 T,
sealcomp e1 e2 ->
sealcomp (open_te_rec k T e1) (open_te_rec k T e2)
with sealcomp_rec_comp_open_te_rec : forall k e1 e2 T,
sealcomp_rec_comp e1 e2 ->
sealcomp_rec_comp (open_te_record_rec k T e1) (open_te_record_rec k T e2).
Proof with eauto.
------
clear sealcomp_open_te_rec.
intros * e1Le2.
generalize dependent k.
dependent induction e1Le2; intros; simpl...
------
clear sealcomp_rec_comp_open_te_rec.
intros * e1Le2.
generalize dependent k.
dependent induction e1Le2; intros...
+ econstructor...
+ econstructor...
Qed.
#[export] Hint Resolve sealcomp_open_te_rec : core.
Lemma sealcomp_open_te : forall e1 e2 T,
sealcomp e1 e2 ->
sealcomp (open_te e1 T) (open_te e2 T).
Proof with eauto.
intros... eapply sealcomp_open_te_rec...
Qed.
#[export] Hint Resolve sealcomp_open_te : core.
(* ********************************************************************** *)
(** * #<a name="sealcomp_store"></a># Properties of [sealcomp_store] *)
Lemma sealcomp_store_reflexive : forall s,
sealcomp_store s s.
Proof with eauto.
intros. split...
Qed.
#[export] Hint Resolve sealcomp_store_reflexive : core.
Lemma sealcomp_store_transitive : forall s t u,
sealcomp_store s t ->
sealcomp_store t u ->
sealcomp_store s u.
Proof with eauto using sealcomp_transitive.
intros * sLt tLu.
destruct sLt. destruct tLu.
split; intros...
+ destruct (H l v) as [x [Maps Seal]]...
destruct (H1 l x) as [x2 [Maps2 Seal2]]...
+ destruct (H2 l v') as [x [Maps Seal]]...
destruct (H0 l x) as [x2 [Maps2 Seal2]]...
Qed.
Lemma sealcomp_stores_are_consistent : forall s s',
sealcomp_store s s' ->
consistent_store s s'.
Proof with eauto.
intros.
inversion H; subst...
split; intros In...
+ destruct In as [v Maps].
destruct (H0 l v) as [v' [Maps' Less]]...
eexists v'...
+ destruct In as [v Maps].
destruct (H1 l v) as [v' [Maps' Less]]...
eexists v'...
Qed.
#[export] Hint Resolve sealcomp_stores_are_consistent : core.
Lemma sealcomp_store_after_add : forall l s s' v v',
sealcomp_store s s' ->
sealcomp v v' ->
sealcomp_store (LabelMapImpl.add l v s) (LabelMapImpl.add l v' s').
Proof with eauto.
intros * sLs' vLv'.
split; intros l1 v1 MapsTo;
rewrite LabelMapFacts.add_mapsto_iff in *;
destruct MapsTo as [[EqL EqV] | [NeqL MapsTo']]; subst...
+ exists v'... split...
LabelMapFacts.map_iff...
+ destruct sLs' as [Left Right]...
destruct (Left l1 v1) as [v1' [Maps v1Lv1']]...
exists v1'... split...
LabelMapFacts.map_iff; right; split...
+ exists v... split...
LabelMapFacts.map_iff...
+ destruct sLs' as [Left Right]...
destruct (Right l1 v1) as [v1' [Maps v1Lv1']]...
exists v1'... split...
LabelMapFacts.map_iff; right; split...
Qed.
#[export] Hint Resolve sealcomp_store_after_add : core.
(* ********************************************************************** *)
(** * #<a name="sealed_records"></a># Properties of [rec_comp]s that are sealed *)
Lemma sealcomp_record_consistent : forall r r' x res,
sealcomp_rec_comp r r' ->
record_lookup_ref x r = res ->
record_lookup_ref x r' = res.
Proof with eauto.
intros * rLr' Eq.
dependent induction rLr'...
simpl in *; destruct (x == a)...
Qed.
Lemma sealcomp_record_consistent_lt : forall r r' x res,
sealcomp_rec_comp r' r ->
record_lookup_ref x r = res ->
record_lookup_ref x r' = res.
Proof with eauto.
intros * rLr' Eq.
dependent induction rLr'...
simpl in *; destruct (x == a)...
Qed.
(* ********************************************************************** *)
(** * #<a name="sealed_values"></a># Properties of [value]s that are sealed *)
Lemma irreducible_value : forall e s f s',
value e ->
~ red e s f s'
with irreducible_record_value : forall e s f s',
value_record_comp e ->
~ red_record_comp e s f s'.
Proof with eauto.
------
clear irreducible_value.
intros * Val Rede.
inversion Rede; subst; inversion Val; subst...
+ inversion Rede; subst...
inversion H3; subst...
+ inversion H; subst...
eapply irreducible_record_value...
+ eapply irreducible_record_value...
------
clear irreducible_record_value.
intros * Val Rede.
induction Rede; subst; inversion Val; subst;
try solve [inversion Rede; eauto]...
Qed.
Lemma sealcomp_value : forall e f,
expr e ->
expr f ->
sealcomp e f ->
value f ->
value e
with sealcomp_rec_comp_value : forall e f,
record_comp e ->
record_comp f ->
sealcomp_rec_comp e f ->
value_record_comp f ->
value_record_comp e.
Proof with eauto.
------
clear sealcomp_value.
intros * Expe Expf Seal Value.
induction Seal; inversion Value; subst...
+ inversion Seal...
+ inversion Seal; subst...
econstructor...
eapply sealcomp_rec_comp_value with (f := r)...
inversion Expe; subst. inversion H1; subst...
+ econstructor...
eapply sealcomp_rec_comp_value with (f := r2)...
inversion Expe...
------
clear sealcomp_rec_comp_value.
intros * Expe Expf Seal Value.
induction Seal; inversion Value; subst...
econstructor...
apply IHSeal... inversion Expe...
Qed.
(* ********************************************************************** *)
(** * #<a name="safety_value"></a># Reduction when equivalent modulo sealing to a value *)
(** #<a name="lemma_5.5"></a># Lemma 5.5 *)
Lemma safety_value : forall e s f ns f' ns',
sealcomp_store s ns ->
sealcomp e f ->
value e ->
red f ns f' ns' ->
sealcomp_store s ns' /\ sealcomp e f' /\ (seal_count f') < (seal_count f)
with safety_record_value : forall e s f ns f' ns',
sealcomp_store s ns ->
sealcomp_rec_comp e f ->
value_record_comp e ->
red_record_comp f ns f' ns' ->
sealcomp_store s ns' /\ sealcomp_rec_comp e f' /\ (seal_count_record f') < (seal_count_record f).
Proof with eauto; try solve [simpl; intuition].
------
clear safety_value.
intros * sLns eLf Vale.
generalize dependent ns'.
generalize dependent f'.
dependent induction eLf; intros; try solve [try inversion Vale; try inversion H; eauto].
* inversion Vale; subst...
+ inversion H; subst; try solve [inversion eLf]...
- edestruct IHeLf as [SSComp [SComp Count]]...
- inversion eLf; repeat (split; eauto)...
- inversion eLf; repeat (split; eauto)...
+ inversion H; subst; try solve [inversion eLf]...
- edestruct IHeLf as [SSComp [SComp Count]]...
- inversion eLf; repeat (split; eauto)...
- inversion eLf; repeat (split; eauto)...
* inversion H0; subst...
edestruct (safety_record_value) as [SSComp [SComp Count]]...
inversion Vale...
* inversion H; subst...
edestruct IHeLf as [SSComp [SComp Count]]...
------
clear safety_record_value.
intros * sLns eLf Vale.
generalize dependent ns'.
generalize dependent f'.
dependent induction eLf; intros; try solve [try inversion Vale; try inversion H; eauto].
inversion Vale; subst...
inversion H; subst; try solve [edestruct IHeLf as [SSComp [SComp Count]]; eauto]...
Qed.
(* ********************************************************************** *)
(** * #<a name="safety"></a># Reduction when equivalent modulo sealing *)
(** #<a name="lemma_5.7"></a># Lemma 5.7 *)
Lemma safety_step' : forall e s f ns f' ns',
expr e ->
well_formed_store s ->
sealcomp_store s ns ->
sealcomp e f ->
red f ns f' ns' ->
(sealcomp_store s ns' /\ sealcomp e f' /\ seal_count f' < seal_count f) \/
(exists e' s', red e s e' s' /\ sealcomp_store s' ns' /\ sealcomp e' f')
with safety_record_step' : forall e s f ns f' ns',
record_comp e ->
well_formed_store s ->
sealcomp_store s ns ->
sealcomp_rec_comp e f ->
red_record_comp f ns f' ns' ->
(sealcomp_store s ns' /\ sealcomp_rec_comp e f' /\ seal_count_record f' < seal_count_record f) \/
(exists e' s', red_record_comp e s e' s'/\ sealcomp_store s' ns' /\ sealcomp_rec_comp e' f').
Proof with eauto; try solve [simpl; eauto; intuition].
------
clear safety_step'.
intros * ExprE WfS sLns eLf Redf.
generalize dependent ns'.
generalize dependent f'.
dependent induction eLf; intros; try solve [try inversion Redf; eauto].
Case "red_app". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_app e' e2)... exists s'...
+ assert (expr (exp_app f1 f2)) as ExprF1F2... inversion ExprF1F2; subst...
unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
edestruct IHeLf2 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_app e1 e')... exists s'...
+ assert (expr (exp_app (exp_abs T e4) f2)) as ExprF1F2... inversion ExprF1F2; subst...
unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
unshelve epose proof (sealcomp_value _ _ _ _ eLf2 _) as ValueE2...
inversion ValueE1; inversion eLf1; subst; try discriminate...
inversion select (exp_abs _ _ = exp_abs _ _); subst...
right... exists (open_ee e0 e2)... exists s...
}
Case "red_tapp". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_tapp e' T)... exists s'...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _) as ValueE1...
inversion ValueE1; inversion eLf; subst; try discriminate...
inversion select (exp_tabs _ _ = exp_tabs _ _); subst...
right... exists (open_te e0 T)... exists s...
}
Case "red_let". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists... exists s'... split...
+ assert (expr (exp_let f1 f2)) as ExprF1F2... inversion ExprF1F2; subst...
unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
right... exists (open_ee e2 e1)... exists s... split...
}
Case "red_box". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists... eexists...
+ assert (expr (exp_box e2)) as ExprE2... inversion ExprE2...
unshelve epose proof (sealcomp_value _ _ _ _ eLf _) as ValueE1...
right... eexists. eexists. split...
erewrite <- consistent_fresh_label_for_store...
eapply consistent_store_symmetric.
apply sealcomp_stores_are_consistent...
}
Case "red_unbox". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists... eexists...
+ inversion eLf; subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l f') as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l f')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists v'. eexists...
+ inversion eLf; subst...
* inversion select (_ <e= exp_ref _); subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l v1) as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l v1)) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists (exp_seal v'). eexists... split...
* inversion select (_ <e= exp_ref _); subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l v1) as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l v1)) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists v'. eexists... split...
}
Case "red_set_box". {
assert (expr (exp_set_box f1 f2)) as ExprF1F2...
inversion ExprE; inversion ExprF1F2; subst...
inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_set_box e' e2). eexists...
+ edestruct IHeLf2 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_set_box e1 e'). eexists... split...
constructor...
eapply sealcomp_value with (f := f1)...
+ inversion eLf1; subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l f') as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns l f')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists v'. exists (LabelMapImpl.add l e2 s)... split... constructor...
eapply sealcomp_value with (f := f2)...
}
Case "red_seal". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists. eexists. split...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
inversion eLf; subst...
right... eexists. eexists. split...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
inversion eLf; subst...
right... eexists. eexists. split...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
inversion eLf; subst...
inversion select (_ <e= exp_ref _); subst.
right...
exists (exp_seal (exp_ref l))...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
inversion eLf; subst...
inversion select (_ <e= exp_record _); subst.
right... eexists. eexists. split...
inversion ValueE1; subst...
}
Case "red_record". {
inversion ExprE; inversion Redf; subst...
unshelve epose proof (safety_record_step' r1 s r2 ns r1' ns')
as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists. eexists...
}
Case "red_record_read". {
inversion ExprE; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists... eexists...
+ inversion eLf; subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l f') as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l f')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists v'. eexists... split...
eapply red_record_read_ref...
eapply sealcomp_rec_comp_value with (f := r)...
inversion select (expr (exp_record _))...
eapply sealcomp_record_consistent_lt...
+ inversion eLf; subst...
* inversion select (_ <e= exp_record _); subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l v1) as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l v1)) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists (exp_seal v'). eexists... split...
eapply red_sealed_record_read_ref...
eapply sealcomp_rec_comp_value with (f := r)...
inversion select (expr (exp_seal (exp_record _)));
inversion select (expr (exp_record _ )); subst...
eapply sealcomp_record_consistent_lt...
* inversion select (_ <e= exp_record _); subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l v1) as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l v1)) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists v'. eexists... split...
eapply red_record_read_ref...
eapply sealcomp_rec_comp_value with (f := r)...
inversion select (expr (exp_record _))...
eapply sealcomp_record_consistent_lt...
}
Case "red_record_write". {
assert (expr (exp_record_write f1 x f2)) as ExprF1F2...
inversion ExprE;
inversion ExprF1F2; subst...
inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_record_write e' x e2). eexists...
+ edestruct IHeLf2 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... exists (exp_record_write e1 x e'). eexists... split... constructor...
eapply sealcomp_value with (f := f1)...
+ inversion eLf1; subst...
right...
destruct (sLns) as [Left Right]...
destruct (Right l f') as [v' [MapS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns l f')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff s l v')) _) as R2...
exists v'. exists (LabelMapImpl.add l e2 s)... split... constructor...
eapply sealcomp_rec_comp_value with (f := r)...
inversion select (expr (exp_record r1))...
eapply sealcomp_record_consistent_lt...
eapply sealcomp_value with (f := f2)...
}
Case "red_seal". {
inversion Redf; subst...
edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists. eexists. split...
}
------
clear safety_record_step'.
intros * RecCompE WfS sLns eLf Redf.
generalize dependent ns'.
generalize dependent f'.
dependent induction eLf; intros; try solve [try inversion Redf; eauto].
Case "red_record_exp". {
inversion RecCompE; subst...
assert (record_comp (rec_exp a e2 r2)) as RecCompE2R2...
inversion RecCompE2R2; subst...
inversion Redf; subst...
+ unshelve epose proof (safety_step' e1 s e2 ns _ _ _ _)
as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists. eexists. split...
+ right. erewrite <- consistent_fresh_label_for_store...
eexists. eexists. split.
eapply red_record_exp_2...
eapply sealcomp_value with (f := e2)...
split...
}
Case "red_record_ref". {
inversion RecCompE;
inversion Redf; subst...
destruct IHeLf
with (f' := r1') (ns' := ns') as [[SealS1 [Seal1 Count]] | [e' [s' [Rede [SealS2 Seal2]]]]]...
right... eexists. eexists. split...
}
Qed.
(** #<a name="lemma_5.6"></a># Lemma 5.6 *)
Lemma safety_step : forall e s e' s' f ns f' ns',
sealcomp_store s ns ->
sealcomp e f ->
red e s e' s' ->
red f ns f' ns' ->
(sealcomp_store s ns' /\ sealcomp e f' /\ seal_count f' < seal_count f) \/ (sealcomp_store s' ns' /\ sealcomp e' f')
with safety_record_step : forall e s e' s' f ns f' ns',
sealcomp_store s ns ->
sealcomp_rec_comp e f ->
red_record_comp e s e' s' ->
red_record_comp f ns f' ns' ->
(sealcomp_store s ns' /\ sealcomp_rec_comp e f' /\ seal_count_record f' < seal_count_record f) \/ (sealcomp_store s' ns' /\ sealcomp_rec_comp e' f').
Proof with eauto; try solve [simpl; eauto; intuition].
------
clear safety_step.
intros * sLns eLf Rede Redf.
generalize dependent s'.
generalize dependent e'.
generalize dependent ns'.
generalize dependent f'.
dependent induction eLf; intros; try solve [try inversion Rede; try inversion Redf; eauto].
Case "red_app". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE2...
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value e1 s f1 ns e1' ns' _ _ _ _) as [Store SComp]...
+ edestruct IHeLf2 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf2 _) as ValueE2...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_abs T e0) ns f1 ns e1' ns' _ _ _ _) as [Store SComp]...
left; split...
eapply sealcomp_store_transitive...
+ unshelve epose proof (safety_value e2 ns f2 ns e2' ns' _ _ _ _) as [Store SComp]...
left; split...
eapply sealcomp_store_transitive...
+ (** sealcomp over opens *)
inversion eLf1...
}
Case "red_tapp". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _) as ValueE1...
exfalso... eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_tabs T1 e0) ns e2 ns e1' ns' _ _ _ _) as [Store SComp]...
left; split...
eapply sealcomp_store_transitive...
+ inversion eLf; subst...
}
Case "red_let". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value e1 s' f1 ns e1' ns' _ _ _ _) as [Store SComp]...
}
Case "red_box". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _) as ValueE1...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value e1 s e2 ns e1' ns' _ _ _ _) as [Store SComp]...
+ erewrite <- consistent_fresh_label_for_store...
}
Case "red_unbox". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ )as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_ref l) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ inversion eLf; subst...
right... split...
destruct (sLns) as [Left Right]...
destruct (Left l0 e') as [v' [MapsNS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 f')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v')) _) as R2...
rewrite R1 in *; inversion R2; subst...
+ inversion eLf; subst...
inversion select (exp_ref _ <e= exp_ref _); subst...
right... split...
destruct (sLns) as [Left Right]...
destruct (Left l0 e') as [v' [MapsNS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v0)) _) as R2...
rewrite R1 in *; inversion R2; subst...
+ unshelve epose proof (safety_value (exp_seal (exp_ref l)) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ inversion eLf; subst...
+ inversion eLf; inversion select (_ <e= exp_ref _); subst...
right... split...
destruct (sLns) as [Left Right]...
destruct (Left l0 v1) as [v' [MapsNS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v0)) _) as R2...
rewrite R1 in *; inversion R2; subst...
}
Case "red_set_box". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _ ) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value e1 s f1 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ edestruct IHeLf2 with (ns' := ns') as [[SealS1 Seal1] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value e2 f2 _ _ _ _)...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_ref l) s f1 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ unshelve epose proof (safety_value e2 s f2 ns e2' ns' _ _ _ _)
as [Store SComp]...
+ inversion eLf1; subst...
right; split...
destruct sLns as [Left Right]...
destruct (Left l0 e') as [f'' [MapsF LtF]]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns l0 f'')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns l0 f')) _) as R2...
rewrite R1 in R2; inversion R2; subst...
}
Case "red_seal". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf as [[LeftS [LeftC Count]] | [RightS RightC]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ ) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_abs T e0) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ unshelve epose proof (safety_value (exp_tabs T e0) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ unshelve epose proof (safety_value (exp_ref l) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ unshelve epose proof (safety_value (exp_record r) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
}
Case "red_record". {
inversion Rede; inversion Redf; subst...
unshelve epose proof (safety_record_step r1 s r1' s' r2 ns r1'0 ns' _ _ _ _)
as [[StoreLeft [LtLeft Count]] | [StoreRight LtRight]]...
}
Case "red_record_read". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf _ )as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_record r) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ inversion eLf; subst...
right... split...
rewrite (sealcomp_record_consistent r r0 x (Some l)) in *...
inversion select (Some l = Some l0); subst...
destruct (sLns) as [Left Right]...
destruct (Left l0 e') as [v' [MapsNS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 f')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v')) _) as R2...
rewrite R1 in *; inversion R2; subst...
+ inversion eLf; subst...
inversion select (exp_record r <e= exp_record r0); subst...
rewrite (sealcomp_record_consistent r r0 x (Some l)) in *...
inversion select (Some l = Some l0); subst...
right... split...
destruct (sLns) as [Left Right]...
destruct (Left l0 e') as [v' [MapsNS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v0)) _) as R2...
rewrite R1 in *; inversion R2; subst...
+ unshelve epose proof (safety_value (exp_seal (exp_record r)) s' e2 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ inversion eLf; subst...
+ inversion eLf;
[inversion select (exp_record _ <e= exp_record _)|
inversion select (exp_seal (exp_record _) <e= exp_record _)]; subst...
rewrite (sealcomp_record_consistent r r0 x (Some l)) in *...
inversion select (Some l = Some l0); subst...
right... split...
destruct (sLns) as [Left Right]...
destruct (Left l0 v1) as [v' [MapsNS' e'Lv']]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns' l0 v0)) _) as R2...
rewrite R1 in *; inversion R2; subst...
}
Case "red_record_write". {
inversion Rede; inversion Redf; subst...
+ edestruct IHeLf1 with (ns' := ns') as [[SealS1 [Seal1 Count]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _) as ValueE1...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (sealcomp_value _ _ _ _ eLf1 _ ) as ValueE1...
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value e1 s f1 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ edestruct IHeLf2 with (ns' := ns') as [[SealS1 [Count Seal1]] | [SealS2 Seal2]]...
+ unshelve epose proof (sealcomp_value e2 f2 _ _ _ _)...
{ unshelve epose proof (red_regular _ _ _ _ Redf) as [ExprF1F2 _]...
inversion ExprF1F2... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value (exp_record r) s f1 ns e1' ns' _ _ _ _)
as [Store SComp]...
+ unshelve epose proof (safety_value e2 s f2 ns e2' ns' _ _ _ _)
as [Store SComp]...
+ inversion eLf1; subst...
rewrite (sealcomp_record_consistent r r0 x (Some l)) in *...
inversion select (Some l = Some l0); subst...
right; split...
destruct sLns as [Left Right]...
destruct (Left l0 e') as [f'' [MapsF LtF]]...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns l0 f'')) _) as R1...
unshelve epose proof ((proj1 (LabelMapFacts.find_mapsto_iff ns l0 f')) _) as R2...
rewrite R1 in R2; inversion R2; subst...
}
Case "red_seal". {
inversion Redf; subst...
unshelve epose proof (IHeLf e1' ns' _ e' s' _) as
[[StoreLeft [CompLeft Count]] | [StoreRight CompRight]]...
}
------
clear safety_record_step.
intros * sLns eLf Rede Redf.
generalize dependent s'.
generalize dependent e'.
generalize dependent ns'.
generalize dependent f'.
dependent induction eLf; intros; try solve [try inversion Rede; try inversion Redf; eauto].
Case "red_record_exp". {
inversion Rede; inversion Redf; subst...
+ unshelve epose proof (safety_step e1 s e1' s' e2 ns e1'0 ns' _ _ _ _)
as [[LeftStore [LeftComp Count]] | [RightStore RightComp]]...
+ unshelve epose proof (sealcomp_value _ _ _ _ H _) as ValueE2...
{ inversion select (value e2)... }
exfalso; eapply irreducible_value...
+ unshelve epose proof (safety_value e1 s e2 ns e1' ns' _ _ _ _)
as [StoreComp [SComp Count]]...
+ erewrite <- consistent_fresh_label_for_store...
}
Case "red_record_ref". {
inversion Rede; inversion Redf; subst...
unshelve epose proof (IHeLf r1'0 ns' _ r1' s' _) as
[[StoreLeft [CompLeft Count]] | [StoreRight CompRight]]...
}
Qed.