Skip to content

Commit 30d7b72

Browse files
authored
Merge pull request #536 from yforster/8.11_into_8.12
Merge again 8.11 into 8.12
2 parents 2f197b3 + f1820f9 commit 30d7b72

Some content is hidden

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

64 files changed

+5028
-1464
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ erasure: template-coq safechecker pcuic
7272
checker: template-coq
7373
$(MAKE) -C checker
7474

75-
examples: template-coq checker
75+
examples: checker safechecker
7676
$(MAKE) -C examples
7777

7878
test-suite: template-coq checker safechecker erasure

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<img src="https://raw.githubusercontent.com/MetaCoq/metacoq.github.io/master/assets/LOGO.png" alt="MetaCoq" width="50px"/>
55
</p>
66

7-
[![Build status](https://github.com/MetaCoq/metacoq/workflows/Test%20compilation/badge.svg?branch=coq-8.12)](https://github.com/MetaCoq/metacoq/actions)
8-
[![MetaCoq Chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg)](https://coq.zulipchat.com)
7+
[![Build status](https://github.com/MetaCoq/metacoq/workflows/Test%20compilation/badge.svg?branch=coq-8.12)](https://github.com/MetaCoq/metacoq/actions) [![MetaCoq Chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg)](https://coq.zulipchat.com)
98

109
MetaCoq is a project formalizing Coq in Coq and providing tools for
1110
manipulating Coq terms and developing certified plugins

TODO.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- `assumption_context` should be a boolean function.
44

5+
- remove duplication of eq_context / eq_context_upto and eq_decl / eq_decl_upto
6+
57
- Rename `mkApps_nested` into `mkApps_app` (et inverser la direction de la
68
règle)
79

@@ -34,6 +36,20 @@
3436

3537
# Big projects
3638

39+
- Refine the longest-simple-path algorithm on universes with the
40+
Bender & al algorithm used in Coq, extended with edges of negative weight.
41+
Alternatively prove the spec for that algorithm. Refinement might be easier:
42+
it amounts to show that the new algorithm calculates the longest simple
43+
path between two universes.
44+
45+
- Verify parsing and printing of terms / votour
46+
47+
- Primivite projections: we could be more relaxed on the elimination sort of the
48+
inductive. If it is e.g. InProp, then all projections to types in Prop should
49+
be definable. Probably not very useful though because if the elimination is
50+
restricted then it means some Type is in the constructor and won't be projectable.
51+
52+
3753
## Website
3854

3955
Put a demo using JS-coq on the webiste
@@ -55,10 +71,3 @@ into β-redexes, hence it is only β-convertible and not a syntactical equality.
5571

5672
- Deduce that we have weakening and substitution lemmas in Template from those of
5773
PCUIC.
58-
59-
60-
## Finish Safechecker correctness
61-
62-
- `valid_btys`
63-
64-
- `check_one_body`

checker/theories/Closed.v

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ Proof.
289289
now rewrite andb_true_r in b.
290290
Qed.
291291

292+
Lemma sorts_local_ctx_Pclosed Σ Γ Δ s :
293+
sorts_local_ctx (lift_typing Pclosed) Σ Γ Δ s ->
294+
Alli (fun i d => closed_decl (#|Γ| + i) d) 0 (List.rev Δ).
295+
Proof.
296+
induction Δ in s |- *; simpl; auto; try constructor.
297+
destruct a as [? [] ?]; intuition auto.
298+
- apply Alli_app_inv; eauto. constructor. simpl.
299+
rewrite List.rev_length. 2:constructor.
300+
unfold closed_decl. unfold Pclosed in b0. simpl.
301+
rewrite app_context_length in b0. now rewrite Nat.add_comm.
302+
- destruct s; auto. destruct X.
303+
apply Alli_app_inv; eauto. constructor. simpl.
304+
rewrite List.rev_length. 2:constructor.
305+
unfold closed_decl. unfold Pclosed in i. simpl.
306+
rewrite app_context_length in i. rewrite Nat.add_comm.
307+
now rewrite andb_true_r in i.
308+
Qed.
309+
292310
Lemma All_local_env_Pclosed Σ Γ :
293311
All_local_env ( lift_typing Pclosed Σ) Γ ->
294312
Alli (fun i d => closed_decl i d) 0 (List.rev Γ).
@@ -413,7 +431,7 @@ Proof.
413431
eapply closedn_lift.
414432
clear -parslen isdecl Heq' onpars X.
415433
rename X into args.
416-
apply type_local_ctx_Pclosed in args.
434+
apply sorts_local_ctx_Pclosed in args.
417435
red in onpars.
418436
eapply All_local_env_Pclosed in onpars.
419437
eapply (Alli_impl (Q:=fun i d => closed_decl (#|ind_params mdecl| + i + #|arities_context (ind_bodies mdecl)|) d)) in args.

checker/theories/WeakeningEnv.v

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,23 @@ Proof.
102102
- simpl. apply ConstraintSet.union_spec. right; eauto.
103103
Qed.
104104

105+
Lemma satisfies_subset φ φ' val :
106+
ConstraintSet.Subset φ φ' ->
107+
satisfies val φ' ->
108+
satisfies val φ.
109+
Proof.
110+
intros sub sat ? isin.
111+
apply sat, sub; auto.
112+
Qed.
113+
105114
Lemma leq_universe_subset {cf:checker_flags} ctrs ctrs' t u
106115
: ConstraintSet.Subset ctrs ctrs'
107116
-> leq_universe ctrs t u -> leq_universe ctrs' t u.
108117
Proof.
109118
intros Hctrs H. unfold leq_universe in *.
110119
destruct check_univs; [|trivial].
111120
intros v Hv. apply H.
112-
intros ctr Hc. apply Hv.
113-
apply Hctrs; eauto.
121+
eapply satisfies_subset; eauto.
114122
Qed.
115123

116124
Lemma eq_universe_subset {cf:checker_flags} ctrs ctrs' t u
@@ -120,8 +128,7 @@ Proof.
120128
intros Hctrs H. unfold eq_universe in *.
121129
destruct check_univs; [|trivial].
122130
intros v Hv. apply H.
123-
intros ctr Hc. apply Hv.
124-
apply Hctrs; eauto.
131+
eapply satisfies_subset; eauto.
125132
Qed.
126133

127134

@@ -204,6 +211,22 @@ Proof.
204211
- econstructor 3; eauto. eapply weakening_env_red1; eauto. exists Σ''; eauto.
205212
Qed.
206213

214+
Lemma weakening_env_is_allowed_elimination `{CF:checker_flags} Σ Σ' φ u allowed :
215+
wf Σ' -> extends Σ Σ' ->
216+
is_allowed_elimination (global_ext_constraints (Σ, φ)) u allowed ->
217+
is_allowed_elimination (global_ext_constraints (Σ', φ)) u allowed.
218+
Proof.
219+
intros wfΣ [Σ'' ->] al.
220+
unfold is_allowed_elimination in *.
221+
destruct check_univs; auto.
222+
intros val sat.
223+
unshelve epose proof (al val _) as al.
224+
{ eapply satisfies_subset; eauto.
225+
apply global_ext_constraints_app. }
226+
destruct allowed; auto; cbn in *; destruct ?; auto.
227+
Qed.
228+
Hint Resolve weakening_env_is_allowed_elimination : extends.
229+
207230
Lemma weakening_env_declared_constant `{CF:checker_flags}:
208231
forall (Σ : global_env) cst (decl : constant_body),
209232
declared_constant Σ cst decl ->
@@ -436,8 +459,10 @@ Proof.
436459
intros decl cs []. unshelve econstructor; eauto.
437460
red in on_ctype |- *. eauto.
438461
clear on_cindices cstr_eq cstr_args_length cstr_concl_head.
439-
induction (cshape_args cs); simpl in *; auto.
440-
** eapply (extends_wf_universe (Σ:=(Σ,φ)) Σ'); auto.
462+
revert on_cargs.
463+
generalize (cshape_sorts cs).
464+
induction (cshape_args cs); destruct l; simpl in *; auto.
465+
** destruct a as [na [b|] ty]; simpl in *; intuition eauto.
441466
** destruct a as [na [b|] ty]; simpl in *; intuition eauto.
442467
** clear on_ctype on_cargs.
443468
revert on_cindices.
@@ -448,32 +473,34 @@ Proof.
448473
simpl in *. move: on_ctype_variance.
449474
unfold cstr_respects_variance. destruct variance_universes as [[[univs u] u']|]; auto.
450475
intros [args idxs]. split.
451-
eapply (All2_local_env_impl args); intros.
476+
eapply (context_relation_impl args); intros.
477+
inversion X; constructor; auto.
478+
eapply weakening_env_cumul; eauto.
479+
eapply weakening_env_conv; eauto.
452480
eapply weakening_env_cumul; eauto.
453481
eapply (All2_impl idxs); intros.
454482
eapply weakening_env_conv; eauto.
455-
-- unfold check_ind_sorts in *. destruct universe_family; auto.
456-
--- split; [apply fst in ind_sorts|apply snd in ind_sorts].
457-
eapply Forall_impl; tea; cbn.
458-
intros. eapply leq_universe_subset; tea.
459-
apply weakening_env_global_ext_constraints; tea.
460-
destruct indices_matter; [|trivial]. clear -ind_sorts HPΣ wfΣ' Hext.
461-
induction ind_indices; simpl in *; auto.
462-
** eapply (extends_wf_universe (Σ:=(Σ,φ)) Σ'); auto.
463-
** destruct a as [na [b|] ty]; simpl in *; intuition eauto.
464-
--- split; [apply fst in ind_sorts|apply snd in ind_sorts].
465-
eapply Forall_impl; tea; cbn.
466-
intros. eapply leq_universe_subset; tea.
467-
apply weakening_env_global_ext_constraints; tea.
468-
destruct indices_matter; [|trivial]. clear -ind_sorts HPΣ wfΣ' Hext.
469-
induction ind_indices; simpl in *; auto.
470-
** eapply (extends_wf_universe (Σ:=(Σ,φ)) Σ'); auto.
471-
** destruct a as [na [b|] ty]; simpl in *; intuition eauto.
483+
-- unfold check_ind_sorts in *.
484+
destruct Universe.is_prop; auto.
485+
destruct Universe.is_sprop; auto.
486+
split; [apply fst in ind_sorts|apply snd in ind_sorts].
487+
eapply Forall_impl; tea; cbn.
488+
intros. eapply Forall_impl; eauto; simpl.
489+
intros; eapply leq_universe_subset; tea.
490+
apply weakening_env_global_ext_constraints; tea.
491+
destruct indices_matter; [|trivial]. clear -ind_sorts HPΣ wfΣ' Hext.
492+
induction ind_indices; simpl in *; auto.
493+
** eapply (extends_wf_universe (Σ:=(Σ,φ)) Σ'); auto.
494+
** destruct a as [na [b|] ty]; simpl in *; intuition eauto.
472495
-- intros v onv.
473496
move: (onIndices v onv). unfold ind_respects_variance.
474497
destruct variance_universes as [[[univs u] u']|] => //.
475-
intros idx; eapply (All2_local_env_impl idx); simpl.
476-
intros par par' t t'. eapply weakening_env_cumul; eauto.
498+
intros idx; eapply (context_relation_impl idx); simpl.
499+
intros par par' t t'.
500+
intros d. inv d; constructor; auto.
501+
eapply weakening_env_cumul; eauto.
502+
eapply weakening_env_conv; eauto.
503+
eapply weakening_env_cumul; eauto.
477504
- red in onP |- *. eapply All_local_env_impl; eauto.
478505
Qed.
479506

erasure/theories/EAst.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Notation " Γ ,, d " := (snoc Γ d) (at level 20, d at next level).
171171
Record one_inductive_body : Set := {
172172
ind_name : ident;
173173
ind_propositional : bool; (* True iff the inductive lives in Prop *)
174-
ind_kelim : sort_family; (* Top allowed elimination sort *)
174+
ind_kelim : allowed_eliminations; (* Allowed eliminations *)
175175
ind_ctors : list (ident * nat (* arity, w/o lets, w/o parameters *));
176176
ind_projs : list (ident) (* names of projections, if any. *) }.
177177

erasure/theories/Erasure.v

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,50 +58,63 @@ Program Fixpoint check_wf_env_only_univs (Σ : global_env)
5858
end
5959
end.
6060
Next Obligation.
61-
repeat constructor. apply graph_eq; try reflexivity.
62-
cbn. symmetry. apply wGraph.VSetProp.singleton_equal_add.
61+
repeat constructor.
6362
Qed.
6463
Next Obligation.
6564
sq. unfold is_graph_of_uctx, gc_of_uctx; simpl.
6665
unfold gc_of_uctx in e. simpl in e.
6766
case_eq (gc_of_constraints (constraints_of_udecl (universes_decl_of_decl g)));
6867
[|intro HH; rewrite HH in e; discriminate e].
69-
intros ctrs' Hctrs'. rewrite Hctrs' in *.
68+
intros ctrs' Hctrs'. rewrite Hctrs' in e.
7069
cbn in e. inversion e; subst; clear e.
7170
unfold global_ext_constraints; simpl.
72-
rewrite gc_of_constraints_union. rewrite Hctrs'.
71+
pose proof (gc_of_constraints_union
72+
(constraints_of_udecl (universes_decl_of_decl g)) (global_constraints Σ)).
73+
rewrite Hctrs' in H0. simpl in H0.
7374
red in i. unfold gc_of_uctx in i; simpl in i.
7475
case_eq (gc_of_constraints (global_constraints Σ));
7576
[|intro HH; rewrite HH in i; cbn in i; contradiction i].
76-
intros Σctrs HΣctrs; rewrite HΣctrs in *; simpl in *.
77-
subst G. unfold global_ext_levels; simpl. rewrite no_prop_levels_union.
78-
symmetry; apply add_uctx_make_graph.
77+
intros Σctrs HΣctrs; rewrite HΣctrs in H0, i; simpl in *.
78+
destruct (gc_of_constraints (ConstraintSet.union _ _)).
79+
simpl in H0.
80+
subst G. unfold global_ext_levels; simpl.
81+
symmetry. rewrite add_uctx_make_graph.
82+
apply graph_eq. simpl. reflexivity.
83+
simpl. now rewrite H0. simpl. reflexivity.
84+
now simpl in H0.
7985
Qed.
8086
Next Obligation.
8187
split; sq. 2: constructor; tas.
8288
unfold is_graph_of_uctx, gc_of_uctx; simpl.
8389
unfold gc_of_uctx in e. simpl in e.
8490
case_eq (gc_of_constraints (constraints_of_udecl (universes_decl_of_decl g)));
8591
[|intro HH; rewrite HH in e; discriminate e].
86-
intros ctrs' Hctrs'. rewrite Hctrs' in *.
92+
intros ctrs' Hctrs'. rewrite Hctrs' in e.
8793
cbn in e. inversion e; subst; clear e.
8894
unfold global_ext_constraints; simpl.
89-
rewrite gc_of_constraints_union.
95+
pose proof (gc_of_constraints_union
96+
(constraints_of_udecl (universes_decl_of_decl g)) (global_constraints Σ)).
97+
rewrite Hctrs' in H1; simpl in H1.
98+
red in i. unfold gc_of_uctx in i; simpl in i.
9099
assert (eq: monomorphic_constraints_decl g
91100
= constraints_of_udecl (universes_decl_of_decl g)). {
92101
destruct g. destruct c, cst_universes; try discriminate; reflexivity.
93102
destruct m, ind_universes; try discriminate; reflexivity. }
94-
rewrite eq; clear eq. rewrite Hctrs'.
95-
red in i. unfold gc_of_uctx in i; simpl in i.
103+
rewrite eq; clear eq.
96104
case_eq (gc_of_constraints (global_constraints Σ));
97105
[|intro HH; rewrite HH in i; cbn in i; contradiction i].
98-
intros Σctrs HΣctrs; rewrite HΣctrs in *; simpl in *.
99-
subst G. unfold global_ext_levels; simpl. rewrite no_prop_levels_union.
106+
intros Σctrs HΣctrs; rewrite HΣctrs in H1, i; simpl in *.
107+
destruct (gc_of_constraints (ConstraintSet.union _ _)).
108+
simpl in H1.
109+
subst G. unfold global_ext_levels; simpl.
100110
assert (eq: monomorphic_levels_decl g
101111
= levels_of_udecl (universes_decl_of_decl g)). {
102112
destruct g. destruct c, cst_universes; try discriminate; reflexivity.
103113
destruct m, ind_universes; try discriminate; reflexivity. }
104-
rewrite eq. symmetry; apply add_uctx_make_graph.
114+
rewrite eq. simpl. rewrite add_uctx_make_graph.
115+
apply graph_eq; try reflexivity.
116+
simpl. now rewrite H1.
117+
now simpl in H1.
105118
Qed.
106119
Next Obligation.
107120
split; sq. 2: constructor; tas.
@@ -114,7 +127,7 @@ Program Fixpoint check_wf_env_only_univs (Σ : global_env)
114127
destruct g. destruct c, cst_universes; try discriminate; reflexivity.
115128
destruct m, ind_universes; try discriminate; reflexivity. }
116129
rewrite eq1; clear eq1.
117-
assumption.
130+
now rewrite levelset_union_empty, constraintset_union_empty.
118131
Qed.
119132

120133
(* This is the total erasure function + the optimization that removes all

erasure/theories/ErasureCorrectness.v

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,26 @@ Lemma wf_local_rel_conv:
7979
forall Σ : global_env × universes_decl,
8080
wf Σ.1 ->
8181
forall Γ Γ' : context,
82-
PCUICContextRelation.context_relation (PCUICContextConversion.conv_decls Σ) Γ Γ' ->
82+
context_relation (conv_decls Σ) Γ Γ' ->
8383
forall Γ0 : context, wf_local Σ Γ' -> wf_local_rel Σ Γ Γ0 -> wf_local_rel Σ Γ' Γ0.
8484
Proof.
8585
intros Σ wfΣ Γ Γ' X1 Γ0 ? w0. induction w0.
8686
- econstructor.
8787
- econstructor; eauto. cbn in *.
8888
destruct t0. exists x. eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
89-
eapply conv_context_app; eauto.
90-
eapply typing_wf_local; eauto.
91-
eapply PCUICSafeChecker.wf_local_app_inv; eauto.
89+
* eapply PCUICSafeChecker.wf_local_app_inv; eauto.
90+
* eapply conv_context_app; eauto.
91+
eapply typing_wf_local; eauto.
9292
- econstructor; eauto.
9393
+ cbn in *.
9494
destruct t0. exists x. eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
95-
eapply conv_context_app; eauto.
96-
eapply typing_wf_local; eauto.
97-
eapply PCUICSafeChecker.wf_local_app_inv; eauto.
95+
* eapply PCUICSafeChecker.wf_local_app_inv; eauto.
96+
* eapply conv_context_app; eauto.
97+
eapply typing_wf_local; eauto.
9898
+ cbn in *. eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
99-
eapply conv_context_app; eauto.
100-
eapply typing_wf_local; eauto.
101-
eapply PCUICSafeChecker.wf_local_app_inv; eauto.
99+
* eapply PCUICSafeChecker.wf_local_app_inv; eauto.
100+
* eapply conv_context_app; eauto.
101+
eapply typing_wf_local; eauto.
102102
Qed.
103103

104104
Hint Resolve Is_type_conv_context : core.
@@ -150,17 +150,15 @@ Proof.
150150
eapply All_local_env_impl; eauto. simpl; intros.
151151
destruct T. simpl in *.
152152
eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
153-
eapply conv_context_app; auto. eapply typing_wf_local; eauto.
153+
2:{ eapply conv_context_app; auto. eapply typing_wf_local; eauto. }
154154
eapply typing_wf_local in X3.
155155
eapply PCUICSafeChecker.wf_local_app_inv.
156156
eauto. eapply wf_local_rel_local in X3.
157157
eapply wf_local_rel_app in X3 as []. rewrite app_context_nil_l in w0.
158-
159-
160158
eapply wf_local_rel_conv; eauto.
161159
destruct X3. exists x0.
162160
eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
163-
eapply conv_context_app; auto. eapply typing_wf_local; eauto.
161+
2:{ eapply conv_context_app; auto. eapply typing_wf_local; eauto. }
164162

165163
eapply typing_wf_local in t0.
166164
eapply PCUICSafeChecker.wf_local_app_inv.
@@ -185,7 +183,7 @@ Proof.
185183
eapply All_local_env_impl; eauto. simpl; intros.
186184
destruct T. simpl in *.
187185
eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
188-
eapply conv_context_app; auto. eapply typing_wf_local; eauto.
186+
2:{ eapply conv_context_app; auto. eapply typing_wf_local; eauto. }
189187
eapply typing_wf_local in X3.
190188
eapply PCUICSafeChecker.wf_local_app_inv.
191189
eauto. eapply wf_local_rel_local in X3.
@@ -195,7 +193,7 @@ Proof.
195193
eapply wf_local_rel_conv; eauto.
196194
destruct X3. exists x0.
197195
eapply PCUICContextConversion.context_conversion with (Γ ,,, Γ0); eauto.
198-
eapply conv_context_app; auto. eapply typing_wf_local; eauto.
196+
2:{ eapply conv_context_app; auto. eapply typing_wf_local; eauto. }
199197

200198
eapply typing_wf_local in t0.
201199
eapply PCUICSafeChecker.wf_local_app_inv.

0 commit comments

Comments
 (0)