Skip to content

Commit fe26a41

Browse files
committed
Shared app_context, integrated Σ in ctx_inst
1 parent a10e95c commit fe26a41

Some content is hidden

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

42 files changed

+283
-310
lines changed

common/theories/BasicAst.v

+50-10
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,13 @@ Record judgment_ {universe Term} := Judge {
217217
j_term : option Term;
218218
j_typ : Term;
219219
j_univ : option universe;
220-
(* rel : option relevance; *)
220+
(* j_rel : option relevance; *)
221221
}.
222222
Arguments judgment_ : clear implicits.
223223
Arguments Judge {universe Term} _ _ _.
224-
Notation Typ typ := (Judge None typ None).
225-
Notation TermTyp tm ty := (Judge (Some tm) ty None).
226-
Notation TermoptTyp tm typ := (Judge tm typ None).
227-
Notation TypUniv ty u := (Judge None ty (Some u)).
228-
Notation TermTypUniv tm ty u := (Judge (Some tm) ty (Some u)).
229224

230225
Definition judgment_map {univ T A} (f: T -> A) (j : judgment_ univ T) :=
231-
Judge (option_map f (j_term j)) (f (j_typ j)) (j_univ j) (* rel *).
226+
Judge (option_map f (j_term j)) (f (j_typ j)) (j_univ j) (* (j_rel j) *).
232227

233228
Section Contexts.
234229
Context {term : Type}.
@@ -244,8 +239,15 @@ End Contexts.
244239

245240
Arguments context_decl : clear implicits.
246241

247-
Definition judgment_of_decl {term universe} d : judgment_ term universe :=
248-
TermoptTyp (decl_body d) (decl_type d).
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_vdef na b ty := (TermTyp b ty (* na.(binder_relevance) *)).
250+
Notation j_decl d := (TermoptTyp (decl_body d) (decl_type d) (* (decl_name d).(binder_relevance) *)).
249251

250252

251253
Definition map_decl {term term'} (f : term -> term') (d : context_decl term) : context_decl term' :=
@@ -314,8 +316,46 @@ Definition snoc {A} (Γ : list A) (d : A) := d :: Γ.
314316

315317
Notation " Γ ,, d " := (snoc Γ d) (at level 20, d at next level).
316318

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

320360
Notation onctx P := (All (ondecl P)).
321361

common/theories/Environment.v

-30
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,6 @@ Module Environment (T : Term).
861861

862862
Definition program : Type := global_env * term.
863863

