Skip to content

Commit 29126ac

Browse files
authored
Ensure constant constructors are declared in evaluation (#718)
1 parent daf3e47 commit 29126ac

File tree

8 files changed

+35
-26
lines changed

8 files changed

+35
-26
lines changed

erasure/theories/EEtaExpandedFix.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ Proof.
18411841
rewrite (remove_last_last l a hl).
18421842
rewrite -[tApp _ _](mkApps_app _ _ [a']).
18431843
eapply eval_mkApps_Construct; tea.
1844-
{ now constructor. }
1844+
{ constructor. cbn [atom]; rewrite H //. }
18451845
{ len. rewrite (All2_length hargs). lia. }
18461846
eapply All2_app.
18471847
eapply forallb_remove_last, forallb_All in etal.

erasure/theories/EInlineProjections.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ Proof.
656656
destruct v => /= //.
657657
- destruct t => //.
658658
all:constructor; eauto.
659+
cbn [atom optimize] in i |- *.
660+
rewrite -lookup_constructor_optimize //.
659661
Qed.
660662

661663
From MetaCoq.Erasure Require Import EEtaExpanded.

erasure/theories/EOptimizePropDiscr.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ Proof.
698698
destruct args using rev_case => // /=. rewrite map_app !mkApps_app /= //.
699699
destruct v => /= //.
700700
- destruct t => //.
701-
all:constructor; eauto.
701+
all:constructor; eauto. cbn [atom optimize] in i |- *.
702+
rewrite -lookup_constructor_optimize //.
702703
Qed.
703704

704705
(*

erasure/theories/ERemoveParams.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ Proof.
965965
rewrite (lookup_constructor_lookup_inductive_pars H).
966966
eapply eval_mkApps_Construct; tea.
967967
+ rewrite lookup_constructor_strip H //.
968-
+ now constructor.
968+
+ constructor. cbn [atom]. rewrite lookup_constructor_strip H //.
969969
+ rewrite /cstr_arity /=.
970970
move: H0; rewrite /cstr_arity /=.
971971
rewrite skipn_length map_length => ->. lia.
@@ -974,7 +974,10 @@ Proof.
974974
intros x y []; auto.
975975

976976
- destruct t => //.
977-
all:constructor; eauto.
977+
all:constructor; eauto. simp strip.
978+
cbn [atom strip] in H |- *.
979+
rewrite lookup_constructor_strip.
980+
destruct lookup_constructor eqn:hl => //. destruct p as [[] ?] => //.
978981
Qed.
979982

980983
From MetaCoq.Erasure Require Import EEtaExpanded.

erasure/theories/EWcbvEval.v

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Local Ltac inv H := inversion H; subst.
2727

2828
(** ** Big step version of weak cbv beta-zeta-iota-fix-delta reduction. *)
2929

30-
Definition atom t :=
30+
Definition atom Σ t :=
3131
match t with
3232
| tBox
33-
| tConstruct _ _
3433
| tCoFix _ _
3534
| tLambda _ _
3635
| tFix _ _ => true
36+
| tConstruct ind c => isSome (lookup_constructor Σ ind c)
3737
| _ => false
3838
end.
3939

@@ -47,7 +47,7 @@ Definition isStuckFix t (args : list term) :=
4747
| _ => false
4848
end.
4949

50-
Lemma atom_mkApps f l : atom (mkApps f l) -> (l = []) /\ atom f.
50+
Lemma atom_mkApps Σ f l : atom Σ (mkApps f l) -> (l = []) /\ atom Σ f.
5151
Proof.
5252
revert f; induction l using rev_ind. simpl. intuition auto.
5353
simpl. intros. now rewrite mkApps_app in H.
@@ -197,7 +197,7 @@ Section Wcbv.
197197

198198

199199
(** Atoms are values (includes abstractions, cofixpoints and constructors) *)
200-
| eval_atom t : atom t -> eval t t.
200+
| eval_atom t : atom Σ t -> eval t t.
201201

202202
Hint Constructors eval : core.
203203
Derive Signature for eval.
@@ -227,7 +227,7 @@ Section Wcbv.
227227
Derive Signature NoConfusion for value_head.
228228

229229
Inductive value : term -> Type :=
230-
| value_atom t : atom t -> value t
230+
| value_atom t : atom Σ t -> value t
231231
| value_app_nonnil f args : value_head #|args| f -> args <> [] -> All value args -> value (mkApps f args).
232232
Derive Signature for value.
233233

@@ -245,12 +245,12 @@ Section Wcbv.
245245
Lemma value_app f args : value_head #|args| f -> All value args -> value (mkApps f args).
246246
Proof.
247247
destruct args.
248-
- intros [] hv; now constructor.
248+
- intros [] hv; constructor; try easy. cbn [atom mkApps]. now rewrite e.
249249
- intros vh av. eapply value_app_nonnil => //.
250250
Qed.
251251

252252
Lemma value_values_ind : forall P : term -> Type,
253-
(forall t, atom t -> P t) ->
253+
(forall t, atom Σ t -> P t) ->
254254
(forall f args, value_head #|args| f -> args <> [] -> All value args -> All P args -> P (mkApps f args)) ->
255255
forall t : term, value t -> P t.
256256
Proof.
@@ -270,14 +270,14 @@ Section Wcbv.
270270
Proof. destruct t; auto. Qed.
271271
Hint Resolve isStuckfix_nApp : core.
272272

273-
Lemma atom_nApp {t} : atom t -> ~~ isApp t.
273+
Lemma atom_nApp {t} : atom Σ t -> ~~ isApp t.
274274
Proof. destruct t; auto. Qed.
275275
Hint Resolve atom_nApp : core.
276276

277277
Lemma value_mkApps_inv t l :
278278
~~ isApp t ->
279279
value (mkApps t l) ->
280-
((l = []) /\ atom t) + ([× l <> [], value_head #|l| t & All value l]).
280+
((l = []) /\ atom Σ t) + ([× l <> [], value_head #|l| t & All value l]).
281281
Proof.
282282
intros H H'. generalize_eq x (mkApps t l).
283283
revert x H' t H. apply: value_values_ind.
@@ -353,7 +353,7 @@ Section Wcbv.
353353
value_head n t -> eval t t.
354354
Proof.
355355
destruct 1.
356-
- now constructor.
356+
- constructor; try easy. now cbn [atom]; rewrite e.
357357
- now eapply eval_atom.
358358
- now eapply eval_atom.
359359
Qed.
@@ -362,9 +362,9 @@ Section Wcbv.
362362
(* It means no redex can remain at the head of an evaluated term. *)
363363

364364
Lemma value_head_spec' n t :
365-
value_head n t -> (~~ (isLambda t || isBox t)) && atom t.
365+
value_head n t -> (~~ (isLambda t || isBox t)) && atom Σ t.
366366
Proof.
367-
induction 1; cbn => //.
367+
induction 1; auto. cbn [atom]; rewrite e //.
368368
Qed.
369369

370370

@@ -953,7 +953,9 @@ Section WcbvEnv.
953953
induction ev; try solve [econstructor;
954954
eauto using (extends_lookup_constructor wf ex), (extends_constructor_isprop_pars_decl wf ex), (extends_is_propositional wf ex)].
955955
econstructor; eauto.
956-
red in isdecl |- *. eauto using extends_lookup.
956+
red in isdecl |- *. eauto using extends_lookup. constructor.
957+
destruct t => //. cbn [atom] in i. destruct lookup_constructor eqn:hl => //.
958+
eapply (extends_lookup_constructor wf ex) in hl. now cbn [atom].
957959
Qed.
958960

959961
End WcbvEnv.
@@ -1359,7 +1361,7 @@ Qed.
13591361

13601362
Lemma eval_mkApps_Construct_inv {fl : WcbvFlags} Σ kn c args e :
13611363
eval Σ (mkApps (tConstruct kn c) args) e ->
1362-
∑ args', (e = mkApps (tConstruct kn c) args') × All2 (eval Σ) args args'.
1364+
∑ args', [× isSome (lookup_constructor Σ kn c), (e = mkApps (tConstruct kn c) args') & All2 (eval Σ) args args'].
13631365
Proof.
13641366
revert e; induction args using rev_ind; intros e.
13651367
- intros ev. depelim ev. exists []=> //.
@@ -1472,18 +1474,18 @@ Lemma eval_mkApps_Construct_size {wfl : WcbvFlags} {Σ ind c args v} :
14721474
Proof.
14731475
intros ev.
14741476
destruct (eval_mkApps_inv_size ev) as [f'' [args' [? []]]].
1475-
exists args'.
1476-
exists (eval_atom _ (tConstruct ind c) eq_refl).
1477+
exists args'.
1478+
destruct (eval_mkApps_Construct_inv _ _ _ _ _ ev) as [? []]. subst v.
1479+
exists (eval_atom _ (tConstruct ind c) i).
14771480
cbn. split => //. destruct ev; cbn => //; auto with arith.
14781481
clear l.
1479-
destruct (eval_mkApps_Construct_inv _ _ _ _ _ ev) as [? []]. subst v.
14801482
eapply (eval_mkApps_Construct_inv _ _ _ []) in x as [? []]. subst f''. depelim a1.
14811483
f_equal.
14821484
eapply eval_deterministic_all; tea.
14831485
eapply All2_impl; tea; cbn; eauto. now intros x y [].
14841486
Qed.
14851487

1486-
Lemma eval_construct_size {fl : WcbvFlags} [Σ kn c args e] :
1488+
Lemma eval_construct_size {fl : WcbvFlags} [Σ kn c args e] :
14871489
forall (ev : eval Σ (mkApps (tConstruct kn c) args) e),
14881490
∑ args', (e = mkApps (tConstruct kn c) args') ×
14891491
All2 (fun x y => ∑ ev' : eval Σ x y, eval_depth ev' < eval_depth ev) args args'.

erasure/theories/EWcbvEvalEtaInd.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Lemma eval_preserve_mkApps_ind :
313313
All2 P args args' ->
314314
P' (mkApps (tConstruct ind i) args) (mkApps (tConstruct ind i) args')) →
315315

316-
(∀ t : term, atom t → Q 0 t -> isEtaExp Σ t -> P' t t) ->
316+
(∀ t : term, atom Σ t → Q 0 t -> isEtaExp Σ t -> P' t t) ->
317317
∀ (t t0 : term), Q 0 t -> isEtaExp Σ t -> eval Σ t t0 → P' t t0.
318318
Proof.
319319
intros * Qpres P P'Q etaΣ wfΣ hasapp.

erasure/theories/EWcbvEvalInd.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Section eval_mkApps_rect.
159159
→ eval Σ a a'
160160
→ P a a'
161161
→ P (tApp f11 a) (tApp f' a'))
162-
→ (∀ t : term, atom t → P t t)
162+
→ (∀ t : term, atom Σ t → P t t)
163163
→ ∀ t t0 : term, eval Σ t t0 → P t t0.
164164
Proof using Type.
165165
intros ?????????????????? H.

erasure/theories/ErasureCorrectness.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,8 @@ Proof.
11021102
* eexists. split. 2: now constructor; econstructor.
11031103
econstructor; eauto.
11041104
+ invs He.
1105-
* eexists. split. 2: now constructor; econstructor.
1105+
* eexists. split. 2:{ constructor; econstructor. cbn [EWcbvEval.atom].
1106+
depelim Hed. eapply EGlobalEnv.declared_constructor_lookup in H0. now rewrite H0. }
11061107
econstructor; eauto.
11071108
* eexists. split. 2: now constructor; econstructor.
11081109
eauto.
@@ -1114,7 +1115,7 @@ Proof.
11141115
* eexists. split; eauto. now constructor; econstructor.
11151116
* eexists. split. 2: now constructor; econstructor.
11161117
econstructor; eauto.
1117-
Unshelve. all: repeat econstructor.
1118+
Unshelve. all: repeat econstructor.
11181119
Qed.
11191120

11201121
(* Print Assumptions erases_correct. *)

0 commit comments

Comments
 (0)