Skip to content

Commit 9dee1c1

Browse files
committed
Cleanup ErasureCorrectness
1 parent e022444 commit 9dee1c1

File tree

15 files changed

+752
-823
lines changed

15 files changed

+752
-823
lines changed

erasure-plugin/theories/ErasureCorrectness.v

Lines changed: 19 additions & 804 deletions
Large diffs are not rendered by default.

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/Extract.v

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,59 @@ From Coq Require Import Program ssrbool.
33
From MetaCoq.Utils Require Import utils.
44
From MetaCoq.Common Require Import config Primitive.
55
From MetaCoq.PCUIC Require Import PCUICAst PCUICAstUtils PCUICPrimitive PCUICTyping
6-
PCUICElimination PCUICWcbvEval PCUICFirstorder.
6+
PCUICElimination PCUICWcbvEval PCUICFirstorder
7+
PCUICWellScopedCumulativity PCUICFirstorder PCUICNormalization PCUICReduction
8+
PCUICConversion PCUICPrincipality PCUICNormal.
9+
710
From MetaCoq.Erasure Require EAst EGlobalEnv.
811

912
Module E := EAst.
1013

1114
Local Existing Instance extraction_checker_flags.
1215

13-
Definition isErasable Σ Γ t := ∑ T, Σ ;;; Γ |- t : T × (isArity T + (∑ u, (Σ ;;; Γ |- T : tSort u) *
14-
is_propositional u))%type.
16+
(* A term is erasable if it has _a_ type which either:
17+
- is a syntactic arity
18+
- is of propositional type *)
19+
Definition isErasable Σ Γ t :=
20+
∑ T, Σ ;;; Γ |- t : T ×
21+
(isArity T + (∑ u, (Σ ;;; Γ |- T : tSort u) * is_propositional u))%type.
22+
23+
(* A more positive notion of relevant terms.
24+
Showing that a term is not erasable requires quantification over all its possible typings.
25+
We give a more positive characterization of relevant terms. A term is not erasable if
26+
it has _a_ type in normal form which is not an arity and whose sort is not propositional.
27+
*)
28+
Definition nisErasable Σ Γ t :=
29+
∑ T u,
30+
[× Σ;;; Γ |- t : T,
31+
nf Σ Γ T,
32+
~ isArity T,
33+
Σ;;; Γ |- T : tSort u &
34+
~ is_propositional u].
35+
36+
Lemma nisErasable_spec Σ Γ t :
37+
wf_ext Σ -> wf_local Σ Γ ->
38+
nisErasable Σ Γ t -> ~ ∥ isErasable Σ Γ t ∥.
39+
Proof.
40+
intros wf wf' [T [u []]].
41+
intros []. destruct X as [T' []].
42+
destruct s.
43+
* destruct (common_typing _ _ t0 t2) as (? & e & ? & ?).
44+
eapply PCUICClassification.invert_cumul_arity_l_gen in e. destruct e as [s [[hr] ha]].
45+
eapply (proj2 (nf_red _ _ _ _)) in n. 2:eapply hr. subst. contradiction.
46+
eapply PCUICClassification.invert_cumul_arity_r_gen. 2:exact w.
47+
exists T'. split; auto. sq.
48+
eapply PCUICValidity.validity in t2 as [s Hs].
49+
eapply PCUICClassification.wt_closed_red_refl; eauto.
50+
* destruct (principal_type _ _ t0) as [princ hprinc].
51+
destruct s as [u' [hs isp]].
52+
pose proof (hprinc _ t2) as [].
53+
destruct (PCUICValidity.validity t3).
54+
eapply PCUICElimination.unique_sorting_equality_propositional in hs; tea; eauto.
55+
pose proof (hprinc _ t0) as [].
56+
eapply PCUICElimination.unique_sorting_equality_propositional in t1; tea; eauto.
57+
congruence.
58+
Qed.
1559

1660
Fixpoint mkAppBox c n :=
1761
match n with

erasure/theories/Typed/OptimizeCorrectness.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Import ExAst.
2424
Import Kernames.
2525
Import ListNotations.
2626

27+
Local Set Firstorder Solver auto.
28+
Ltac Tauto.intuition_solver ::= auto with *.
29+
2730
Lemma lookup_env_trans_env Σ kn :
2831
EGlobalEnv.lookup_env (trans_env Σ) kn =
2932
option_map trans_global_decl (lookup_env Σ kn).

pcuic/theories/PCUICEtaExpand.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,3 +1368,9 @@ Proof.
13681368
eapply IHX0_2. now eapply IHX0_1.
13691369
Qed.
13701370

1371+
Lemma expanded_tApp_arg Σ Γ t u : expanded Σ Γ (tApp t u) -> expanded Σ Γ u.
1372+
Proof.
1373+
move/expanded_mkApps_inv' => [expa _].
1374+
move: expa; rewrite (arguments_mkApps t [u]).
1375+
move/Forall_app => [] _ hu; now depelim hu.
1376+
Qed.

0 commit comments

Comments
 (0)