Skip to content

Commit 69a80fc

Browse files
committed
Adapted erasure to new array evaluation rules, except named wcbveval relation
1 parent 822cb61 commit 69a80fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+609
-244
lines changed

common/theories/Environment.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ Module Environment (T : Term).
856856
Definition primitive_invariants (p : prim_tag) (cdecl : constant_body) :=
857857
match p with
858858
| primInt | primFloat =>
859-
∑ s, [/\ cdecl.(cst_type) = tSort s, cdecl.(cst_body) = None &
860-
cdecl.(cst_universes) = Monomorphic_ctx]
859+
[/\ cdecl.(cst_type) = tSort Universe.type0, cdecl.(cst_body) = None &
860+
cdecl.(cst_universes) = Monomorphic_ctx]
861861
| primArray =>
862862
let s := Universe.make (Level.lvar 0) in
863863
[/\ cdecl.(cst_type) = tImpl (tSort s) (tSort s), cdecl.(cst_body) = None &

erasure-plugin/theories/ErasureCorrectness.v

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Proof.
262262
intros Hf.
263263
fix aux 2.
264264
intros t fo; destruct fo.
265-
eapply Hf => //. clear H. rename H0 into H.
265+
eapply Hf => //. clear H. rename H0 into H.
266266
move: args H.
267267
fix aux' 2.
268268
intros args []; constructor.
@@ -741,7 +741,7 @@ Proof.
741741
move: v; apply: firstorder_evalue_elim.
742742
intros.
743743
rewrite /flip (compile_evalue_box_mkApps) // ?app_nil_r.
744-
pose proof (H' := H).
744+
pose proof (H' := H).
745745
eapply lookup_constructor_pars_args_nopars in H; tea. subst npars.
746746
rewrite skipn_0 in H1.
747747
constructor.
@@ -1559,7 +1559,7 @@ Section pipeline_cond.
15591559
- cbn. intros wf ? ? ? ? ? ?. now eapply Normalisation.
15601560
Qed.
15611561

1562-
End pipeline_cond.
1562+
End pipeline_cond.
15631563

15641564
Section pipeline_theorem.
15651565

@@ -1602,7 +1602,7 @@ Section pipeline_theorem.
16021602

16031603
Lemma v_t_spec : v_t = (transform verified_erasure_pipeline (Σ, v) (precond2 _ _ _ _ expΣ expt typing _ _ Heval)).2.
16041604
Proof.
1605-
unfold v_t. generalize fo_v. set (pre := precond2 _ _ _ _ _ _ _ _ _ _) in *. clearbody pre.
1605+
unfold v_t. generalize fo_v. set (pre := precond2 _ _ _ _ _ _ _ _ _ _) in *. clearbody pre.
16061606
intros hv.
16071607
unfold verified_erasure_pipeline.
16081608
rewrite -transform_compose_assoc.
@@ -1629,7 +1629,7 @@ Section pipeline_theorem.
16291629
set (p := transform erase_transform _ _).
16301630
pose proof (@erase_tranform_firstorder _ h v i u (List.map PCUICExpandLets.trans args) Normalisation').
16311631
forward H0.
1632-
{ cbn. rewrite -eqtr.
1632+
{ cbn. rewrite -eqtr.
16331633
eapply (PCUICClassification.subject_reduction_eval (Σ := Σ)) in X; tea.
16341634
eapply PCUICExpandLetsCorrectness.expand_lets_sound in X.
16351635
now rewrite PCUICExpandLetsCorrectness.trans_mkApps /= in X. }
@@ -1664,24 +1664,24 @@ Section pipeline_theorem.
16641664

16651665
Lemma verified_erasure_pipeline_lookup_env_in kn decl (efl := EInlineProjections.switch_no_params all_env_flags) {has_rel : has_tRel} {has_box : has_tBox} :
16661666
EGlobalEnv.lookup_env Σ_v kn = Some (EAst.InductiveDecl decl) ->
1667-
exists decl',
1667+
exists decl',
16681668
PCUICAst.PCUICEnvironment.lookup_global (PCUICExpandLets.trans_global_decls
16691669
(PCUICAst.PCUICEnvironment.declarations
16701670
Σ.1)) kn = Some (PCUICAst.PCUICEnvironment.InductiveDecl decl')
1671-
/\ decl = ERemoveParams.strip_inductive_decl (erase_mutual_inductive_body decl').
1672-
Proof.
1671+
/\ decl = ERemoveParams.strip_inductive_decl (erase_mutual_inductive_body decl').
1672+
Proof.
16731673
Opaque compose.
16741674
unfold Σ_v, verified_erasure_pipeline.
1675-
repeat rewrite -transform_compose_assoc.
1676-
destruct_compose; intro. cbn.
1675+
repeat rewrite -transform_compose_assoc.
1676+
destruct_compose; intro. cbn.
16771677
destruct_compose; intro. cbn.
1678-
set (erase_program _ _).
1678+
set (erase_program _ _).
16791679
unfold verified_lambdabox_pipeline.
1680-
repeat rewrite -transform_compose_assoc.
1681-
repeat (destruct_compose; intro).
1680+
repeat rewrite -transform_compose_assoc.
1681+
repeat (destruct_compose; intro).
16821682
unfold transform at 1. cbn -[transform].
16831683
rewrite EConstructorsAsBlocks.lookup_env_transform_blocks.
1684-
set (EConstructorsAsBlocks.transform_blocks_decl _).
1684+
set (EConstructorsAsBlocks.transform_blocks_decl _).
16851685
unfold transform at 1. cbn -[transform].
16861686
unfold transform at 1. cbn -[transform].
16871687
erewrite EInlineProjections.lookup_env_optimize.
@@ -1692,7 +1692,7 @@ Section pipeline_theorem.
16921692
rewrite erase_global_deps_fast_spec.
16931693
eapply erase_global_deps_wf_glob.
16941694
intros ? He; now rewrite He. }
1695-
set (EInlineProjections.optimize_decl _).
1695+
set (EInlineProjections.optimize_decl _).
16961696
unfold transform at 1. cbn -[transform].
16971697
unfold transform at 1. cbn -[transform].
16981698
erewrite EOptimizePropDiscr.lookup_env_remove_match_on_box.
@@ -1710,25 +1710,25 @@ Section pipeline_theorem.
17101710
unfold transform at 1. cbn -[transform].
17111711
rewrite erase_global_deps_fast_spec.
17121712
2: { cbn. intros ? He. rewrite He. eauto. }
1713-
intro.
1713+
intro.
17141714
set (EAstUtils.term_global_deps _).
17151715
set (build_wf_env_from_env _ _).
1716-
epose proof
1716+
epose proof
17171717
(lookup_env_in_erase_global_deps optimized_abstract_env_impl w t0
17181718
_ kn _ Hyp0).
17191719
set (EGlobalEnv.lookup_env _ _).
17201720
case_eq o. 2: { intros ?. inversion 1. }
17211721
destruct g3; intro Ho; [inversion 1|].
1722-
cbn. inversion 1.
1722+
cbn. inversion 1.
17231723
specialize (H8 m). forward H8.
17241724
epose proof (wf_fresh_globals _ HΣ). clear - H10.
17251725
revert H10. cbn. set (Σ.1). induction 1; econstructor; eauto.
17261726
cbn. clear -H. induction H; econstructor; eauto.
1727-
unfold o in Ho; rewrite Ho in H8.
1728-
specialize (H8 eq_refl).
1727+
unfold o in Ho; rewrite Ho in H8.
1728+
specialize (H8 eq_refl).
17291729
destruct H8 as [decl' [? ?]]. exists decl'; split ; eauto.
17301730
rewrite <- H10. now destruct decl, m.
1731-
Qed.
1731+
Qed.
17321732

17331733
Lemma verified_erasure_pipeline_firstorder_evalue_block :
17341734
firstorder_evalue_block Σ_v v_t.
@@ -1740,9 +1740,9 @@ Section pipeline_theorem.
17401740
destruct_compose.
17411741
generalize fo_v. intros hv.
17421742
cbn [transform pcuic_expand_lets_transform].
1743-
intros pre1. destruct_compose. intros pre2.
1744-
destruct lambdabox_pres_fo as [fn [tr hfn]].
1745-
destruct tr. destruct typing as [typing']. pose proof (Heval' := Heval). sq. rewrite transform_fo.
1743+
intros pre1. destruct_compose. intros pre2.
1744+
destruct lambdabox_pres_fo as [fn [tr hfn]].
1745+
destruct tr. destruct typing as [typing']. pose proof (Heval' := Heval). sq. rewrite transform_fo.
17461746
{ intro. eapply preserves_fo. }
17471747
assert (eqtr : PCUICExpandLets.trans v = v).
17481748
{ clear -hv.
@@ -1759,7 +1759,7 @@ Section pipeline_theorem.
17591759
set (p := transform erase_transform _ _).
17601760
pose proof (@erase_tranform_firstorder _ pre1 v i u (List.map PCUICExpandLets.trans args) Normalisation').
17611761
forward H0.
1762-
{ cbn.
1762+
{ cbn.
17631763
eapply (PCUICClassification.subject_reduction_eval (Σ := Σ)) in Heval'; tea.
17641764
eapply PCUICExpandLetsCorrectness.expand_lets_sound in Heval'.
17651765
now rewrite PCUICExpandLetsCorrectness.trans_mkApps /= in Heval'. }
@@ -1777,29 +1777,29 @@ Section pipeline_theorem.
17771777
eapply PCUICWcbvEval.eval_closed; tea. apply HΣ.
17781778
unshelve apply (PCUICClosedTyp.subject_closed typing'). now rewrite eqtr. }
17791779
specialize (H0 _ eq_refl).
1780-
rewrite /p.
1780+
rewrite /p.
17811781
rewrite erase_transform_fo //. { cbn. rewrite eqtr. exact H. }
17821782
set (Σer := (transform erase_transform _ _).1).
17831783
assert (firstorder_evalue Σer (compile_value_erase v [])).
17841784
{ apply H0. }
1785-
simpl. unfold fo_evalue_map. rewrite eqtr. exact H1.
1786-
Qed.
1785+
simpl. unfold fo_evalue_map. rewrite eqtr. exact H1.
1786+
Qed.
17871787

17881788
Lemma verified_erasure_pipeline_extends (efl := EInlineProjections.switch_no_params all_env_flags) {has_rel : has_tRel} {has_box : has_tBox} :
17891789
EGlobalEnv.extends Σ_v Σ_t.
17901790
Proof.
17911791
unfold Σ_v, Σ_t. unfold verified_erasure_pipeline.
1792-
repeat (destruct_compose; intro). destruct typing as [typing'], Heval.
1792+
repeat (destruct_compose; intro). destruct typing as [typing'], Heval.
17931793
cbn [transform compose pcuic_expand_lets_transform] in *.
17941794
unfold run, time.
17951795
cbn [transform erase_transform] in *.
17961796
set (erase_program _ _). set (erase_program _ _).
17971797
eapply verified_lambdabox_pipeline_extends.
1798-
eapply extends_erase_pcuic_program; eauto.
1798+
eapply extends_erase_pcuic_program; eauto.
17991799
unshelve eapply (PCUICExpandLetsCorrectness.trans_wcbveval (cf := extraction_checker_flags) (Σ := (Σ.1, Σ.2))).
18001800
{ now eapply PCUICExpandLetsCorrectness.trans_wf. }
18011801
{ clear -HΣ typing'. now eapply PCUICClosedTyp.subject_closed in typing'. }
1802-
assumption.
1802+
assumption.
18031803
now eapply PCUICExpandLetsCorrectness.trans_axiom_free.
18041804
pose proof (PCUICExpandLetsCorrectness.expand_lets_sound typing').
18051805
rewrite PCUICExpandLetsCorrectness.trans_mkApps in X. eapply X.
@@ -1808,8 +1808,9 @@ Section pipeline_theorem.
18081808
rewrite PCUICExpandLetsCorrectness.trans_lookup.
18091809
destruct PCUICAst.PCUICEnvironment.lookup_env => //.
18101810
destruct g => //=.
1811-
eapply PCUICExpandLetsCorrectness.trans_firstorder_mutind. eapply PCUICExpandLetsCorrectness.trans_firstorder_env. }
1812-
Qed.
1811+
eapply PCUICExpandLetsCorrectness.trans_firstorder_mutind.
1812+
eapply PCUICExpandLetsCorrectness.trans_firstorder_env. }
1813+
Qed.
18131814

18141815
Lemma verified_erasure_pipeline_theorem :
18151816
∥ eval (wfl := extraction_wcbv_flags) Σ_t t_t v_t ∥.
@@ -1820,7 +1821,7 @@ Section pipeline_theorem.
18201821
destruct Hev as [v' [[H1] H2]].
18211822
move: H2.
18221823
rewrite v_t_spec.
1823-
set (pre := precond2 _ _ _ _ _ _ _ _ _ _) in *. clearbody pre.
1824+
set (pre := precond2 _ _ _ _ _ _ _ _ _ _) in *. clearbody pre.
18241825
subst v_t Σ_t t_t.
18251826
revert H1.
18261827
unfold verified_erasure_pipeline.
@@ -1874,7 +1875,7 @@ Section pipeline_theorem.
18741875
eapply (ErasureFunctionProperties.firstorder_erases_deterministic optimized_abstract_env_impl wfe Σ.2) in b0. 3:tea.
18751876
2:{ cbn. reflexivity. }
18761877
2:{ eapply PCUICExpandLetsCorrectness.trans_wcbveval. eapply PCUICWcbvEval.eval_closed; tea. apply HΣ.
1877-
clear -typing'' HΣ. now eapply PCUICClosedTyp.subject_closed in typing''.
1878+
clear -typing'' HΣ. now eapply PCUICClosedTyp.subject_closed in typing''.
18781879
eapply PCUICWcbvEval.value_final. now eapply PCUICWcbvEval.eval_to_value in X0. }
18791880
(* 2:{ clear -fo. cbn. now eapply (PCUICExpandLetsCorrectness.trans_firstorder_ind Σ). }
18801881
eapply PCUICWcbvEval.value_final. now eapply PCUICWcbvEval.eval_to_value in X. } *)

erasure/theories/EArities.v

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,3 +1051,70 @@ Proof.
10511051
eapply PCUICElimination.unique_sorting_equality_propositional in Hprinc; eauto.
10521052
rewrite Hprinc; eauto.
10531053
Qed.
1054+
1055+
(** Inhabitants of primitive types are not erasable: they must live in a relevant universe.
1056+
1057+
This currently relies on int and float being in Set, while arrays are universe polymorphic,
1058+
hence always relevant, and the primitive types are axioms, so not convertible to arities. *)
1059+
1060+
Lemma prim_type_inv p prim_ty :
1061+
∑ u args, prim_type p prim_ty = mkApps (tConst prim_ty u) args.
1062+
Proof.
1063+
destruct p as [? []]; simp prim_type.
1064+
- eexists [], []. reflexivity.
1065+
- eexists [], []; reflexivity.
1066+
- eexists [_], [_]; reflexivity.
1067+
Qed.
1068+
1069+
Lemma primitive_invariants_axiom t decl : primitive_invariants t decl -> cst_body decl = None.
1070+
Proof.
1071+
destruct t; cbn => //.
1072+
1-2:now intros [? []].
1073+
now intros [].
1074+
Qed.
1075+
1076+
Lemma nisErasable_tPrim Σ p :
1077+
wf_ext Σ ->
1078+
isErasable Σ [] (tPrim p) -> False.
1079+
Proof.
1080+
intros wfΣ [T [Ht h]].
1081+
eapply inversion_Prim in Ht as [prim_ty [cdecl []]]; eauto.
1082+
pose proof (type_Prim _ _ _ _ _ a e d p0 p1). eapply validity in X.
1083+
destruct h.
1084+
- eapply invert_cumul_arity_r in w; tea.
1085+
destruct w as [ar [[H] r]].
1086+
destruct (prim_type_inv p prim_ty) as [u [args eq]].
1087+
rewrite eq in H.
1088+
eapply invert_red_axiom_app in H as [args' []]; tea.
1089+
2:now eapply primitive_invariants_axiom.
1090+
subst ar. now eapply isArity_mkApps in r as [].
1091+
- destruct s as [s [hs isp]].
1092+
eapply cumul_prop1' in hs; tea; eauto.
1093+
depelim p1; simp prim_type in hs.
1094+
* destruct p0 as [hd hb hu].
1095+
eapply inversion_Const in hs as [decl' [wf [decl'' [cu hs']]]]; eauto.
1096+
unshelve eapply declared_constant_to_gen in d, decl''. 3,6:eapply wfΣ.
1097+
eapply declared_constant_inj in d; tea. subst decl'.
1098+
rewrite hd in hs'. cbn in hs'.
1099+
eapply ws_cumul_pb_Sort_inv in hs'. red in hs'.
1100+
destruct s => //.
1101+
* destruct p0 as [hd hb hu].
1102+
eapply inversion_Const in hs as [decl' [wf [decl'' [cu hs']]]]; eauto.
1103+
unshelve eapply declared_constant_to_gen in d, decl''. 3,6:eapply wfΣ.
1104+
eapply declared_constant_inj in d; tea. subst decl'.
1105+
rewrite hd in hs'. cbn in hs'.
1106+
eapply ws_cumul_pb_Sort_inv in hs'. red in hs'.
1107+
destruct s => //.
1108+
* destruct p0 as [hd hb hu].
1109+
eapply inversion_App in hs as [na [A [B [hp [harg hres]]]]]; eauto.
1110+
eapply inversion_Const in hp as [decl' [wf [decl'' [cu hs']]]]; eauto.
1111+
unshelve eapply declared_constant_to_gen in d, decl''. 3,6:eapply wfΣ.
1112+
eapply declared_constant_inj in d; tea. subst decl'.
1113+
rewrite hd in hs'. cbn in hs'.
1114+
eapply ws_cumul_pb_Prod_Prod_inv in hs' as [].
1115+
eapply substitution_ws_cumul_pb_vass in w1; tea.
1116+
cbn in w1.
1117+
pose proof (ws_cumul_pb_trans _ _ _ w1 hres) as X0.
1118+
eapply ws_cumul_pb_Sort_inv in X0.
1119+
destruct s => //.
1120+
Qed.

erasure/theories/EConstructorsAsBlocks.v

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Section transform_blocks.
8787

8888
End Def.
8989

90-
Hint Rewrite @map_InP_spec : transform_blocks.
90+
Hint Rewrite @map_primIn_spec @map_InP_spec : transform_blocks.
9191

9292
Arguments eqb : simpl never.
9393

@@ -428,6 +428,8 @@ Section transform_blocks.
428428

429429
End transform_blocks.
430430

431+
Global Hint Rewrite @map_primIn_spec @map_InP_spec : transform_blocks.
432+
431433
Definition transform_blocks_constant_decl Σ cb :=
432434
{| cst_body := option_map (transform_blocks Σ) cb.(cst_body) |}.
433435

@@ -985,7 +987,7 @@ Proof.
985987
+ unfold constructor_isprop_pars_decl.
986988
rewrite lookup_constructor_transform_blocks. cbn [fst].
987989
rewrite eqc //= H8 //.
988-
+ now rewrite map_InP_spec nth_error_map H3; eauto.
990+
+ now rewrite nth_error_map H3; eauto.
989991
+ len.
990992
+ rewrite H9. len.
991993
+ rewrite wellformed_mkApps in i4 => //.
@@ -1014,8 +1016,7 @@ Proof.
10141016
* eauto.
10151017
* revert e1. set (x := transform_blocks Σ f5).
10161018
simp transform_blocks.
1017-
* rewrite map_InP_spec.
1018-
cbn in i8. unfold wf_fix in i8. rtoProp.
1019+
* cbn in i8. unfold wf_fix in i8. rtoProp.
10191020
erewrite <- transform_blocks_cunfold_fix => //.
10201021
all: eauto.
10211022
eapply closed_fix_subst. solve_all. destruct x; cbn in H5 |- *. eauto.
@@ -1049,7 +1050,7 @@ Proof.
10491050
- simp transform_blocks. rewrite -!transform_blocks_equation_1.
10501051
rewrite transform_blocks_mkApps //=.
10511052
simp transform_blocks. rewrite -!transform_blocks_equation_1.
1052-
rewrite !map_InP_spec. cbn [plus].
1053+
cbn [plus].
10531054
intros.
10541055
destruct H3 as [ev wf eta etad].
10551056
destruct H6.
@@ -1062,7 +1063,7 @@ Proof.
10621063
now rewrite transform_blocks_mkApps_eta_fn in e.
10631064
- intros; repeat match goal with [H : MCProd.and5 _ _ _ _ _ |- _] => destruct H end.
10641065
rewrite transform_blocks_mkApps //= in e0.
1065-
simp transform_blocks in e0. rewrite -!transform_blocks_equation_1 map_InP_spec in e0. simpl in e0.
1066+
simp transform_blocks in e0. rewrite -!transform_blocks_equation_1 in e0. simpl in e0.
10661067
simp transform_blocks. rewrite -!transform_blocks_equation_1.
10671068
move: i; rewrite /= wellformed_mkApps //. move/and3P => [] hasp wffn wfargs.
10681069
move: i4; rewrite /= wellformed_mkApps //. move/andP => [] wfcof _.
@@ -1174,6 +1175,11 @@ Proof.
11741175
unfold cstr_arity. cbn. rewrite H4; len.
11751176
solve_all. clear -X0. eapply All2_All2_Set. solve_all.
11761177
match goal with H : _ |- _ => apply H end.
1178+
- intros X; depelim X; simp transform_blocks; repeat constructor.
1179+
destruct a0.
1180+
eapply All2_over_undep in a. eapply All2_Set_All2 in ev. eapply All2_All2_Set. solve_all.
1181+
now destruct b.
1182+
now destruct a0.
11771183
- intros. destruct t; try solve [constructor; cbn in H, H0 |- *; try congruence].
11781184
cbn -[lookup_constructor] in H |- *. destruct args => //.
11791185
destruct lookup_constructor eqn:hl => //.

erasure/theories/EDeps.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ Proof.
345345
now constructor.
346346
- congruence.
347347
- depelim er. now constructor.
348+
- depelim er; depelim X; constructor; eauto.
349+
eapply All2_over_undep in a0. solve_all.
348350
- easy.
349351
Qed.
350352

0 commit comments

Comments
 (0)