Skip to content

Commit efb65d2

Browse files
authored
Merge pull request #1239 from mattam82/9.0-remap-mutual-block
Remap not just one inductive but whole blocks at a time.
2 parents cd83f0a + bd3c37d commit efb65d2

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

erasure/theories/EProgram.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Record extract_inductive :=
2525
{ cstrs : list kername; (* One constant for each constructor *)
2626
elim : kername } (* The new eliminator *).
2727

28-
Definition extract_inductives := list (inductive * extract_inductive).
28+
(** Association from one mutual inductive block to the translations of each of its components *)
29+
Definition extract_inductives := list (kername * list extract_inductive).
2930

3031
Definition eprogram := (EAst.global_context * EAst.term).
3132
Definition eprogram_env := (EEnvMap.GlobalContextMap.t * EAst.term).

erasure/theories/ERemapInductives.v

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Proof.
2323
intros [= <- <- <-]. intuition auto.
2424
Qed.
2525

26-
Fixpoint lookup_inductive_assoc {A} (Σ : list (inductive × A)) (kn : inductive) {struct Σ} : option A :=
26+
Fixpoint lookup_kername_assoc {A} (Σ : list (kername × A)) (kn : kername) {struct Σ} : option A :=
2727
match Σ with
2828
| [] => None
29-
| d :: tl => if kn == d.1 then Some d.2 else lookup_inductive_assoc tl kn
29+
| d :: tl => if kn == d.1 then Some d.2 else lookup_kername_assoc tl kn
3030
end.
3131

3232
Equations filter_map {A B} (f : A -> option B) (l : list A) : list B :=
@@ -39,9 +39,13 @@ Section Remap.
3939
Context (Σ : global_declarations).
4040
Context (mapping : extract_inductives).
4141

42-
Definition lookup_constructor_mapping i c : option kername :=
43-
trs <- lookup_inductive_assoc mapping i ;;
44-
nth_error trs.(cstrs) c.
42+
Definition lookup_inductive_assoc i : option extract_inductive :=
43+
trs <- lookup_kername_assoc mapping (inductive_mind i) ;;
44+
nth_error trs (inductive_ind i).
45+
46+
Definition lookup_constructor_mapping (i : inductive) c : option kername :=
47+
tri <- lookup_inductive_assoc i ;;
48+
nth_error tri.(cstrs) c.
4549

4650
Definition lookup_constructor_remapping i c args :=
4751
match lookup_constructor_mapping i c with
@@ -62,7 +66,7 @@ Section Remap.
6266
end.
6367

6468
Definition remap_case i c brs :=
65-
match lookup_inductive_assoc mapping (fst i) with
69+
match lookup_inductive_assoc (fst i) with
6670
| None => tCase i c brs
6771
| Some tr =>
6872
mkApps (tConst tr.(elim)) (c :: map make_branch brs)
@@ -93,24 +97,26 @@ Section Remap.
9397
Definition remap_constant_decl cb :=
9498
{| cst_body := option_map remap cb.(cst_body) |}.
9599

96-
Definition remaped_one_ind kn i (oib : one_inductive_body) : bool :=
97-
match lookup_inductive_assoc mapping {| inductive_mind := kn; inductive_ind := i |} with
98-
| None => false
99-
| Some trs => true
100-
end.
100+
Definition axiom (kn : kername) := (kn, ConstantDecl {| cst_body := None |}).
101+
Definition remapping_decls tr :=
102+
let cstrs := map axiom tr.(cstrs) in
103+
axiom tr.(elim) :: cstrs.
101104

102105
Definition remap_inductive_decl kn idecl :=
103-
let remapings := mapi (remaped_one_ind kn) idecl.(ind_bodies) in
104-
List.forallb (fun b => b) remapings.
106+
match lookup_kername_assoc mapping kn with
107+
| None => [(kn, InductiveDecl idecl)]
108+
| Some trs =>
109+
concat (map remapping_decls trs)
110+
end.
105111

106112
Definition remap_decl d :=
107113
match d.2 with
108-
| ConstantDecl cb => Some (d.1, ConstantDecl (remap_constant_decl cb))
109-
| InductiveDecl idecl => if remap_inductive_decl d.1 idecl then None else Some d
114+
| ConstantDecl cb => [(d.1, ConstantDecl (remap_constant_decl cb))]
115+
| InductiveDecl idecl => remap_inductive_decl d.1 idecl
110116
end.
111117

112118
Definition remap_env Σ :=
113-
filter_map (remap_decl) Σ.
119+
concat (map (remap_decl) Σ).
114120

115121
End Remap.
116122

0 commit comments

Comments
 (0)