Skip to content

Commit 29994d4

Browse files
committed
Take relevance into account for typing
1 parent fa25a7f commit 29994d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1527
-1015
lines changed

common/theories/BasicAst.v

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ Lemma map_dbody {A B} (f : A -> B) (g : A -> B) (d : def A) :
138138
g (dbody d) = dbody (map_def f g d).
139139
Proof. destruct d; reflexivity. Qed.
140140

141+
Lemma map_dname {A B} (f : A -> B) (g : A -> B) (d : def A) :
142+
dname d = dname (map_def f g d).
143+
Proof. destruct d; reflexivity. Qed.
144+
141145
Definition mfixpoint term := list (def term).
142146

143147
Definition test_def {A} (tyf bodyf : A -> bool) (d : def A) :=
@@ -217,13 +221,13 @@ Record judgment_ {universe Term} := Judge {
217221
j_term : option Term;
218222
j_typ : Term;
219223
j_univ : option universe;
220-
(* j_rel : option relevance; *)
224+
j_rel : option relevance;
221225
}.
222226
Arguments judgment_ : clear implicits.
223227
Arguments Judge {universe Term} _ _ _.
224228

225229
Definition judgment_map {univ T A} (f: T -> A) (j : judgment_ univ T) :=
226-
Judge (option_map f (j_term j)) (f (j_typ j)) (j_univ j) (* (j_rel j) *).
230+
Judge (option_map f (j_term j)) (f (j_typ j)) (j_univ j) (j_rel j).
227231

228232
Section Contexts.
229233
Context {term : Type}.
@@ -239,17 +243,21 @@ End Contexts.
239243

240244
Arguments context_decl : clear implicits.
241245

242-
Notation Typ typ := (Judge None typ None).
243-
Notation TermTyp tm ty := (Judge (Some tm) ty None).
244-
Notation TermoptTyp tm typ := (Judge tm typ None).
245-
Notation TypUniv ty u := (Judge None ty (Some u)).
246-
Notation TermTypUniv tm ty u := (Judge (Some tm) ty (Some u)).
247-
248-
Notation j_vass na ty := (Typ ty (* na.(binder_relevance) *)) (only parsing).
249-
Notation j_vass_s na ty s := (TypUniv ty s (* na.(binder_relevance) *)) (only parsing).
250-
Notation j_vdef na b ty := (TermTyp b ty (* na.(binder_relevance) *)) (only parsing).
251-
Notation j_decl d := (TermoptTyp (decl_body d) (decl_type d) (* (decl_name d).(binder_relevance) *)).
252-
Notation j_decl_s d s := (Judge (decl_body d) (decl_type d) s (* (decl_name d).(binder_relevance) *)).
246+
Notation Typ typ := (Judge None typ None None).
247+
Notation TypRel typ rel := (Judge None typ None (Some rel)).
248+
Notation TermTyp tm ty := (Judge (Some tm) ty None None).
249+
Notation TermTypRel tm ty rel := (Judge (Some tm) ty None (Some rel)).
250+
Notation TermoptTyp tm typ := (Judge tm typ None None).
251+
Notation TermoptTypRel tm typ rel := (Judge tm typ None (Some rel)).
252+
Notation TypUniv ty u := (Judge None ty (Some u) None).
253+
Notation TypUnivRel ty u rel := (Judge None ty (Some u) (Some rel)).
254+
Notation TermTypUniv tm ty u := (Judge (Some tm) ty (Some u) None).
255+
256+
Notation j_vass na ty := (TypRel ty na.(binder_relevance)).
257+
Notation j_vass_s na ty s := (TypUnivRel ty s na.(binder_relevance)).
258+
Notation j_vdef na b ty := (TermTypRel b ty na.(binder_relevance)).
259+
Notation j_decl d := (TermoptTypRel (decl_body d) (decl_type d) (decl_name d).(binder_relevance)).
260+
Notation j_decl_s d s := (Judge (decl_body d) (decl_type d) s (Some (decl_name d).(binder_relevance))).
253261

254262
Definition map_decl {term term'} (f : term -> term') (d : context_decl term) : context_decl term' :=
255263
{| decl_name := d.(decl_name);

common/theories/Environment.v

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ Module Environment (T : Term).
155155
(** Local (de Bruijn) context *)
156156

157157
Definition context := list context_decl.
158+
Definition mark_context := list relevance.
159+
Definition marks_of_context : context -> mark_context := fun l => List.map (fun d => d.(decl_name).(binder_relevance)) l.
158160

159161
(** Last declaration first *)
160162

@@ -895,7 +897,7 @@ Module Environment (T : Term).
895897
end.
896898

897899
Definition tImpl (dom codom : term) : term :=
898-
tProd {| binder_name := nAnon; binder_relevance := Relevant |}
900+
tProd {| binder_name := nAnon; binder_relevance := rel_of_Type |}
899901
dom (lift 1 0 codom).
900902

901903
Definition array_uctx := ([nAnon], ConstraintSet.empty).
@@ -1043,12 +1045,30 @@ Module Environment (T : Term).
10431045

10441046
Definition arities_context (l : list one_inductive_body) :=
10451047
rev_map (fun ind => vass (mkBindAnn (nNamed ind.(ind_name))
1046-
(ind.(ind_relevance))) ind.(ind_type)) l.
1048+
rel_of_Type) ind.(ind_type)) l.
10471049

10481050
Lemma arities_context_length l : #|arities_context l| = #|l|.
10491051
Proof. unfold arities_context. now rewrite length_rev_map. Qed.
10501052
#[global] Hint Rewrite arities_context_length : len.
10511053

1054+
Lemma nth_error_arities_context idecls i idecl :
1055+
nth_error (List.rev idecls) i = Some idecl ->
1056+
nth_error (arities_context idecls) i =
1057+
Some {| decl_name := {| binder_name := nNamed idecl.(ind_name); binder_relevance := rel_of_Type |};
1058+
decl_body := None;
1059+
decl_type := idecl.(ind_type) |}.
1060+
Proof using Type.
1061+
intros hnth.
1062+
epose proof (nth_error_Some_length hnth). autorewrite with len in H.
1063+
rewrite nth_error_rev in hnth. now autorewrite with len.
1064+
rewrite List.rev_involutive in hnth. autorewrite with len in hnth.
1065+
unfold arities_context.
1066+
rewrite rev_map_spec.
1067+
rewrite nth_error_rev; autorewrite with len; auto.
1068+
rewrite List.rev_involutive nth_error_map.
1069+
rewrite hnth. simpl. reflexivity.
1070+
Qed.
1071+
10521072
Definition map_mutual_inductive_body f m :=
10531073
match m with
10541074
| Build_mutual_inductive_body finite ind_npars ind_pars ind_bodies ind_universes ind_variance =>

0 commit comments

Comments
 (0)