Skip to content

Commit 662169d

Browse files
authored
Merge pull request #472 from MetaCoq/fix-erase-projs
Fix the erasure of projection types that was done in the wrong context.
2 parents 9dfb42d + e0dba17 commit 662169d

File tree

2 files changed

+24
-45
lines changed

2 files changed

+24
-45
lines changed

erasure/theories/SafeErasureFunction.v

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
658643
Next Obligation.
@@ -668,12 +653,6 @@ Next Obligation.
668653
sq. inv X. apply X0.
669654
Qed.
670655

671-
672-
Next Obligation.
673-
sq. split. cbn.
674-
eapply PCUICWeakeningEnv.wf_extends. eauto. eexists [_]; reflexivity.
675-
now inversion X; subst.
676-
Qed.
677656
Next Obligation.
678657
sq. eapply PCUICWeakeningEnv.wf_extends. eauto. eexists [_]; reflexivity.
679658
Qed.
@@ -685,7 +664,7 @@ Program Definition erase_global Σ : ∥wf Σ∥ -> _:=
685664

686665

687666
Lemma erase_global_correct Σ (wfΣ : ∥ wf Σ∥) Σ' :
688-
erase_global Σ wfΣ = Checked Σ' ->
667+
erase_global Σ wfΣ = CorrectDecl Σ' ->
689668
erases_global Σ Σ'.
690669
Proof.
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 *.

erasure/theories/SafeTemplateErasure.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Program Definition erase_template_program (p : Ast.program)
131131
: EnvCheck (EAst.global_context * EAst.term) :=
132132
let Σ := (trans_global (Ast.empty_ext p.1)).1 in
133133
G <- check_wf_env_only_univs Σ ;;
134-
Σ' <- wrap_error (empty_ext Σ) "erasure of the global context" (SafeErasureFunction.erase_global Σ _) ;;
134+
Σ' <- (SafeErasureFunction.erase_global Σ _) ;;
135135
t <- wrap_error (empty_ext Σ) ("During erasure of " ++ string_of_term (trans p.2)) (SafeErasureFunction.erase (empty_ext Σ) _ nil (trans p.2) _);;
136136
ret (Monad:=envcheck_monad) (Σ', t).
137137

@@ -150,7 +150,6 @@ Qed.
150150

151151
Local Open Scope string_scope.
152152

153-
154153
(** This uses the checker-based erasure *)
155154
Program Definition erase_and_print_template_program_check {cf : checker_flags} (p : Ast.program)
156155
: string + string :=

0 commit comments

Comments
 (0)