864-
(* TODO MOVE AstUtils factorisation *)
865-
866-
Definition app_context (Γ Γ' : context) : context := Γ' ++ Γ.
867-
Notation "Γ ,,, Γ'" :=
868-
(app_context Γ Γ') (at level 25, Γ' at next level, left associativity).
869-
870864
(** Make a lambda/let-in string of abstractions from a context [Γ], ending with term [t]. *)
871865

872866
Definition mkLambda_or_LetIn d t :=
@@ -987,30 +981,6 @@ Module Environment (T : Term).
987981
Proof. unfold arities_context. now rewrite rev_map_length. Qed.
988982
#[global] Hint Rewrite arities_context_length : len.
989983

990-
Lemma app_context_nil_l Γ : [] ,,, Γ = Γ.
991-
Proof.
992-
unfold app_context. rewrite app_nil_r. reflexivity.
993-
Qed.
994-
995-
Lemma app_context_assoc Γ Γ' Γ'' : Γ ,,, (Γ' ,,, Γ'') = Γ ,,, Γ' ,,, Γ''.
996-
Proof. unfold app_context; now rewrite app_assoc. Qed.
997-
998-
Lemma app_context_cons Γ Γ' A : Γ ,,, (Γ' ,, A) = (Γ ,,, Γ') ,, A.
999-
Proof. exact (app_context_assoc _ _ [A]). Qed.
1000-
1001-
Lemma app_context_length Γ Γ' : #|Γ ,,, Γ'| = #|Γ'| + #|Γ|.
1002-
Proof. unfold app_context. now rewrite app_length. Qed.
1003-
#[global] Hint Rewrite app_context_length : len.
1004-
1005-
Lemma nth_error_app_context_ge v Γ Γ' :
1006-
#|Γ'| <= v -> nth_error (Γ ,,, Γ') v = nth_error Γ (v - #|Γ'|).
1007-
Proof. apply nth_error_app_ge. Qed.
1008-
1009-
Lemma nth_error_app_context_lt v Γ Γ' :
1010-
v < #|Γ'| -> nth_error (Γ ,,, Γ') v = nth_error Γ' v.
1011-
Proof. apply nth_error_app_lt. Qed.
1012-
1013-
1014984
Definition map_mutual_inductive_body f m :=
1015985
match m with
1016986
| Build_mutual_inductive_body finite ind_npars ind_pars ind_bodies ind_universes ind_variance =>

common/theories/EnvironmentTyping.v

+25-22
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
319319
(** Well-formedness of local environments embeds a sorting for each variable *)
320320

321321
Definition on_local_decl (P : context -> judgment -> Type) Γ d :=
322-
P Γ (TermoptTyp d.(decl_body) d.(decl_type)).
322+
P Γ (j_decl d).
323323

324324
Definition on_def_type (P : context -> judgment -> Type) Γ d :=
325325
P Γ (Typ d.(dtype)).
@@ -330,7 +330,10 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
330330
(* Various kinds of lifts *)
331331

332332
Definition lift_wf_term wf_term (j : judgment) := option_default wf_term (j_term j) (unit : Type) × wf_term (j_typ j).
333-
Notation lift_on_term on_term := (fun (Γ : context) => lift_wf_term (on_term Γ)).
333+
Notation lift_wf_term1 wf_term := (fun (Γ : context) => lift_wf_term (wf_term Γ)).
334+
335+
Definition lift_wfb_term wfb_term (j : judgment) := option_default wfb_term (j_term j) true && wfb_term (j_typ j).
336+
Notation lift_wfb_term1 wfb_term := (fun (Γ : context) => lift_wfb_term (wfb_term Γ)).
334337

335338
Definition lift_sorting checking sorting : judgment -> Type :=
336339
fun j => option_default (fun tm => checking tm (j_typ j)) (j_term j) (unit : Type) ×
@@ -872,28 +875,28 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
872875
Defined.
873876

874877
Section TypeCtxInst.
875-
Context (typing : forall (Σ : global_env_ext) (Γ : context), term -> term -> Type).
878+
Context (typing : forall (Γ : context), term -> term -> Type).
876879

877880
(* Γ |- s : Δ, where Δ is a telescope (reverse context) *)
878-
Inductive ctx_inst Σ (Γ : context) : list term -> context -> Type :=
879-
| ctx_inst_nil : ctx_inst Σ Γ [] []
881+
Inductive ctx_inst (Γ : context) : list term -> context -> Type :=
882+
| ctx_inst_nil : ctx_inst Γ [] []
880883
| ctx_inst_ass na t i inst Δ :
881-
typing Σ Γ i t ->
882-
ctx_inst Σ Γ inst (subst_telescope [i] 0 Δ) ->
883-
ctx_inst Σ Γ (i :: inst) (vass na t :: Δ)
884+
typing Γ i t ->
885+
ctx_inst Γ inst (subst_telescope [i] 0 Δ) ->
886+
ctx_inst Γ (i :: inst) (vass na t :: Δ)
884887
| ctx_inst_def na b t inst Δ :
885-
ctx_inst Σ Γ inst (subst_telescope [b] 0 Δ) ->
886-
ctx_inst Σ Γ inst (vdef na b t :: Δ).
888+
ctx_inst Γ inst (subst_telescope [b] 0 Δ) ->
889+
ctx_inst Γ inst (vdef na b t :: Δ).
887890
Derive Signature NoConfusion for ctx_inst.
888891
End TypeCtxInst.
889892

890-
Lemma ctx_inst_impl_gen Σ Γ inst Δ args P :
891-
{ P' & ctx_inst P' Σ Γ inst Δ } ->
893+
Lemma ctx_inst_impl_gen Γ inst Δ args P :
894+
{ P' & ctx_inst P' Γ inst Δ } ->
892895
(forall t T,
893-
All (fun P' => P' Σ Γ t T) args ->
894-
P Σ Γ t T) ->
895-
All (fun P' => ctx_inst P' Σ Γ inst Δ) args ->
896-
ctx_inst P Σ Γ inst Δ.
896+
All (fun P' => P' Γ t T) args ->
897+
P Γ t T) ->
898+
All (fun P' => ctx_inst P' Γ inst Δ) args ->
899+
ctx_inst P Γ inst Δ.
897900
Proof.
898901
intros [? Hexists] HPQ H.
899902
induction Hexists; constructor; tea.
@@ -902,10 +905,10 @@ Module EnvTyping (T : Term) (E : EnvironmentSig T) (TU : TermUtils T E).
902905
all: eapply All_impl; tea; cbn; intros *; inversion 1; subst; eauto.
903906
Qed.
904907

