Skip to content

Commit b63f41a

Browse files
authored
Merge pull request #1013 from MetaCoq/compile-pipeline-app
Compile pipeline app: applications of eta-expanded terms are preserved by the erasure pipeline. This introduces a judgment for normal forms (and neutrals), and a proof that the PCUICExpandLets transformation preserves normal forms. Also introduces a more positive `nisErasable` notion that characterizes non-erasable/relevant terms.
2 parents b33a9bd + 27d6ad2 commit b63f41a

21 files changed

+1791
-252
lines changed

erasure-plugin/theories/ErasureCorrectness.v

Lines changed: 710 additions & 206 deletions
Large diffs are not rendered by default.

erasure/theories/EArities.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,23 +1031,23 @@ Proof.
10311031
exists Tty. split => //. eapply subject_reduction; tea.
10321032
Qed.
10331033

1034-
Lemma not_isErasable Σ Γ f A u :
1034+
Lemma not_isErasable Σ Γ f A u :
10351035
wf_ext Σ -> wf_local Σ Γ ->
10361036
∥Σ;;; Γ |- f : A∥ ->
10371037
(forall B, ∥Σ;;; Γ ⊢ A ⇝ B∥ -> A = B) ->
10381038
(forall B, ∥Σ ;;; Γ |- f : B∥ -> ∥Σ ;;; Γ ⊢ A ≤ B∥) ->
10391039
~ ∥ isArity A ∥ ->
1040-
∥ Σ;;; Γ |- A : tSort u ∥ ->
1040+
∥ Σ;;; Γ |- A : tSort u ∥ ->
10411041
~ is_propositional u ->
10421042
~ ∥ Extract.isErasable Σ Γ f ∥.
10431043
Proof.
10441044
intros wfΣ Hlocal Hf Hnf Hprinc Harity Hfu Hu [[T [HT []]]]; sq.
1045-
- eapply Harity; sq.
1045+
- eapply Harity; sq.
10461046
eapply EArities.arity_type_inv in i as [T' [? ?]]; eauto.
10471047
eapply Hnf in H. subst; eauto.
1048-
- destruct s as [s [? ?]]. eapply Hu.
1048+
- destruct s as [s [? ?]]. eapply Hu.
10491049
specialize (Hprinc _ (sq HT)).
1050-
pose proof (Hs := i). sq.
1050+
pose proof (Hs := i). sq.
10511051
eapply PCUICElimination.unique_sorting_equality_propositional in Hprinc; eauto.
1052-
rewrite Hprinc; eauto.
1053-
Qed.
1052+
rewrite Hprinc; eauto.
1053+
Qed.

erasure/theories/EAstUtils.v

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Definition decompose_app f := decompose_app_rec f [].
1818
Definition head t := fst (decompose_app t).
1919
Definition spine t := snd (decompose_app t).
2020

21+
Lemma decompose_app_head_spine t : decompose_app t = (head t, spine t).
22+
Proof.
23+
unfold head, spine.
24+
destruct decompose_app => //.
25+
Qed.
26+
2127
Lemma decompose_app_rec_mkApps f l l' :
2228
decompose_app_rec (mkApps f l) l' = decompose_app_rec f (l ++ l').
2329
Proof.
@@ -31,7 +37,6 @@ Proof.
3137
destruct f; simpl in *; (discriminate || reflexivity).
3238
Qed.
3339

34-
3540
Lemma mkApps_app t l l' : mkApps t (l ++ l') = mkApps (mkApps t l) l'.
3641
Proof.
3742
induction l in t, l' |- *; simpl; auto.
@@ -156,6 +161,12 @@ Proof.
156161
intros napp. destruct t => //.
157162
Qed.
158163

164+
Lemma head_mkApps_nApp f a : ~~ EAst.isApp f -> head (EAst.mkApps f a) = f.
165+
Proof.
166+
rewrite head_mkApps /head => appf.
167+
rewrite (decompose_app_mkApps f []) //.
168+
Qed.
169+
159170
Lemma mkApps_eq_inj {t t' l l'} :
160171
mkApps t l = mkApps t' l' ->
161172
~~ isApp t -> ~~ isApp t' -> t = t' /\ l = l'.

erasure/theories/EEnvMap.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From Coq Require Import ssreflect ssrbool Morphisms Setoid.
1+
From Coq Require Import ssreflect ssrbool Morphisms Setoid ProofIrrelevance.
22
From Equations Require Import Equations.
33
From MetaCoq.Utils Require Import utils.
44
From MetaCoq.Common Require Import Kernames EnvMap BasicAst.
@@ -173,6 +173,12 @@ Module GlobalContextMap.
173173
{| global_decls := g;
174174
map := EnvMap.of_global_env g |}.
175175

176+
Lemma make_irrel Σ fr fr' : EEnvMap.GlobalContextMap.make Σ fr = EEnvMap.GlobalContextMap.make Σ fr'.
177+
Proof.
178+
unfold make. f_equal.
179+
apply proof_irrelevance.
180+
Qed.
181+
176182
End GlobalContextMap.
177183

