Skip to content

Commit e9b17dc

Browse files
authored
Merge pull request #1007 from yannl35133/rejudgment
More unified judgment type and All_local_env
2 parents b646cd3 + 078344e commit e9b17dc

File tree

166 files changed

+11855
-12894
lines changed

Some content is hidden

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

166 files changed

+11855
-12894
lines changed

common/theories/BasicAst.v

+62-15
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,17 @@ Proof.
213213
eapply map_def_spec; eauto.
214214
Qed.
215215

216-
Variant typ_or_sort_ {term} := Typ (T : term) | Sort.
217-
Arguments typ_or_sort_ : clear implicits.
218-
219-
Definition typ_or_sort_map {T T'} (f: T -> T') t :=
220-
match t with
221-
| Typ T => Typ (f T)
222-
| Sort => Sort
223-
end.
224-
225-
Definition typ_or_sort_default {T A} (f: T -> A) t d :=
226-
match t with
227-
| Typ T => f T
228-
| Sort => d
229-
end.
216+
Record judgment_ {universe Term} := Judge {
217+
j_term : option Term;
218+
j_typ : Term;
219+
j_univ : option universe;
220+
(* j_rel : option relevance; *)
221+
}.
222+
Arguments judgment_ : clear implicits.
223+
Arguments Judge {universe Term} _ _ _.
224+
225+
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) *).
230227

231228
Section Contexts.
232229
Context {term : Type}.
@@ -242,6 +239,18 @@ End Contexts.
242239

