Skip to content

Commit 59b4733

Browse files
authored
Introduce and use Senv.inject, Genv.inject, Val.inject_ptr_flat (#593)
This replaces Event.symbols_inject and Event.meminj_preserves_globals, and factors out some code in Op.v and in the proofs of the passes that use memory injections.
1 parent 1154e1f commit 59b4733

16 files changed

Lines changed: 250 additions & 375 deletions

File tree

‎aarch64/Op.v‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,20 +1691,12 @@ Section EVAL_INJECT.
16911691
Variable F V: Type.
16921692
Variable genv: Genv.t F V.
16931693
Variable f: meminj.
1694-
Hypothesis globals: meminj_preserves_globals genv f.
1694+
Hypothesis globals: Genv.inject f genv.
16951695
Variable sp1: block.
16961696
Variable sp2: block.
16971697
Variable delta: Z.
16981698
Hypothesis sp_inj: f sp1 = Some(sp2, delta).
16991699

1700-
Remark symbol_address_inject:
1701-
forall id ofs, Val.inject f (Genv.symbol_address genv id ofs) (Genv.symbol_address genv id ofs).
1702-
Proof.
1703-
intros. unfold Genv.symbol_address. destruct (Genv.find_symbol genv id) eqn:?; auto.
1704-
exploit (proj1 globals); eauto. intros.
1705-
econstructor; eauto. rewrite Ptrofs.add_zero; auto.
1706-
Qed.
1707-
17081700
Lemma eval_condition_inject:
17091701
forall cond vl1 vl2 b m1 m2,
17101702
Val.inject_list f vl1 vl2 ->
@@ -1729,8 +1721,7 @@ Lemma eval_addressing_inject:
17291721
Proof.
17301722
intros.
17311723
rewrite eval_shift_stack_addressing.
1732-
eapply eval_addressing_inj with (sp1 := Vptr sp1 Ptrofs.zero); eauto.
1733-
intros. apply symbol_address_inject.
1724+
eapply eval_addressing_inj with (sp1 := Vptr sp1 Ptrofs.zero); eauto using Genv.symbol_address_inject.
17341725
econstructor; eauto. rewrite Ptrofs.add_zero_l; auto.
17351726
Qed.
17361727

@@ -1750,7 +1741,7 @@ Proof.
17501741
intros; eapply Mem.weak_valid_pointer_inject_val; eauto.
17511742
intros; eapply Mem.weak_valid_pointer_inject_no_overflow; eauto.
17521743
intros; eapply Mem.different_pointers_inject; eauto.
1753-
intros. apply symbol_address_inject.
1744+
intros. eapply Genv.symbol_address_inject; eauto.
17541745
econstructor; eauto. rewrite Ptrofs.add_zero_l; auto.
17551746
Qed.
17561747

‎arm/Op.v‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,20 +1085,12 @@ Section EVAL_INJECT.
10851085
Variable F V: Type.
10861086
Variable genv: Genv.t F V.
10871087
Variable f: meminj.
1088-
Hypothesis globals: meminj_preserves_globals genv f.
1088+
Hypothesis globals: Genv.inject f genv.
10891089
Variable sp1: block.
10901090
Variable sp2: block.
10911091
Variable delta: Z.
10921092
Hypothesis sp_inj: f sp1 = Some(sp2, delta).
10931093

1094-
Remark symbol_address_inject:
1095-
forall id ofs, Val.inject f (Genv.symbol_address genv id ofs) (Genv.symbol_address genv id ofs).
1096-
Proof.
1097-
intros. unfold Genv.symbol_address. destruct (Genv.find_symbol genv id) eqn:?; auto.
1098-
exploit (proj1 globals); eauto. intros.
1099-
econstructor; eauto. rewrite Ptrofs.add_zero; auto.
1100-
Qed.
1101-
11021094
Lemma eval_condition_inject:
11031095
forall cond vl1 vl2 b m1 m2,
11041096
Val.inject_list f vl1 vl2 ->
@@ -1123,8 +1115,7 @@ Lemma eval_addressing_inject:
11231115
Proof.
11241116
intros.
11251117
rewrite eval_shift_stack_addressing.
1126-
eapply eval_addressing_inj with (sp1 := Vptr sp1 Ptrofs.zero); eauto.
1127-
intros. apply symbol_address_inject.
1118+
eapply eval_addressing_inj with (sp1 := Vptr sp1 Ptrofs.zero); eauto using Genv.symbol_address_inject.
11281119
econstructor; eauto. rewrite Ptrofs.add_zero_l; auto.
11291120
Qed.
11301121

@@ -1144,7 +1135,7 @@ Proof.
11441135
intros; eapply Mem.weak_valid_pointer_inject_val; eauto.
11451136
intros; eapply Mem.weak_valid_pointer_inject_no_overflow; eauto.
11461137
intros; eapply Mem.different_pointers_inject; eauto.
1147-
intros; apply symbol_address_inject.
1138+
intros; eapply Genv.symbol_address_inject; eauto.
11481139
econstructor; eauto. rewrite Ptrofs.add_zero_l; auto.
11491140
Qed.
11501141

‎backend/Inliningproof.v‎

Lines changed: 39 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -356,32 +356,18 @@ Qed.
356356

357357
(** ** Relating global environments *)
358358

359-
Inductive match_globalenvs (F: meminj) (bound: block): Prop :=
360-
| mk_match_globalenvs
361-
(DOMAIN: forall b, Plt b bound -> F b = Some(b, 0))
362-
(IMAGE: forall b1 b2 delta, F b1 = Some(b2, delta) -> Plt b2 bound -> b1 = b2)
363-
(SYMBOLS: forall id b, Genv.find_symbol ge id = Some b -> Plt b bound)
364-
(FUNCTIONS: forall b fd, Genv.find_funct_ptr ge b = Some fd -> Plt b bound)
365-
(VARINFOS: forall b gv, Genv.find_var_info ge b = Some gv -> Plt b bound).
366-
367359
Lemma find_function_agree:
368-
forall ros rs fd F ctx rs' bound,
360+
forall ros rs fd F ctx rs',
369361
find_function ge ros rs = Some fd ->
370362
agree_regs F ctx rs rs' ->
371-
match_globalenvs F bound ->
363+
Genv.inject F ge ->
372364
exists cu fd',
373365
find_function tge (sros ctx ros) rs' = Some fd' /\ transf_fundef (funenv_program cu) fd = OK fd' /\ linkorder cu prog.
374366
Proof.
375367
intros. destruct ros as [r | id]; simpl in *.
376368
- (* register *)
377369
assert (EQ: rs'#(sreg ctx r) = rs#r).
378-
{ exploit Genv.find_funct_inv; eauto. intros [b EQ].
379-
assert (A: Val.inject F rs#r rs'#(sreg ctx r)). eapply agree_val_reg; eauto.
380-
rewrite EQ in A; inv A.
381-
inv H1. rewrite DOMAIN in H5. inv H5. auto.
382-
apply FUNCTIONS with fd.
383-
rewrite EQ in H; rewrite Genv.find_funct_find_funct_ptr in H. auto.
384-
}
370+
{ eapply Genv.find_funct_inject; eauto using agree_val_reg. }
385371
rewrite EQ. eapply functions_translated; eauto.
386372
- (* symbol *)
387373
rewrite symbols_preserved. destruct (Genv.find_symbol ge id); try discriminate.
@@ -405,8 +391,8 @@ Qed.
405391
(** Translation of builtin arguments. *)
406392

407393
Lemma tr_builtin_arg:
408-
forall F bound ctx rs rs' sp sp' m m',
409-
match_globalenvs F bound ->
394+
forall F ctx rs rs' sp sp' m m',
395+
Genv.inject F ge ->
410396
agree_regs F ctx rs rs' ->
411397
F sp = Some(sp', ctx.(dstk)) ->
412398
Mem.inject F m m' ->
@@ -415,7 +401,12 @@ Lemma tr_builtin_arg:
415401
exists v', eval_builtin_arg tge (fun r => rs'#r) (Vptr sp' Ptrofs.zero) m' (sbuiltinarg ctx a) v'
416402
/\ Val.inject F v v'.
417403
Proof.
418-
intros until m'; intros MG AG SP MI. induction 1; simpl.
404+
intros until m'; intros MG AG SP MI.
405+
assert (SYMB: forall id ofs, Val.inject F (Senv.symbol_address ge id ofs) (Senv.symbol_address tge id ofs)).
406+
{ intros. unfold Senv.symbol_address; simpl. rewrite symbols_preserved.
407+
destruct (Genv.find_symbol ge id) as [b|] eqn:FS; auto.
408+
eauto using Val.inject_ptr_flat, Genv.find_symbol_inject. }
409+
induction 1; simpl.
419410
- exists rs'#(sreg ctx x); split. constructor. eapply agree_val_reg; eauto.
420411
- econstructor; eauto with barg.
421412
- econstructor; eauto with barg.
@@ -426,16 +417,8 @@ Proof.
426417
simpl. econstructor; eauto. rewrite Ptrofs.add_zero_l; auto.
427418
intros (v' & A & B). exists v'; split; auto. constructor. simpl. rewrite Ptrofs.add_zero_l; auto.
428419
- econstructor; split. constructor. simpl. econstructor; eauto. rewrite ! Ptrofs.add_zero_l; auto.
429-
- assert (Val.inject F (Senv.symbol_address ge id ofs) (Senv.symbol_address tge id ofs)).
430-
{ unfold Senv.symbol_address; simpl; unfold Genv.symbol_address.
431-
rewrite symbols_preserved. destruct (Genv.find_symbol ge id) as [b|] eqn:FS; auto.
432-
inv MG. econstructor. eauto. rewrite Ptrofs.add_zero; auto. }
433-
exploit Mem.loadv_inject; eauto. intros (v' & A & B).
434-
exists v'; eauto with barg.
435-
- econstructor; split. constructor.
436-
unfold Senv.symbol_address; simpl; unfold Genv.symbol_address.
437-
rewrite symbols_preserved. destruct (Genv.find_symbol ge id) as [b|] eqn:FS; auto.
438-
inv MG. econstructor. eauto. rewrite Ptrofs.add_zero; auto.
420+
- exploit Mem.loadv_inject; eauto. intros (v' & A & B). exists v'; eauto with barg.
421+
- econstructor; split. constructor. auto.
439422
- destruct IHeval_builtin_arg1 as (v1' & A1 & B1).
440423
destruct IHeval_builtin_arg2 as (v2' & A2 & B2).
441424
econstructor; split. eauto with barg. apply Val.longofwords_inject; auto.
@@ -446,8 +429,8 @@ Proof.
446429
Qed.
447430

448431
Lemma tr_builtin_args:
449-
forall F bound ctx rs rs' sp sp' m m',
450-
match_globalenvs F bound ->
432+
forall F ctx rs rs' sp sp' m m',
433+
Genv.inject F ge ->
451434
agree_regs F ctx rs rs' ->
452435
F sp = Some(sp', ctx.(dstk)) ->
453436
Mem.inject F m m' ->
@@ -467,9 +450,9 @@ Qed.
467450

468451
Inductive match_stacks (F: meminj) (m m': mem):
469452
list stackframe -> list stackframe -> block -> Prop :=
470-
| match_stacks_nil: forall bound1 bound
471-
(MG: match_globalenvs F bound1)
472-
(BELOW: Ple bound1 bound),
453+
| match_stacks_nil: forall bound
454+
(GINJ: Genv.inject F ge)
455+
(BELOW: Ple (Genv.genv_next ge) bound),
473456
match_stacks F m m' nil nil bound
474457
| match_stacks_cons: forall res f sp pc rs stk f' sp' rs' stk' bound fenv ctx
475458
(MS: match_stacks_inside F m m' stk stk' f' ctx sp' rs')
@@ -528,38 +511,23 @@ Variables m m': mem.
528511

529512
Lemma match_stacks_globalenvs:
530513
forall stk stk' bound,
531-
match_stacks F m m' stk stk' bound -> exists b, match_globalenvs F b
514+
match_stacks F m m' stk stk' bound -> Genv.inject F ge
532515
with match_stacks_inside_globalenvs:
533516
forall stk stk' f ctx sp rs',
534-
match_stacks_inside F m m' stk stk' f ctx sp rs' -> exists b, match_globalenvs F b.
517+
match_stacks_inside F m m' stk stk' f ctx sp rs' -> Genv.inject F ge.
535518
Proof.
536519
induction 1; eauto.
537520
induction 1; eauto.
538521
Qed.
539522

540-
Lemma match_globalenvs_preserves_globals:
541-
forall b, match_globalenvs F b -> meminj_preserves_globals ge F.
542-
Proof.
543-
intros. inv H. red. split. eauto. split. eauto.
544-
intros. symmetry. eapply IMAGE; eauto.
545-
Qed.
546-
547-
Lemma match_stacks_inside_globals:
548-
forall stk stk' f ctx sp rs',
549-
match_stacks_inside F m m' stk stk' f ctx sp rs' -> meminj_preserves_globals ge F.
550-
Proof.
551-
intros. exploit match_stacks_inside_globalenvs; eauto. intros [b A].
552-
eapply match_globalenvs_preserves_globals; eauto.
553-
Qed.
554-
555523
Lemma match_stacks_bound:
556524
forall stk stk' bound bound1,
557525
match_stacks F m m' stk stk' bound ->
558526
Ple bound bound1 ->
559527
match_stacks F m m' stk stk' bound1.
560528
Proof.
561529
intros. inv H.
562-
apply match_stacks_nil with bound0. auto. eapply Ple_trans; eauto.
530+
apply match_stacks_nil. auto. eapply Ple_trans; eauto.
563531
eapply match_stacks_cons; eauto. eapply Pos.lt_le_trans; eauto.
564532
eapply match_stacks_untailcall; eauto. eapply Pos.lt_le_trans; eauto.
565533
Qed.
@@ -600,10 +568,10 @@ with match_stacks_inside_invariant:
600568
Proof.
601569
induction 1; intros.
602570
(* nil *)
603-
apply match_stacks_nil with (bound1 := bound1).
604-
inv MG. constructor; auto.
605-
intros. apply IMAGE with delta. eapply INJ; eauto. eapply Pos.lt_le_trans; eauto.
606-
auto. auto.
571+
apply match_stacks_nil; auto.
572+
destruct GINJ as [A B]. split; intros.
573+
apply INCR. apply A. extlia.
574+
apply B; auto. apply INJ; auto. extlia.
607575
(* cons *)
608576
apply match_stacks_cons with (fenv := fenv) (ctx := ctx); auto.
609577
eapply match_stacks_inside_invariant; eauto.
@@ -773,10 +741,10 @@ with match_stacks_inside_extcall:
773741
match_stacks_inside F2 m2 m2' stk stk' f' ctx sp' rs'.
774742
Proof.
775743
induction 1; intros.
776-
apply match_stacks_nil with bound1; auto.
777-
inv MG. constructor; intros; eauto.
778-
destruct (F1 b1) as [[b2' delta']|] eqn:?.
779-
exploit INCR; eauto. intros EQ; rewrite H0 in EQ; inv EQ. eapply IMAGE; eauto.
744+
apply match_stacks_nil; auto.
745+
destruct GINJ as [P Q]. split; intros; eauto.
746+
destruct (F1 b) as [[b0 delta0]|] eqn:?.
747+
exploit INCR; eauto. intros EQ; rewrite H0 in EQ; inv EQ. eauto.
780748
exploit SEP; eauto. intros [A B]. elim B. red. extlia.
781749
eapply match_stacks_cons; eauto.
782750
eapply match_stacks_inside_extcall; eauto. extlia.
@@ -921,7 +889,7 @@ Proof.
921889
- (* op *)
922890
exploit tr_funbody_inv; eauto. intros TR; inv TR.
923891
exploit eval_operation_inject.
924-
eapply match_stacks_inside_globals; eauto.
892+
eapply match_stacks_inside_globalenvs; eauto.
925893
eexact SP.
926894
instantiate (2 := rs##args). instantiate (1 := rs'##(sregs ctx args)). eapply agree_val_regs; eauto.
927895
eexact MINJ. eauto.
@@ -936,7 +904,7 @@ Proof.
936904
- (* load *)
937905
exploit tr_funbody_inv; eauto. intros TR; inv TR.
938906
exploit eval_addressing_inject.
939-
eapply match_stacks_inside_globals; eauto.
907+
eapply match_stacks_inside_globalenvs; eauto.
940908
eexact SP.
941909
instantiate (2 := rs##args). instantiate (1 := rs'##(sregs ctx args)). eapply agree_val_regs; eauto.
942910
eauto.
@@ -953,7 +921,7 @@ Proof.
953921
- (* store *)
954922
exploit tr_funbody_inv; eauto. intros TR; inv TR.
955923
exploit eval_addressing_inject.
956-
eapply match_stacks_inside_globals; eauto.
924+
eapply match_stacks_inside_globalenvs; eauto.
957925
eexact SP.
958926
instantiate (2 := rs##args). instantiate (1 := rs'##(sregs ctx args)). eapply agree_val_regs; eauto.
959927
eauto.
@@ -973,8 +941,7 @@ Proof.
973941
intros. eapply SSZ2. eapply Mem.perm_store_2; eauto with mem.
974942

975943
- (* call *)
976-
exploit match_stacks_inside_globalenvs; eauto. intros [bound G].
977-
exploit find_function_agree; eauto. intros (cu & fd' & A & B & C).
944+
exploit find_function_agree; eauto using match_stacks_inside_globalenvs. intros (cu & fd' & A & B & C).
978945
exploit tr_funbody_inv; eauto. intros TR; inv TR.
979946
+ (* not inlined *)
980947
left; econstructor; split.
@@ -994,8 +961,7 @@ Proof.
994961
red; intros; apply PRIV. destruct H16. lia.
995962

996963
- (* tailcall *)
997-
exploit match_stacks_inside_globalenvs; eauto. intros [bound G].
998-
exploit find_function_agree; eauto. intros (cu & fd' & A & B & C).
964+
exploit find_function_agree; eauto using match_stacks_inside_globalenvs. intros (cu & fd' & A & B & C).
999965
assert (PRIV': range_private F m' m'0 sp' (dstk ctx) f'.(fn_stacksize)).
1000966
{ eapply range_private_free_left; eauto. inv FB. rewrite <- H4. auto. }
1001967
exploit tr_funbody_inv; eauto. intros TR; inv TR.
@@ -1050,10 +1016,8 @@ Proof.
10501016

10511017
- (* builtin *)
10521018
exploit tr_funbody_inv; eauto. intros TR; inv TR.
1053-
exploit match_stacks_inside_globalenvs; eauto. intros [bound MG].
1054-
exploit tr_builtin_args; eauto. intros (vargs' & P & Q).
1055-
exploit external_call_mem_inject; eauto.
1056-
eapply match_stacks_inside_globals; eauto.
1019+
exploit tr_builtin_args; eauto using match_stacks_inside_globalenvs. intros (vargs' & P & Q).
1020+
exploit external_call_mem_inject; eauto using match_stacks_inside_globalenvs.
10571021
intros [F1 [v1 [m1' [A [B [C [D [E [J K]]]]]]]]].
10581022
left; econstructor; split.
10591023
eapply plus_one. eapply exec_Ibuiltin; eauto.
@@ -1207,9 +1171,7 @@ Proof.
12071171
auto. auto.
12081172

12091173
- (* external function *)
1210-
exploit match_stacks_globalenvs; eauto. intros [bound MG].
1211-
exploit external_call_mem_inject; eauto.
1212-
eapply match_globalenvs_preserves_globals; eauto.
1174+
exploit external_call_mem_inject; eauto using match_stacks_globalenvs.
12131175
intros [F1 [v1 [m1' [A [B [C [D [E [J K]]]]]]]]].
12141176
simpl in FD. inv FD.
12151177
left; econstructor; split.
@@ -1274,14 +1236,8 @@ Proof.
12741236
rewrite <- H3. eapply sig_function_translated; eauto.
12751237
econstructor; eauto.
12761238
instantiate (1 := Mem.flat_inj (Mem.nextblock m0)).
1277-
apply match_stacks_nil with (Mem.nextblock m0).
1278-
constructor; intros.
1279-
unfold Mem.flat_inj. apply pred_dec_true; auto.
1280-
unfold Mem.flat_inj in H. destruct (plt b1 (Mem.nextblock m0)); congruence.
1281-
eapply Genv.find_symbol_not_fresh; eauto.
1282-
eapply Genv.find_funct_ptr_not_fresh; eauto.
1283-
eapply Genv.find_var_info_not_fresh; eauto.
1284-
apply Ple_refl.
1239+
erewrite <- Genv.init_mem_genv_next by eauto.
1240+
apply match_stacks_nil. apply Genv.init_inject. apply Ple_refl.
12851241
eapply Genv.initmem_inject; eauto.
12861242
Qed.
12871243

‎backend/Stackingproof.v‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,14 +1610,13 @@ Lemma find_function_translated:
16101610
/\ Genv.find_funct_ptr tge bf = Some tf
16111611
/\ transf_fundef f = OK tf.
16121612
Proof.
1613-
intros until f; intros AG [bound [_ [?????]]] FF.
1613+
intros until f; intros AG [BOUND GINJ] FF.
16141614
destruct ros; simpl in FF.
1615-
- exploit Genv.find_funct_inv; eauto. intros [b EQ]. rewrite EQ in FF.
1615+
- exploit Genv.find_funct_inject; eauto. intros EQ.
1616+
exploit Genv.find_funct_inv; eauto. intros [b EQ']. rewrite EQ' in FF.
16161617
rewrite Genv.find_funct_find_funct_ptr in FF.
16171618
exploit function_ptr_translated; eauto. intros [tf [A B]].
1618-
exists b; exists tf; split; auto. simpl.
1619-
generalize (AG m0). rewrite EQ. intro INJ. inv INJ.
1620-
rewrite DOMAIN in H2. inv H2. simpl. auto. eapply FUNCTIONS; eauto.
1619+
exists b; exists tf; split; auto. simpl. rewrite EQ, EQ'. auto.
16211620
- destruct (Genv.find_symbol ge i) as [b|] eqn:?; try discriminate.
16221621
exploit function_ptr_translated; eauto. intros [tf [A B]].
16231622
exists b; exists tf; split; auto. simpl.
@@ -1734,11 +1733,8 @@ Lemma transl_builtin_arg_correct:
17341733
/\ Val.inject j v v'.
17351734
Proof.
17361735
assert (SYMB: forall id ofs, Val.inject j (Senv.symbol_address ge id ofs) (Senv.symbol_address ge id ofs)).
1737-
{ assert (G: meminj_preserves_globals ge j).
1738-
{ eapply globalenv_inject_preserves_globals. eapply sep_proj2. eapply sep_proj2. eexact SEP. }
1739-
intros; unfold Senv.symbol_address; simpl; unfold Genv.symbol_address.
1740-
destruct (Genv.find_symbol ge id) eqn:FS; auto.
1741-
destruct G. econstructor. eauto. rewrite Ptrofs.add_zero; auto. }
1736+
{ intros. apply Genv.symbol_address_inject.
1737+
eapply globalenv_inject_preserves_globals. eapply sep_proj2. eapply sep_proj2. eexact SEP. }
17421738
Local Opaque fe.
17431739
induction 1; simpl; intros VALID BOUNDS.
17441740
- assert (loc_valid f x = true) by auto.
@@ -2171,13 +2167,8 @@ Proof.
21712167
red; simpl; auto.
21722168
simpl. rewrite sep_pure. split; auto. split;[|split].
21732169
eapply Genv.initmem_inject; eauto.
2174-
simpl. exists (Mem.nextblock m0); split. apply Ple_refl.
2175-
unfold j, Mem.flat_inj; constructor; intros.
2176-
apply pred_dec_true; auto.
2177-
destruct (plt b1 (Mem.nextblock m0)); congruence.
2178-
change (Mem.valid_block m0 b0). eapply Genv.find_symbol_not_fresh; eauto.
2179-
change (Mem.valid_block m0 b0). eapply Genv.find_funct_ptr_not_fresh; eauto.
2180-
change (Mem.valid_block m0 b0). eapply Genv.find_var_info_not_fresh; eauto.
2170+
simpl. unfold j. erewrite <- Genv.init_mem_genv_next by eauto.
2171+
auto using Genv.init_inject, Ple_refl.
21812172
red; simpl; tauto.
21822173
Qed.
21832174

0 commit comments

Comments
 (0)