178184
Coercion GlobalContextMap.global_decls : GlobalContextMap.t >-> global_declarations.

erasure/theories/EEtaExpanded.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,18 @@ Proof.
670670
eapply expanded_mkApps => //. now rewrite eqc. solve_all.
671671
Qed.
672672

673+
Lemma isEtaExp_tApp_arg Σ t u : isEtaExp Σ (tApp t u) -> isEtaExp Σ u.
674+
Proof.
675+
move/isEtaExp_tApp. destruct decompose_app eqn:da.
676+
eapply decompose_app_inv in da. destruct l using rev_case.
677+
- cbn in da. subst t0. cbn. now move/and3P => [].
678+
- rewrite mkApps_app in da. noconf da.
679+
destruct construct_viewc.
680+
* intros [_ [_ [_ H]]]. move/andP: H => [] /andP[] _. rewrite forallb_app.
681+
move=> /andP[] //=. now rewrite andb_true_r.
682+
* now move/and4P => [].
683+
Qed.
684+
673685
From MetaCoq.Erasure Require Import EEtaExpandedFix.
674686

675687
Local Ltac simp_eta ::= simp isEtaExp; rewrite -?isEtaExp_equation_1 -?EEtaExpanded.isEtaExp_equation_1.

erasure/theories/EEtaExpandedFix.v

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ Section isEtaExp.
533533
funelim (isEtaExp Γ_ b); try simp_eta; eauto; try fold csubst;
534534
try toAll; try solve_all; subst.
535535
- intros. simp isEtaExp ; cbn. destruct (Nat.compare_spec #|Γ0| i) => //; simp_eta.
536-
+ rewrite nth_error_app2 in H0; try lia; cbn in H0; try easy. subst. rewrite minus_diag in H0. cbn in H0. easy.
536+
+ rewrite nth_error_app2 in H0; try lia; cbn in H0; try easy. subst. rewrite Nat.sub_diag in H0. cbn in H0. easy.
537537
+ rewrite !nth_error_app2 in H0 |- *; cbn; try lia.
538538
erewrite option_default_ext; eauto. f_equal.
539539
destruct i; cbn; lia.
@@ -587,7 +587,7 @@ Section isEtaExp.
587587
rtoProp. repeat split; eauto.
588588
* unfold isEtaExp_fixapp. rewrite Hnth. len.
589589
subst. rewrite nth_error_app2 in H1; try lia.
590-
rewrite minus_diag in H1. cbn in H1. eapply Nat.ltb_lt.
590+
rewrite Nat.sub_diag in H1. cbn in H1. eapply Nat.ltb_lt.
591591
eapply Nat.leb_le in H1. lia.
592592
* cbn in Hcl. solve_all. rtoProp; intuition auto.
593593
now eapply expanded_weakening.
@@ -1942,3 +1942,19 @@ Proof.
19421942
destruct (cst_body c); cbn in * => //.
19431943
now eapply expanded_isEtaExp.
19441944
Qed.
1945+
1946+
Lemma isEtaExpFix_tApp_arg Σ Γ t u : isEtaExp Σ Γ (tApp t u) -> isEtaExp Σ Γ u.
1947+
Proof.
1948+
move/isEtaExp_tApp'. destruct decompose_app eqn:da.
1949+
eapply decompose_app_inv in da. destruct l using rev_case.
1950+
- cbn in da. subst t0. cbn. now move/and3P => [].
1951+
- rewrite mkApps_app in da. noconf da.
1952+
destruct expanded_head_viewc.
1953+
* intros [_ [_ [_ H]]]. move/andP: H => [] /andP[] _. rewrite forallb_app.
1954+
move=> /andP[] //=. now rewrite andb_true_r.
1955+
* intros [_ [_ [_ H]]]. move/andP: H => [] /andP[] _ _. rewrite forallb_app.
1956+
move=> /andP[] //=. now rewrite andb_true_r.
1957+
* intros [_ [_ [_ H]]]. move/andP: H => [] _. rewrite forallb_app.
1958+
move=> /andP[] //=. now rewrite andb_true_r.
1959+
* now move/and4P => [].
1960+
Qed.

erasure/theories/ERemoveParams.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ Proof.
402402
do 2 destruct nth_error => //.
403403
Qed.
404404

405+
Lemma lookup_constructor_pars_args_strip (Σ : GlobalContextMap.t) i n npars nargs :
406+
EGlobalEnv.lookup_constructor_pars_args Σ i n = Some (npars, nargs) ->
407+
EGlobalEnv.lookup_constructor_pars_args (strip_env Σ) i n = Some (0, nargs).
408+
Proof.
409+
rewrite /EGlobalEnv.lookup_constructor_pars_args. rewrite lookup_constructor_strip //=.
410+
destruct EGlobalEnv.lookup_constructor => //. destruct p as [[] ?] => //=. now intros [= <- <-].
411+
Qed.
412+
405413
Lemma is_propositional_strip (Σ : GlobalContextMap.t) ind :
406414
match inductive_isprop_and_pars Σ.(GlobalContextMap.global_decls) ind with
407415
| Some (prop, npars) =>

erasure/theories/EWcbvEval.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,13 @@ Section Wcbv.
12901290
now noconf H.
12911291
Qed.
12921292

1293+
Lemma eval_value v v' :
1294+
value v -> eval v v' -> v = v'.
1295+
Proof.
1296+
intros isv ev.
1297+
now pose proof (eval_deterministic ev (value_final _ isv)).
1298+
Qed.
1299+
12931300
Lemma eval_deterministic_all {t v v'} :
12941301
All2 eval t v ->
12951302
All2 eval t v' ->

erasure/theories/EWcbvEvalNamed.v

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
(* Distributed under the terms of the MIT license. *)
22
From Coq Require Import Utf8 Program.
3-
From MetaCoq.Utils Require Import utils.
43
From MetaCoq.Common Require Import config BasicAst.
4+
From MetaCoq.Utils Require Import utils.
55
From MetaCoq.PCUIC Require PCUICWcbvEval.
66
From MetaCoq.Erasure Require Import EAst EAstUtils ELiftSubst ECSubst EReflect EGlobalEnv
77
EWellformed EWcbvEval.
8+
From MetaCoq.Utils Require Import bytestring MCString.
9+
From MetaCoq.Erasure Require Import EWcbvEvalCstrsAsBlocksFixLambdaInd.
10+
From Coq Require Import BinaryString.
11+
Import String.
812

913
From Equations Require Import Equations.
1014
Require Import ssreflect ssrbool.
@@ -672,10 +676,6 @@ Local Notation "'⊩' v ~ s" := (represents_value v s) (at level 50).
672676
Local Hint Constructors represents : core.
673677
Local Hint Constructors represents_value : core.
674678

675-
From MetaCoq.Utils Require Import bytestring MCString.
676-
Require Import BinaryString.
677-
Import String.
678-
679679
Fixpoint gen_fresh_aux (na : ident) (Γ : list string) i :=
680680
match i with
681681
| 0 => na
@@ -1560,8 +1560,6 @@ Proof.
15601560
+ eapply All2_All2_Set, All2_app. eapply H1; eauto. econstructor; eauto.
15611561
Qed.
15621562

1563-
From MetaCoq Require Import EWcbvEvalCstrsAsBlocksFixLambdaInd.
1564-
15651563
Lemma lookup_in_env Σ Σ' ind i :
15661564
All2 (fun d d' => d.1 = d'.1 × match d.2 with ConstantDecl (Build_constant_body (Some body)) =>
15671565
∑ body', d'.2 = ConstantDecl (Build_constant_body (Some body')) × [] ;;; [] ⊩ body' ~ body

erasure/theories/ErasureFunctionProperties.v

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ From MetaCoq.PCUIC Require Import PCUICAst PCUICAstUtils PCUICPrimitive
88
PCUICReduction PCUICReflect PCUICWeakeningEnv PCUICWeakeningEnvTyp PCUICCasesContexts
99
PCUICWeakeningConv PCUICWeakeningTyp PCUICContextConversionTyp PCUICTyping PCUICGlobalEnv PCUICInversion PCUICGeneration
1010
PCUICConfluence PCUICConversion PCUICUnivSubstitutionTyp PCUICCumulativity PCUICSR PCUICSafeLemmata PCUICNormalization
11-
PCUICValidity PCUICPrincipality PCUICElimination PCUICOnFreeVars PCUICWellScopedCumulativity PCUICSN PCUICEtaExpand.
11+
PCUICValidity PCUICPrincipality PCUICElimination PCUICOnFreeVars PCUICWellScopedCumulativity PCUICSN PCUICEtaExpand
12+
PCUICFirstorder.
1213

1314
From MetaCoq.SafeChecker Require Import PCUICErrors PCUICWfEnv PCUICSafeReduce PCUICSafeRetyping PCUICRetypingEnvIrrelevance.
1415
From MetaCoq.Erasure Require Import EAstUtils EArities Extract Prelim EDeps ErasureProperties ErasureCorrectness ErasureFunction.
@@ -1984,9 +1985,10 @@ Proof.
19841985
intros. sq. now rewrite (abstract_env_ext_irr _ H H2).
19851986
Qed.
19861987

1987-
From MetaCoq.PCUIC Require Import PCUICFirstorder.
1988+
(*Inductive is_abstraction : EAst.term -> Prop :=
1989+
| is_lam na b : is_abstraction (EAst.tLambda na b)
1990+
| is_fix mfix idx : is_abstraction (EAst.tFix mfix idx). *)
19881991

1989-
From Equations Require Import Equations.
19901992

19911993
Inductive firstorder_evalue Σ : EAst.term -> Prop :=
19921994
| is_fo i n args npars nargs :

0 commit comments

Comments
 (0)