243240
Arguments context_decl : clear implicits.
244241

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) *)).
249+
Notation j_vass_s na ty s := (TypUniv ty s (* na.(binder_relevance) *)).
250+
Notation j_vdef na b ty := (TermTyp b ty (* na.(binder_relevance) *)).
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) *)).
253+
245254
Definition map_decl {term term'} (f : term -> term') (d : context_decl term) : context_decl term' :=
246255
{| decl_name := d.(decl_name);
247256
decl_body := option_map f d.(decl_body);
@@ -308,8 +317,46 @@ Definition snoc {A} (Γ : list A) (d : A) := d :: Γ.
308317

309318
Notation " Γ ,, d " := (snoc Γ d) (at level 20, d at next level).
310319

320+
Definition app_context {A} (Γ Γ': list A) := Γ' ++ Γ.
321+
322+
Notation "Γ ,,, Γ'" := (app_context Γ Γ') (at level 25, Γ' at next level, left associativity).
323+
324+
Lemma app_context_nil_l {T} Γ : [] ,,, Γ = Γ :> list T.
325+
Proof.
326+
unfold app_context. rewrite app_nil_r. reflexivity.
327+
Qed.
328+
329+
Lemma app_context_assoc {T} Γ Γ' Γ'' : Γ ,,, (Γ' ,,, Γ'') = Γ ,,, Γ' ,,, Γ'' :> list T.
330+
Proof. unfold app_context; now rewrite app_assoc. Qed.
331+
332+
Lemma app_context_cons {T} Γ Γ' A : Γ ,,, (Γ' ,, A) = (Γ ,,, Γ') ,, A :> list T.
333+
Proof. exact (app_context_assoc _ _ [A]). Qed.
334+
335+
Lemma app_context_push {T} Γ Δ Δ' d : (Γ ,,, Δ ,,, Δ') ,, d = (Γ ,,, Δ ,,, (Δ' ,, d)) :> list T.
336+
Proof using Type.
337+
reflexivity.
338+
Qed.
339+
340+
Lemma snoc_app_context {T Γ Δ d} : (Γ ,,, (d :: Δ)) = (Γ ,,, Δ) ,,, [d] :> list T.
341+
Proof using Type.
342+
reflexivity.
343+
Qed.
344+
345+
Lemma app_context_length {T} (Γ Γ' : list T) : #|Γ ,,, Γ'| = #|Γ'| + #|Γ|.
346+
Proof. unfold app_context. now rewrite app_length. Qed.
347+
#[global] Hint Rewrite @app_context_length : len.
348+
349+
Lemma nth_error_app_context_ge {T} v Γ Γ' :
350+
#|Γ'| <= v -> nth_error (Γ ,,, Γ') v = nth_error Γ (v - #|Γ'|) :> option T.
351+
Proof. apply nth_error_app_ge. Qed.
352+
353+
Lemma nth_error_app_context_lt {T} v Γ Γ' :
354+
v < #|Γ'| -> nth_error (Γ ,,, Γ') v = nth_error Γ' v :> option T.
355+
Proof. apply nth_error_app_lt. Qed.
356+
357+
311358
Definition ondecl {A} (P : A -> Type) (d : context_decl A) :=
312-
P d.(decl_type) × option_default P d.(decl_body) unit.
359+
option_default P d.(decl_body) unit × P d.(decl_type).
313360

314361
Notation onctx P := (All (ondecl P)).
315362

common/theories/Environment.v

+6-36
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Module Type Term.
99
Parameter Inline term : Type.
1010

1111
Parameter Inline tRel : nat -> term.
12-
Parameter Inline tSort : Universe.t -> term.
12+
Parameter Inline tSort : Sort.t -> term.
1313
Parameter Inline tProd : aname -> term -> term -> term.
1414
Parameter Inline tLambda : aname -> term -> term -> term.
1515
Parameter Inline tLetIn : aname -> term -> term -> term -> term.
@@ -129,7 +129,7 @@ Module Environment (T : Term).
129129
Import T.
130130
#[global] Existing Instance subst_instance_constr.
131131

132-
Definition typ_or_sort := typ_or_sort_ term.
132+
Definition judgment := judgment_ Sort.t term.
133133

134134
(** ** Declarations *)
135135
Notation context_decl := (context_decl term).
@@ -344,7 +344,7 @@ Module Environment (T : Term).
344344
Record one_inductive_body := {
345345
ind_name : ident;
346346
ind_indices : context; (* Indices of the inductive types, under params *)
347-
ind_sort : Universe.t; (* Sort of the inductive. *)
347+
ind_sort : Sort.t; (* Sort of the inductive. *)
348348
ind_type : term; (* Closed arity = forall mind_params, ind_indices, tSort ind_sort *)
349349
ind_kelim : allowed_eliminations; (* Allowed eliminations *)
350350
ind_ctors : list constructor_body;
@@ -856,10 +856,10 @@ Module Environment (T : Term).
856856
Definition primitive_invariants (p : prim_tag) (cdecl : constant_body) :=
857857
match p with
858858
| primInt | primFloat =>
859-
[/\ cdecl.(cst_type) = tSort Universe.type0, cdecl.(cst_body) = None &
859+
[/\ cdecl.(cst_type) = tSort Sort.type0, cdecl.(cst_body) = None &
860860
cdecl.(cst_universes) = Monomorphic_ctx]
861861
| primArray =>
862-
let s := Universe.make (Level.lvar 0) in
862+
let s := sType (Universe.make' (Level.lvar 0)) in
863863
[/\ cdecl.(cst_type) = tImpl (tSort s) (tSort s), cdecl.(cst_body) = None &
864864
cdecl.(cst_universes) = Polymorphic_ctx array_uctx]
865865
end.
@@ -882,12 +882,6 @@ Module Environment (T : Term).
882882

883883
Definition program : Type := global_env * term.
884884

885-
(* TODO MOVE AstUtils factorisation *)
886-
887-
Definition app_context (Γ Γ' : context) : context := Γ' ++ Γ.
888-
Notation "Γ ,,, Γ'" :=
889-
(app_context Γ Γ') (at level 25, Γ' at next level, left associativity).
890-
891885
(** Make a lambda/let-in string of abstractions from a context [Γ], ending with term [t]. *)
892886

893887
Definition mkLambda_or_LetIn d t :=
@@ -1008,30 +1002,6 @@ Module Environment (T : Term).
10081002
Proof. unfold arities_context. now rewrite rev_map_length. Qed.
10091003
#[global] Hint Rewrite arities_context_length : len.
10101004

1011-
Lemma app_context_nil_l Γ : [] ,,, Γ = Γ.
1012-
Proof.
1013-
unfold app_context. rewrite app_nil_r. reflexivity.
1014-
Qed.
1015-
1016-
Lemma app_context_assoc Γ Γ' Γ'' : Γ ,,, (Γ' ,,, Γ'') = Γ ,,, Γ' ,,, Γ''.
1017-
Proof. unfold app_context; now rewrite app_assoc. Qed.
1018-
1019-
Lemma app_context_cons Γ Γ' A : Γ ,,, (Γ' ,, A) = (Γ ,,, Γ') ,, A.
1020-
Proof. exact (app_context_assoc _ _ [A]). Qed.
1021-
1022-
Lemma app_context_length Γ Γ' : #|Γ ,,, Γ'| = #|Γ'| + #|Γ|.
1023-
Proof. unfold app_context. now rewrite app_length. Qed.
1024-
#[global] Hint Rewrite app_context_length : len.
1025-
1026-
Lemma nth_error_app_context_ge v Γ Γ' :
1027-
#|Γ'| <= v -> nth_error (Γ ,,, Γ') v = nth_error Γ (v - #|Γ'|).
1028-
Proof. apply nth_error_app_ge. Qed.
1029-
1030-
Lemma nth_error_app_context_lt v Γ Γ' :
1031-
v < #|Γ'| -> nth_error (Γ ,,, Γ') v = nth_error Γ' v.
1032-
Proof. apply nth_error_app_lt. Qed.
1033-
1034-
10351005
Definition map_mutual_inductive_body f m :=
10361006
match m with
10371007
| Build_mutual_inductive_body finite ind_npars ind_pars ind_bodies ind_universes ind_variance =>
@@ -1269,7 +1239,7 @@ End EnvironmentDecideReflectInstances.
12691239
Module Type TermUtils (T: Term) (E: EnvironmentSig T).
12701240
Import T E.
12711241

1272-
Parameter Inline destArity : context -> term -> option (context × Universe.t).
1242+
Parameter Inline destArity : context -> term -> option (context × Sort.t).
12731243
Parameter Inline inds : kername -> Instance.t -> list one_inductive_body -> list term.
12741244

12751245
End TermUtils.

0 commit comments

Comments
 (0)