@@ -611,48 +611,33 @@ Definition lift_opt_typing {A} (a : option A) (e : type_error) : typing_result A
611611 | None => raise e
612612 end .
613613
614- Program
615- Definition erase_one_inductive_body (Σ : global_env_ext) (wfΣ : ∥ wf_ext Σ ∥) npars
616- (arities : context)
617- (oib : one_inductive_body) : typing_result E.one_inductive_body :=
618-
619- decty <- lift_opt_typing (decompose_prod_n_assum [] npars oib.(ind_type))
620- (NotAnInductive oib.(ind_type)) ;;
621- let '(params, arity) := (decty : context * term) in
622- (* type <- erase Σ wfΣ [] wf_local_nil oib.(ind_type) ;; *)
623- ctors <- monad_map (A:=(ident * term) * nat) (fun '((x, y), z) => y' <- erase Σ wfΣ arities y _;; ret (x, y', z)) oib.(ind_ctors);;
624- (* FIXME not used! let projctx := arities ,,, params ,, vass nAnon oib.(ind_type) in *)
625- projs <- monad_map (fun '(x, y) => y' <- erase Σ wfΣ [] (y : term) _;; ret (x, y')) oib.(ind_projs);;
626- ret {| E.ind_name := oib.(ind_name);
627- E.ind_kelim := oib.(ind_kelim);
628- E.ind_ctors := ctors;
629- E.ind_projs := projs |}.
630- Next Obligation .
631- intros. todo "welltyped threading".
632- Qed .
633- Next Obligation .
634- intros. todo "welltyped threading".
635- Qed .
636-
637- Program Definition erase_mutual_inductive_body Σ wfΣ
638- (mib : mutual_inductive_body)
639- : typing_result E.mutual_inductive_body :=
614+ Definition erase_one_inductive_body (oib : one_inductive_body) : E.one_inductive_body :=
615+ (* Projection and constructor types are types, hence always erased *)
616+ let ctors := map (A:=(ident * term) * nat) (fun '((x, y), z) => (x, EAst.tBox, z)) oib.(ind_ctors) in
617+ let projs := map (fun '(x, y) => (x, EAst.tBox)) oib.(ind_projs) in
618+ {| E.ind_name := oib.(ind_name);
619+ E.ind_kelim := oib.(ind_kelim);
620+ E.ind_ctors := ctors;
621+ E.ind_projs := projs |}.
622+
623+ Definition erase_mutual_inductive_body (mib : mutual_inductive_body) : E.mutual_inductive_body :=
640624 let bds := mib.(ind_bodies) in
641625 let arities := arities_context bds in
642- bodies <- monad_map ( erase_one_inductive_body Σ wfΣ mib.(ind_npars) arities) bds ;;
643- ret {| E.ind_npars := mib.(ind_npars);
644- E.ind_bodies := bodies; |}.
626+ let bodies := map erase_one_inductive_body bds in
627+ {| E.ind_npars := mib.(ind_npars);
628+ E.ind_bodies := bodies; |}.
645629
646- Program Fixpoint erase_global_decls Σ : ∥ wf Σ ∥ -> typing_result E.global_declarations := fun wfΣ =>
630+ Program Fixpoint erase_global_decls Σ : ∥ wf Σ ∥ -> EnvCheck E.global_declarations := fun wfΣ =>
647631 match Σ with
648632 | [] => ret []
649- | (kn, ConstantDecl cb) :: Σ =>
650- cb' <- erase_constant_body (Σ, cst_universes cb) _ cb _;;
651- Σ' <- erase_global_decls Σ _;;
633+ | (kn, ConstantDecl cb) :: Σ' =>
634+ cb' <- wrap_error (Σ', cst_universes cb) ("Erasure of " ++ string_of_kername kn)
635+ (erase_constant_body (Σ', cst_universes cb) _ cb _);;
636+ Σ' <- erase_global_decls Σ' _;;
652637 ret ((kn, E.ConstantDecl cb') :: Σ')
653- | (kn, InductiveDecl mib) :: Σ =>
654- mib' <- erase_mutual_inductive_body (Σ, ind_universes mib) _ mib ;;
655- Σ' <- erase_global_decls Σ _;;
638+ | (kn, InductiveDecl mib) :: Σ' =>
639+ let mib' := erase_mutual_inductive_body mib in
640+ Σ' <- erase_global_decls Σ' _;;
656641 ret ((kn, E.InductiveDecl mib') :: Σ')
657642 end .
658643Next Obligation .
@@ -668,12 +653,6 @@ Next Obligation.
668653 sq. inv X. apply X0.
669654Qed .
670655
671-
672- Next Obligation .
673- sq. split. cbn.
674- eapply PCUICWeakeningEnv.wf_extends. eauto . eexists [_]; reflexivity.
675- now inversion X; subst.
676- Qed .
677656Next Obligation .
678657 sq. eapply PCUICWeakeningEnv.wf_extends. eauto . eexists [_]; reflexivity.
679658Qed .
@@ -685,7 +664,7 @@ Program Definition erase_global Σ : ∥wf Σ∥ -> _:=
685664
686665
687666Lemma erase_global_correct Σ (wfΣ : ∥ wf Σ∥) Σ' :
688- erase_global Σ wfΣ = Checked Σ' ->
667+ erase_global Σ wfΣ = CorrectDecl Σ' ->
689668 erases_global Σ Σ'.
690669Proof .
691670 induction Σ in wfΣ, Σ' |- *; intros; sq.
@@ -696,6 +675,7 @@ Proof.
696675 unfold bind in E2. cbn in E2. repeat destruct ?; try congruence.
697676 inv E2. econstructor.
698677 all:todo "finish".
678+ + all:todo "finish".
699679(* * unfold optM in E0. destruct ?; try congruence.
700680 -- unfold erases_constant_body.
701681 cbn. cbn in *.
0 commit comments