@@ -468,62 +468,37 @@ Definition env_flags_blocks :=
468468
469469Local Existing Instance env_flags.
470470
471- Lemma Qpreserves_wellformed Σ : wf_glob Σ -> Qpreserves (fun n x => wellformed Σ n x) Σ.
472- Proof .
473- intros clΣ.
474- split.
475- - red. move=> n t.
476- destruct t; cbn; intuition auto; try solve [constructor; auto].
477- eapply on_letin; rtoProp; intuition auto.
478- eapply on_app; rtoProp; intuition auto.
479- eapply on_case; rtoProp; intuition auto. solve_all.
480- eapply on_fix. solve_all. move/andP: H => [] _ ha. solve_all.
481- - red. intros kn decl.
482- move/(lookup_env_wellformed clΣ).
483- unfold wf_global_decl. destruct cst_body => //.
484- - red. move=> hasapp n t args. rewrite wellformed_mkApps //.
485- split; intros; rtoProp; intuition auto; solve_all.
486- - red. cbn => //.
487- (* move=> hascase n ci discr brs. simpl.
488- destruct lookup_inductive eqn:hl => /= //.
489- split; intros; rtoProp; intuition auto; solve_all. *)
490- - red. move=> hasproj n p discr. now cbn in hasproj.
491- - red. move=> t args clt cll.
492- eapply wellformed_substl. solve_all. now rewrite Nat.add_0_r.
493- - red. move=> n mfix idx. cbn. unfold wf_fix.
494- split; intros; rtoProp; intuition auto; solve_all. now apply Nat.ltb_lt.
495- - red. move=> n mfix idx. cbn.
496- split; intros; rtoProp; intuition auto; solve_all.
497- Qed .
498-
499471Definition block_wcbv_flags :=
500472 {| with_prop_case := false ; with_guarded_fix := false ; with_constructor_as_block := true |}.
501473
502474Local Hint Resolve wellformed_closed : core.
503475
504- Lemma wellformed_lookup_inductive_pars Σ kn mdecl :
476+ Lemma wellformed_lookup_inductive_pars {efl : EEnvFlags} Σ kn mdecl :
477+ has_cstr_params = false ->
505478 wf_glob Σ ->
506479 lookup_minductive Σ kn = Some mdecl -> mdecl.(ind_npars) = 0.
507480Proof .
481+ intros hasp.
508482 induction 1; cbn => //.
509483 case: eqb_spec => [|].
510484 - intros ->. destruct d => //. intros [= <-].
511485 cbn in H0. unfold wf_minductive in H0.
512- rtoProp. cbn in H0. now eapply eqb_eq in H0.
486+ rtoProp. cbn in H0. rewrite hasp in H0; now eapply eqb_eq in H0.
513487 - intros _. eapply IHwf_glob.
514488Qed .
515489
516- Lemma wellformed_lookup_constructor_pars {Σ kn c mdecl idecl cdecl} :
490+ Lemma wellformed_lookup_constructor_pars {efl : EEnvFlags} {Σ kn c mdecl idecl cdecl} :
491+ has_cstr_params = false ->
517492 wf_glob Σ ->
518493 lookup_constructor Σ kn c = Some (mdecl, idecl, cdecl) -> mdecl.(ind_npars) = 0.
519494Proof .
520- intros wf. cbn -[lookup_minductive].
495+ intros hasp wf. cbn -[lookup_minductive].
521496 destruct lookup_minductive eqn:hl => //.
522497 do 2 destruct nth_error => //.
523498 eapply wellformed_lookup_inductive_pars in hl => //. congruence.
524499Qed .
525500
526- Lemma lookup_constructor_pars_args_spec {Σ ind n mdecl idecl cdecl} :
501+ Lemma lookup_constructor_pars_args_spec {efl : EEnvFlags} { Σ ind n mdecl idecl cdecl} :
527502 wf_glob Σ ->
528503 lookup_constructor Σ ind n = Some (mdecl, idecl, cdecl) ->
529504 lookup_constructor_pars_args Σ ind n = Some (mdecl.(ind_npars), cdecl.(cstr_nargs)).
@@ -533,23 +508,25 @@ Proof.
533508 intros [= -> -> <-]. cbn. f_equal.
534509Qed .
535510
536- Lemma wellformed_lookup_constructor_pars_args {Σ ind n block_args} :
511+ Lemma wellformed_lookup_constructor_pars_args {efl : EEnvFlags} { Σ ind n block_args} :
537512 wf_glob Σ ->
513+ has_cstr_params = false ->
538514 wellformed Σ 0 (EAst.tConstruct ind n block_args) ->
539515 ∑ args, lookup_constructor_pars_args Σ ind n = Some (0, args).
540516Proof .
541- intros wfΣ wf. cbn -[lookup_constructor] in wf.
517+ intros wfΣ hasp wf. cbn -[lookup_constructor] in wf.
542518 destruct lookup_constructor as [[[mdecl idecl] cdecl]|] eqn:hl => //.
543519 exists cdecl.(cstr_nargs).
544- pose proof (wellformed_lookup_constructor_pars wfΣ hl).
520+ pose proof (wellformed_lookup_constructor_pars hasp wfΣ hl).
545521 eapply lookup_constructor_pars_args_spec in hl => //. congruence.
522+ destruct has_tConstruct => //.
546523Qed .
547524
548- Lemma constructor_isprop_pars_decl_params {Σ ind c b pars cdecl} :
549- wf_glob Σ ->
525+ Lemma constructor_isprop_pars_decl_params {efl : EEnvFlags} { Σ ind c b pars cdecl} :
526+ has_cstr_params = false -> wf_glob Σ ->
550527 constructor_isprop_pars_decl Σ ind c = Some (b, pars, cdecl) -> pars = 0.
551528Proof .
552- intros hwf.
529+ intros hasp hwf.
553530 rewrite /constructor_isprop_pars_decl /lookup_constructor /lookup_inductive.
554531 destruct lookup_minductive as [mdecl|] eqn:hl => /= //.
555532 do 2 destruct nth_error => //.
@@ -601,7 +578,7 @@ Proof.
601578 + eapply EEtaExpandedFix.decompose_app_tApp_split in da as [Ha Ht].
602579 cbn in wf.
603580 move: wf => /andP[]. rewrite Ha wellformed_mkApps // => /andP[] wfc wfl wft.
604- destruct (wellformed_lookup_constructor_pars_args wfΣ wfc).
581+ destruct (wellformed_lookup_constructor_pars_args wfΣ eq_refl wfc).
605582 rewrite e. cbn.
606583 destruct chop eqn:eqch => //.
607584 intros. apply H1. intuition auto.
@@ -674,14 +651,17 @@ Proof.
674651Qed .
675652
676653Lemma lookup_constructor_transform_blocks Σ ind c :
677- lookup_constructor (transform_blocks_env Σ) ind c =
678- lookup_constructor Σ ind c.
654+ lookup_constructor (transform_blocks_env Σ) ind c =
655+ lookup_constructor Σ ind c.
679656Proof .
680657 unfold lookup_constructor, lookup_inductive, lookup_minductive in *.
681658 rewrite lookup_env_transform_blocks.
682659 destruct lookup_env as [ [] | ]; cbn; congruence.
683660Qed .
684661
662+ Lemma isLambda_transform_blocks Σ c : isLambda c -> isLambda (transform_blocks Σ c).
663+ Proof . destruct c => //. Qed .
664+
685665Lemma transform_wellformed' Σ n t :
686666 wf_glob Σ ->
687667 @wellformed env_flags Σ n t ->
@@ -692,9 +672,12 @@ Proof.
692672 all: rewrite ?map_InP_spec; toAll; eauto; try now solve_all.
693673 - destruct H1. unfold isEtaExp_app in H1. unfold lookup_constructor_pars_args in *.
694674 destruct (lookup_constructor Σ) as [[[]] | ]; try congruence; cbn - [transform_blocks].
695- 2: eauto. split; auto.
675+ 2: eauto. split; auto. cbn in H1. eapply Nat.leb_le in H1.
676+ apply/eqb_spec. lia.
696677 - destruct H4. solve_all.
697- - unfold wf_fix in *. rtoProp. solve_all. len. solve_all. len. destruct x.
678+ - unfold wf_fix in *. rtoProp. solve_all. now eapply isLambda_transform_blocks.
679+ - unfold wf_fix in *. rtoProp. solve_all.
680+ len. solve_all. len. destruct x.
698681 cbn -[transform_blocks isEtaExp] in *. rtoProp. eauto.
699682 - rewrite !wellformed_mkApps in Hw |- * => //. rtoProp. intros.
700683 eapply isEtaExp_mkApps in H3. rewrite decompose_app_mkApps in H3; eauto.
@@ -708,16 +691,18 @@ Proof.
708691 rewrite ?lookup_constructor_transform_blocks; eauto.
709692 * destruct lookup_constructor as [ [[]] | ] eqn:E; cbn -[transform_blocks] in *; eauto.
710693 invs Heq. rewrite chop_firstn_skipn in Ec. invs Ec.
711- rewrite firstn_length. len. eapply Nat.leb_le in H2. eapply Nat.leb_le.
712- destruct lookup_env as [ [] | ] eqn:E'; try congruence.
713- eapply lookup_env_wellformed in E'; eauto.
714- cbn in E'. red in E'. unfold wf_minductive in E'.
715- rewrite andb_true_iff in E'.
716- cbn in E'. destruct E'.
717- eapply Nat.eqb_eq in H6.
718- destruct nth_error; invs E.
719- destruct nth_error; invs H9.
720- rewrite H6. lia.
694+ rewrite firstn_length. len. eapply Nat.leb_le in H2.
695+ apply/eqb_spec.
696+ assert (ind_npars m0 = 0).
697+ { destruct lookup_env as [ [] | ] eqn:E'; try congruence.
698+ eapply lookup_env_wellformed in E'; eauto.
699+ cbn in E'. red in E'. unfold wf_minductive in E'.
700+ rewrite andb_true_iff in E'.
701+ cbn in E'. destruct E'.
702+ eapply Nat.eqb_eq in H6.
703+ destruct nth_error; invs E.
704+ now destruct nth_error; invs H9. }
705+ lia.
721706 * rewrite chop_firstn_skipn in Ec. invs Ec.
722707 solve_all. eapply All_firstn. solve_all.
723708 * rewrite chop_firstn_skipn in Ec. invs Ec.
@@ -994,11 +979,18 @@ Proof.
994979 eapply All2_length in X0 as Hlen.
995980 cbn.
996981 rewrite !skipn_all Hlen skipn_all firstn_all. cbn.
997- eapply eval_mkApps_Construct_block ; tea. eauto.
982+ eapply eval_construct_block ; tea. eauto.
998983 now rewrite lookup_constructor_transform_blocks.
999- constructor. cbn [atom]. now rewrite lookup_constructor_transform_blocks H.
1000- len. unfold cstr_arity. lia.
1001- solve_all. destruct H6; eauto.
1002- - intros. econstructor. destruct t; try solve [cbn in H, H0 |- *; try congruence].
1003- cbn -[lookup_constructor] in H |- *. destruct l => //. now rewrite lookup_constructor_transform_blocks H.
984+ unfold cstr_arity. cbn. rewrite H4; len.
985+ solve_all. clear -X0. eapply All2_All2_Set. solve_all.
986+ apply H.
987+ - intros. destruct t; try solve [constructor; cbn in H, H0 |- *; try congruence].
988+ cbn -[lookup_constructor] in H |- *. destruct l => //.
989+ destruct lookup_constructor eqn:hl => //.
990+ destruct p as [[mdecl idecl] cdecl].
991+ eapply eval_construct_block => //.
992+ now rewrite lookup_constructor_transform_blocks hl.
993+ simp_eta in H1. cbn in H1. unfold isEtaExp_app in H1.
994+ rewrite (lookup_constructor_pars_args_spec wfΣ hl) andb_true_r in H1.
995+ apply Nat.leb_le in H1; cbn; unfold cstr_arity. lia.
1004996Qed .
0 commit comments