905-
Lemma ctx_inst_impl P Q Σ Σ' Γ inst Δ :
906-
ctx_inst P Σ Γ inst Δ ->
907-
(forall t T, P Σ Γ t T -> Q Σ' Γ t T) ->
908-
ctx_inst Q Σ' Γ inst Δ.
908+
Lemma ctx_inst_impl P Q Γ inst Δ :
909+
ctx_inst P Γ inst Δ ->
910+
(forall t T, P Γ t T -> Q Γ t T) ->
911+
ctx_inst Q Γ inst Δ.
909912
Proof.
910913
intros H HPQ. induction H; econstructor; auto.
911914
Qed.
@@ -1369,7 +1372,7 @@ Module GlobalMaps (T: Term) (E: EnvironmentSig T) (TU : TermUtils T E) (ET: EnvT
13691372
sorts_local_ctx Σ (arities_context mdecl.(ind_bodies) ,,, mdecl.(ind_params))
13701373
cdecl.(cstr_args) cunivs;
13711374
on_cindices :
1372-
ctx_inst (fun Σ Γ t T => P Σ Γ (TermTyp t T)) Σ (arities_context mdecl.(ind_bodies) ,,, mdecl.(ind_params) ,,, cdecl.(cstr_args))
1375+
ctx_inst (fun Γ t T => P Σ Γ (TermTyp t T)) (arities_context mdecl.(ind_bodies) ,,, mdecl.(ind_params) ,,, cdecl.(cstr_args))
13731376
cdecl.(cstr_indices)
13741377
(List.rev (lift_context #|cdecl.(cstr_args)| 0 ind_indices));
13751378

@@ -1806,7 +1809,7 @@ Module GlobalMaps (T: Term) (E: EnvironmentSig T) (TU : TermUtils T E) (ET: EnvT
18061809
{ eapply All_map, All_impl; tea; intros *; destr_prod; destruct 1; cbn; tea. } }
18071810
{ eapply ctx_inst_impl_gen; tea.
18081811
{ eexists; tea. }
1809-
{ intros; eapply H1, All_eta3; cbn. apply All_map_inv with (P:=fun P => P _ _ t T1) (f:=fun P Σ Γ t T => snd P Σ Γ (TermTyp t T)); tea. }
1812+
{ intros; eapply H1, All_eta3; cbn. apply All_map_inv with (P:=fun P => P _ t T1) (f:=fun P Γ t T => snd P Σ Γ (TermTyp t T)); tea. }
18101813
{ eapply All_map, All_impl; tea; intros *; destr_prod; destruct 1; cbn; tea. } }
18111814
{ move => ? H'.
18121815
match goal with H : _ |- _ => specialize (H _ H'); revert H end => H''.

erasure/theories/ESubstitution.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Lemma erases_weakening' (Σ : global_env_ext) (Γ Γ' Γ'' : context) (t T : ter
180180
Σ ;;; Γ ,,, Γ'' ,,, lift_context #|Γ''| 0 Γ' |- (lift #|Γ''| #|Γ'| t) ⇝ℇ (ELiftSubst.lift #|Γ''| #|Γ'| t').
181181
Proof.
182182
intros HΣ HΓ'' * H He.
183-
generalize_eqs H. intros eqw. rewrite <- eqw in *.
183+
remember (Γ ,,, Γ') as Γ0 eqn:eqw.
184184
revert Γ Γ' Γ'' HΓ'' eqw t' He.
185185
revert Σ HΣ Γ0 t T H .
186186
apply (typing_ind_env (fun Σ Γ0 t T => forall Γ Γ' Γ'',
@@ -393,7 +393,7 @@ Lemma erases_subst (Σ : global_env_ext) Γ Γ' Δ t s t' s' T :
393393
Σ ;;; (Γ ,,, subst_context s 0 Δ) |- (subst s #|Δ| t) ⇝ℇ ELiftSubst.subst s' #|Δ| t'.
394394
Proof.
395395
intros HΣ HΔ Hs Ht He.
396-
generalize_eqs Ht. intros eqw.
396+
remember (Γ ,,, Γ' ,,, Δ) as Γ0 eqn:eqw in Ht.
397397
revert Γ Γ' Δ t' s Hs HΔ He eqw.
398398
revert Σ HΣ Γ0 t T Ht.
399399
eapply (typing_ind_env (fun Σ Γ0 t T =>

pcuic/theories/Bidirectional/BDFromPCUIC.v

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ Proof.
2424
lia.
2525
Qed.
2626

27-
Lemma ctx_inst_length {ty Σ Γ args Δ} :
28-
PCUICTyping.ctx_inst ty Σ Γ args Δ ->
29-
#|args| = context_assumptions Δ.
27+
Lemma ctx_inst_length {ty Γ args Δ} :
28+
PCUICTyping.ctx_inst ty Γ args Δ ->
29+
#|args| = context_assumptions Δ.
3030
Proof.
31-
induction 1; simpl; auto.
32-
rewrite /subst_telescope in IHX.
33-
rewrite context_assumptions_mapi in IHX. congruence.
34-
rewrite context_assumptions_mapi in IHX. congruence.
31+
induction 1; simpl; auto.
32+
rewrite /subst_telescope in IHX.
33+
rewrite context_assumptions_mapi in IHX. congruence.
34+
rewrite context_assumptions_mapi in IHX. congruence.
3535
Qed.
3636

3737

38-
Lemma ctx_inst_app_impl {P Q Σ Γ} {Δ : context} {Δ' args} (c : PCUICTyping.ctx_inst P Σ Γ args (Δ ++ Δ')) :
39-
(forall Γ' t T, P Σ Γ' t T -> Q Σ Γ' t T) ->
40-
PCUICTyping.ctx_inst Q Σ Γ (firstn (context_assumptions Δ) args) Δ.
38+
Lemma ctx_inst_app_impl {P Q Γ} {Δ : context} {Δ' args} (c : PCUICTyping.ctx_inst P Γ args (Δ ++ Δ')) :
39+
(forall t T, P Γ t T -> Q Γ t T) ->
40+
PCUICTyping.ctx_inst Q Γ (firstn (context_assumptions Δ) args) Δ.
4141
Proof.
4242
revert args Δ' c.
4343
induction Δ using ctx_length_ind; intros.
@@ -238,7 +238,7 @@ Proof.
238238
* rewrite subst_instance_app_ctx rev_app_distr in Hinst.
239239
replace (pparams p) with (firstn (context_assumptions (List.rev (subst_instance (puinst p)(ind_params mdecl)))) (pparams p ++ indices)).
240240
eapply ctx_inst_app_impl ; tea.
241-
1: intros ??? [] ; by apply conv_check.
241+
1: intros ?? [] ; by apply conv_check.
242242
rewrite context_assumptions_rev context_assumptions_subst_instance.
243243
erewrite PCUICGlobalMaps.onNpars.
244244
2: eapply on_declared_minductive ; eauto.
@@ -472,8 +472,8 @@ Proof.
472472
Qed.
473473

474474
Theorem ctx_inst_typing_bd `{checker_flags} (Σ : global_env_ext) Γ l Δ (wfΣ : wf Σ) :
475-
PCUICTyping.ctx_inst typing Σ Γ l Δ ->
476-
PCUICTyping.ctx_inst checking Σ Γ l Δ.
475+
PCUICTyping.ctx_inst (typing Σ) Γ l Δ ->
476+
PCUICTyping.ctx_inst (checking Σ) Γ l Δ.
477477
Proof.
478478
intros inl.
479479
induction inl.

pcuic/theories/Bidirectional/BDStrengthening.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ Lemma rename_telescope P f Γ Δ tel tys:
591591
on_ctx_free_vars P Γ ->
592592
forallb (on_free_vars P) tys ->
593593
on_free_vars_ctx P (List.rev tel) ->
594-
PCUICTyping.ctx_inst (fun _ => Pcheck) Σ Γ tys tel ->
595-
PCUICTyping.ctx_inst checking Σ Δ (map (rename f) tys) (rename_telescope f tel).
594+
PCUICTyping.ctx_inst Pcheck Γ tys tel ->
595+
PCUICTyping.ctx_inst (checking Σ) Δ (map (rename f) tys) (rename_telescope f tel).
596596
Proof using Type.
597597
intros ur hΓ htys htel ins.
598598
induction ins in Δ, ur, hΓ, htys, htel |- *.

pcuic/theories/Bidirectional/BDToPCUIC.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Section BDToPCUICTyping.
153153
Qed.
154154

155155
Lemma ctx_inst_impl Γ (wfΓ : wf_local Σ Γ) (Δ : context) (wfΔ : wf_local_rel Σ Γ (List.rev Δ)) :
156-
forall args, PCUICTyping.ctx_inst (fun _ => Pcheck) Σ Γ args Δ -> ctx_inst Σ Γ args Δ.
156+
forall args, PCUICTyping.ctx_inst Pcheck Γ args Δ -> ctx_inst Σ Γ args Δ.
157157
Proof using wfΣ.
158158
revert wfΔ.
159159
induction Δ using ctx_length_ind.
@@ -479,8 +479,8 @@ Qed.
479479

480480
Theorem ctx_inst_bd_typing `{checker_flags} (Σ : global_env_ext) Γ l Δ (wfΣ : wf Σ) :
481481
wf_local Σ (Γ,,,Δ) ->
482-
PCUICTyping.ctx_inst checking Σ Γ l (List.rev Δ) ->
483-
PCUICTyping.ctx_inst typing Σ Γ l (List.rev Δ).
482+
PCUICTyping.ctx_inst (checking Σ) Γ l (List.rev Δ) ->
483+
PCUICTyping.ctx_inst (typing Σ) Γ l (List.rev Δ).
484484
Proof.
485485
intros wfΓ inl.
486486
rewrite -(List.rev_involutive Δ) in wfΓ.

pcuic/theories/Bidirectional/BDTyping.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Inductive infering `{checker_flags} (Σ : global_env_ext) (Γ : context) : term
8383
consistent_instance_ext Σ (ind_universes mdecl) (puinst p) ->
8484
wf_local_bd_rel Σ Γ predctx ->
8585
is_allowed_elimination Σ (ind_kelim idecl) ps ->
86-
ctx_inst checking Σ Γ (pparams p)
86+
ctx_inst (checking Σ) Γ (pparams p)
8787
(List.rev mdecl.(ind_params)@[p.(puinst)]) ->
8888
isCoFinite mdecl.(ind_finite) = false ->
8989
R_global_instance Σ (eq_universe Σ) (leq_universe Σ)
@@ -401,9 +401,9 @@ Section BidirectionalInduction.
401401
wf_local_bd_rel Σ Γ predctx ->
402402
PΓ_rel Γ predctx ->
403403
is_allowed_elimination Σ (ind_kelim idecl) ps ->
404-
ctx_inst checking Σ Γ (pparams p)
404+
ctx_inst (checking Σ) Γ (pparams p)
405405
(List.rev mdecl.(ind_params)@[p.(puinst)]) ->
406-
ctx_inst (fun _ => Pcheck) Σ Γ p.(pparams)
406+
ctx_inst Pcheck Γ p.(pparams)
407407
(List.rev (subst_instance p.(puinst) mdecl.(ind_params))) ->
408408
isCoFinite mdecl.(ind_finite) = false ->
409409
R_global_instance Σ (eq_universe Σ) (leq_universe Σ)

0 commit comments

Comments
 (0)