Skip to content

Commit f698673

Browse files
committed
Big change in universes:
- change the representation of UnivExpr - change the representation of universes (sorted, non empty list w/o duplicate) - prove completness of the comparison algorithm
1 parent e4d4e80 commit f698673

File tree

85 files changed

+3774
-2797
lines changed

Some content is hidden

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

85 files changed

+3774
-2797
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ pcuic/src/pCUICUtils.mli
357357
/erasure/src/pCUICSafeRetyping.mli
358358
/erasure/src/safeErasureFunction.ml
359359
/erasure/src/safeErasureFunction.mli
360+
erasure/src/mSetWeakList.ml
361+
erasure/src/mSetWeakList.mli
362+
erasure/src/utils.ml
363+
erasure/src/utils.mli
360364

361365
template-coq/gen-src/cRelationClasses.mli.rej
362366
.DS_Store

checker/src/metacoq_checker_plugin.mlpack

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Compare_dec
2-
MSetList
31
EqdepFacts
42
Wf
53
WGraph
64
Monad_utils
5+
Utils
6+
MSetWeakList
77
UGraph0
88
EnvironmentTyping
99
Typing0

checker/theories/Checker.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ Section Typecheck.
546546
| None => raise (NotEnoughFuel fuel)
547547
end.
548548

549-
Definition reduce_to_sort Γ (t : term) : typing_result universe :=
549+
Definition reduce_to_sort Γ (t : term) : typing_result Universe.t :=
550550
match t with
551551
| tSort s => ret s
552552
| _ =>

checker/theories/Closed.v

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Proof.
2626
rewrite -> ?map_map_compose, ?compose_on_snd, ?compose_map_def, ?map_length, ?Nat.add_assoc;
2727
simpl closed in *; solve_all;
2828
unfold compose, test_def, test_snd in *;
29-
try solve [simpl lift; simpl closed; f_equal; auto; repeat (toProp; solve_all)]; try easy.
29+
try solve [simpl lift; simpl closed; f_equal; auto; repeat (rtoProp; solve_all)]; try easy.
3030

3131
- elim (Nat.leb_spec k' n0); intros. simpl.
3232
elim (Nat.ltb_spec); auto. apply Nat.ltb_lt in H. lia.
@@ -41,7 +41,7 @@ Proof.
4141
induction t in n, k, k' |- * using term_forall_list_ind; intros;
4242
simpl in *;
4343
rewrite -> ?map_map_compose, ?compose_on_snd, ?compose_map_def, ?map_length, ?Nat.add_assoc in *;
44-
simpl closed in *; repeat (toProp; solve_all); try change_Sk;
44+
simpl closed in *; repeat (rtoProp; solve_all); try change_Sk;
4545
unfold compose, test_def, on_snd, test_snd in *; simpl in *; eauto with all.
4646

4747
- revert H0.
@@ -51,8 +51,8 @@ Proof.
5151
- specialize (IHt2 n (S k) (S k')). eauto with all.
5252
- specialize (IHt2 n (S k) (S k')). eauto with all.
5353
- specialize (IHt3 n (S k) (S k')). eauto with all.
54-
- toProp. solve_all. specialize (H1 n (#|m| + k) (#|m| + k')). eauto with all.
55-
- toProp. solve_all. specialize (H1 n (#|m| + k) (#|m| + k')). eauto with all.
54+
- rtoProp. solve_all. specialize (H1 n (#|m| + k) (#|m| + k')). eauto with all.
55+
- rtoProp. solve_all. specialize (H1 n (#|m| + k) (#|m| + k')). eauto with all.
5656
Qed.
5757

5858
Lemma closedn_mkApps k f u:
@@ -85,7 +85,7 @@ Proof.
8585
induction t in k' |- * using term_forall_list_ind; intros;
8686
simpl in *;
8787
rewrite -> ?map_map_compose, ?compose_on_snd, ?compose_map_def, ?map_length;
88-
simpl closed in *; try change_Sk; repeat (toProp; solve_all);
88+
simpl closed in *; try change_Sk; repeat (rtoProp; solve_all);
8989
unfold compose, test_def, on_snd, test_snd in *; simpl in *; eauto with all.
9090

9191
- elim (Nat.leb_spec k' n); intros. simpl.
@@ -105,10 +105,10 @@ Proof.
105105
- specialize (IHt3 (S k')).
106106
rewrite <- Nat.add_succ_comm in IHt3. eauto.
107107
- rewrite closedn_mkApps; solve_all.
108-
- toProp; solve_all. rewrite -> !Nat.add_assoc in *.
108+
- rtoProp; solve_all. rewrite -> !Nat.add_assoc in *.
109109
specialize (H0 (#|m| + k')). unfold is_true. rewrite <- H0. f_equal. lia.
110110
unfold is_true. rewrite <- H2. f_equal. lia.
111-
- toProp; solve_all. rewrite -> !Nat.add_assoc in *.
111+
- rtoProp; solve_all. rewrite -> !Nat.add_assoc in *.
112112
specialize (H0 (#|m| + k')). unfold is_true. rewrite <- H0. f_equal. lia.
113113
unfold is_true. rewrite <- H2. f_equal. lia.
114114
Qed.
@@ -249,6 +249,7 @@ Proof.
249249
now rewrite app_length // plus_n_Sm.
250250
Qed.
251251

252+
252253
Lemma typecheck_closed `{cf : checker_flags} :
253254
env_prop (fun Σ Γ t T =>
254255
closedn #|Γ| t && closedn #|Γ| T).
@@ -317,7 +318,7 @@ Proof.
317318
eauto using closed_upwards with arith.
318319

319320
- intuition auto. solve_all. unfold test_snd. simpl in *.
320-
toProp; eauto.
321+
rtoProp; eauto.
321322
apply closedn_mkApps; auto.
322323
rewrite forallb_app. simpl. rewrite H1.
323324
rewrite forallb_skipn; auto.
@@ -342,26 +343,26 @@ Proof.
342343

343344
- split. solve_all.
344345
destruct x; simpl in *.
345-
unfold test_def. simpl. toProp.
346+
unfold test_def. simpl. rtoProp.
346347
split.
347348
rewrite -> app_context_length in *. rewrite -> Nat.add_comm in *.
348349
eapply closedn_lift_inv in H2; eauto. lia.
349350
subst types.
350351
now rewrite app_context_length fix_context_length in H1.
351-
eapply nth_error_all in H0; eauto. simpl in H0. intuition. toProp.
352+
eapply nth_error_all in H0; eauto. simpl in H0. intuition. rtoProp.
352353
subst types. rewrite app_context_length in H1.
353354
rewrite Nat.add_comm in H1.
354355
now eapply closedn_lift_inv in H1.
355356

356357
- split. solve_all. destruct x; simpl in *.
357-
unfold test_def. simpl. toProp.
358+
unfold test_def. simpl. rtoProp.
358359
split.
359360
rewrite -> app_context_length in *. rewrite -> Nat.add_comm in *.
360361
eapply closedn_lift_inv in H2; eauto. lia.
361362
subst types.
362363
now rewrite -> app_context_length, fix_context_length in H1.
363364
eapply (nth_error_all) in H; eauto. simpl in *.
364-
intuition. toProp.
365+
intuition. rtoProp.
365366
subst types. rewrite app_context_length in H1.
366367
rewrite Nat.add_comm in H1.
367368
now eapply closedn_lift_inv in H1.
@@ -435,7 +436,7 @@ Proof.
435436
eapply on_global_env_impl; cycle 1.
436437
apply (env_prop_sigma _ typecheck_closed _ X).
437438
red; intros. unfold lift_typing in *. destruct T; intuition auto with wf.
438-
destruct X1 as [s0 Hs0]. simpl. toProp; intuition.
439+
destruct X1 as [s0 Hs0]. simpl. rtoProp; intuition.
439440
Qed.
440441

441442
Lemma closed_decl_upwards k d : closed_decl k d -> forall k', k <= k' -> closed_decl k' d.

checker/theories/Reflect.v

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ Proof.
226226
unfold eq_inductive, eqb; cbn. now rewrite eq_string_refl Nat.eqb_refl.
227227
Defined.
228228

229-
Definition eq_def {A : Set} `{ReflectEq A} (d1 d2 : def A) : bool :=
229+
Definition eq_def {A} `{ReflectEq A} (d1 d2 : def A) : bool :=
230230
match d1, d2 with
231231
| mkdef n1 t1 b1 a1, mkdef n2 t2 b2 a2 =>
232232
eqb n1 n2 && eqb t1 t2 && eqb b1 b2 && eqb a1 a2
233233
end.
234234

235-
#[program] Instance reflect_def : forall {A : Set} `{ReflectEq A}, ReflectEq (def A) := {
235+
#[program] Instance reflect_def : forall {A} `{ReflectEq A}, ReflectEq (def A) := {
236236
eqb := eq_def
237237
}.
238238
Next Obligation.
@@ -246,25 +246,6 @@ Next Obligation.
246246
cbn. constructor. subst. reflexivity.
247247
Defined.
248248

249-
Fixpoint eq_non_empty_list {A : Set} (eqA : A -> A -> bool) (l l' : non_empty_list A) : bool :=
250-
match l, l' with
251-
| NEL.sing a, NEL.sing a' => eqA a a'
252-
| NEL.cons a l, NEL.cons a' l' =>
253-
eqA a a' && eq_non_empty_list eqA l l'
254-
| _, _ => false
255-
end.
256-
257-
#[program] Instance reflect_non_empty_list :
258-
forall {A : Set} `{ReflectEq A}, ReflectEq (non_empty_list A) :=
259-
{ eqb := eq_non_empty_list eqb }.
260-
Next Obligation.
261-
induction x, y; cbn.
262-
destruct (eqb_spec a a0); constructor; congruence.
263-
constructor; congruence.
264-
constructor; congruence.
265-
destruct (eqb_spec a a0), (IHx y); constructor; congruence.
266-
Defined.
267-
268249
Fixpoint eq_cast_kind (c c' : cast_kind) : bool :=
269250
match c, c' with
270251
| VmCast, VmCast
@@ -293,13 +274,16 @@ Local Ltac fcase c :=
293274
let e := fresh "e" in
294275
case c ; intro e ; [ subst ; try (left ; reflexivity) | finish ].
295276

277+
Instance eq_dec_univ : EqDec Universe.t.
278+
Admitted.
279+
296280
Local Ltac term_dec_tac term_dec :=
297281
repeat match goal with
298282
| t : term, u : term |- _ => fcase (term_dec t u)
299-
| u : universe, u' : universe |- _ => fcase (eq_dec u u')
300-
| x : universe_instance, y : universe_instance |- _ =>
283+
| u : Universe.t, u' : Universe.t |- _ => fcase (eq_dec u u')
284+
| x : Instance.t, y : Instance.t |- _ =>
301285
fcase (eq_dec x y)
302-
| x : list Level.t, y : universe_instance |- _ =>
286+
| x : list Level.t, y : Instance.t |- _ =>
303287
fcase (eq_dec x y)
304288
| n : nat, m : nat |- _ => fcase (Nat.eq_dec n m)
305289
| i : ident, i' : ident |- _ => fcase (string_dec i i')
@@ -315,18 +299,18 @@ Local Ltac term_dec_tac term_dec :=
315299

316300
Derive NoConfusion NoConfusionHom for term.
317301

318-
Derive EqDec for term.
319-
Next Obligation.
320-
induction x using term_forall_list_rect ; intro t ;
302+
Instance EqDec_term : EqDec term.
303+
Proof.
304+
intro x; induction x using term_forall_list_rect ; intro t ;
321305
destruct t ; try (right ; discriminate).
322306
all: term_dec_tac term_dec.
323-
- induction H in args |- *.
307+
- induction X in args |- *.
324308
+ destruct args.
325309
* left. reflexivity.
326310
* right. discriminate.
327311
+ destruct args.
328312
* right. discriminate.
329-
* destruct (IHAll args) ; nodec.
313+
* destruct (IHX args) ; nodec.
330314
destruct (p t) ; nodec.
331315
subst. left. inversion e. reflexivity.
332316
- destruct (IHx1 t1) ; nodec.
@@ -343,11 +327,11 @@ Next Obligation.
343327
destruct (IHx3 t3) ; nodec.
344328
subst. left. reflexivity.
345329
- destruct (IHx t) ; nodec.
346-
subst. induction H in args |- *.
330+
subst. induction X in args |- *.
347331
+ destruct args. all: nodec.
348332
left. reflexivity.
349333
+ destruct args. all: nodec.
350-
destruct (IHAll args). all: nodec.
334+
destruct (IHX args). all: nodec.
351335
destruct (p t0). all: nodec.
352336
subst. inversion e. subst.
353337
left. reflexivity.

checker/theories/Retyping.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Section TypeOf.
109109
end
110110
end.
111111

112-
Definition sort_of (Γ : context) (t : term) : typing_result universe :=
112+
Definition sort_of (Γ : context) (t : term) : typing_result Universe.t :=
113113
ty <- type_of Γ t;;
114114
type_of_as_sort type_of Γ ty.
115115

checker/theories/Substitution.v

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Inductive subs `{cf : checker_flags} Σ (Γ : context) : list term -> context ->
3434
(** Linking a context (with let-ins), an instance (reversed substitution)
3535
for its assumptions and a well-formed substitution for it. *)
3636

37-
Inductive context_subst : context -> list term -> list term -> Set :=
37+
Inductive context_subst : context -> list term -> list term -> Type :=
3838
| context_subst_nil : context_subst [] [] []
3939
| context_subst_ass Γ args s na t a :
4040
context_subst Γ args s ->
@@ -920,7 +920,7 @@ Proof.
920920
f_equal.
921921
rewrite (lift_to_extended_list_k _ _ 1) map_map_compose.
922922
pose proof (to_extended_list_k_spec Γ k).
923-
solve_all. destruct H3 as [n [-> Hn]].
923+
solve_all. destruct H2 as [n [-> Hn]].
924924
rewrite /compose /lift (subst_app_decomp [a] s k); auto with wf.
925925
rewrite subst_rel_gt. simpl; lia.
926926
repeat (f_equal; simpl; try lia).
@@ -929,7 +929,7 @@ Proof.
929929
rewrite -IHcontext_subst // to_extended_list_k_cons /=.
930930
rewrite (lift_to_extended_list_k _ _ 1) map_map_compose.
931931
pose proof (to_extended_list_k_spec Γ k).
932-
solve_all. destruct H3 as [n [-> Hn]].
932+
solve_all. destruct H2 as [n [-> Hn]].
933933
rewrite /compose /lift (subst_app_decomp [subst0 s b] s k); auto with wf.
934934
rewrite subst_rel_gt. simpl; lia.
935935
repeat (f_equal; simpl; try lia).
@@ -943,7 +943,7 @@ Proof.
943943
induction 1. constructor.
944944
eapply All_app in wfargs as [wfargs wfa]. inv wfa. inv wfctx.
945945
constructor; intuition auto.
946-
inv wfctx. red in H0. constructor; solve_all. apply wf_subst. solve_all. intuition auto with wf.
946+
inv wfctx. red in H. constructor; solve_all. apply wf_subst. solve_all. intuition auto with wf.
947947
Qed.
948948

949949
Lemma wf_make_context_subst ctx args s' :
@@ -1235,7 +1235,7 @@ Lemma red1_mkApps_l Σ Γ M1 N1 M2 :
12351235
Proof.
12361236
induction M2 in M1, N1 |- *. simpl; auto.
12371237
intros. specialize (IHM2 (mkApp M1 a) (mkApp N1 a)).
1238-
inv H0.
1238+
inv X.
12391239
forward IHM2. apply wf_mkApp; auto.
12401240
forward IHM2. auto.
12411241
rewrite <- !mkApps_mkApp; auto.
@@ -1247,17 +1247,17 @@ Lemma red1_mkApps_r Σ Γ M1 M2 N2 :
12471247
Ast.wf M1 -> All Ast.wf M2 ->
12481248
OnOne2 (red1 Σ Γ) M2 N2 -> red1 Σ Γ (mkApps M1 M2) (mkApps M1 N2).
12491249
Proof.
1250-
intros. induction X in M1, H, H0 |- *.
1251-
inv H0.
1250+
intros. induction X0 in M1, H, X |- *.
1251+
inv X.
12521252
destruct (isApp M1) eqn:Heq. destruct M1; try discriminate.
12531253
simpl. constructor. apply OnOne2_app. constructor. auto.
12541254
rewrite mkApps_tApp; try congruence.
12551255
rewrite mkApps_tApp; try congruence.
12561256
constructor. constructor. auto.
1257-
inv H0.
1258-
specialize (IHX (mkApp M1 hd)). forward IHX.
1259-
apply wf_mkApp; auto. forward IHX; auto.
1260-
now rewrite !mkApps_mkApp in IHX.
1257+
inv X.
1258+
specialize (IHX0 (mkApp M1 hd)). forward IHX0.
1259+
apply wf_mkApp; auto. forward IHX0; auto.
1260+
now rewrite !mkApps_mkApp in IHX0.
12611261
Qed.
12621262

12631263
Lemma wf_fix :
@@ -1402,11 +1402,11 @@ Proof.
14021402
now apply All_map.
14031403
assert(Ast.wf M1). now inv wfM.
14041404
assert(All Ast.wf M2). eapply Forall_All. now inv wfM.
1405-
clear -X H1 H2 wfΓ Hs.
1405+
clear -X H0 X1 wfΓ Hs.
14061406
induction X; constructor; auto.
14071407
intuition.
1408-
eapply b; eauto. now inv H2.
1409-
apply IHX. now inv H2.
1408+
eapply b; eauto. now inv X1.
1409+
apply IHX. now inv X1.
14101410

14111411
- forward IHred1. now inv wfM.
14121412
constructor. specialize (IHred1 _ _ (Γ'' ,, vass na M1) eq_refl).
@@ -1592,13 +1592,13 @@ Proof.
15921592
eapply All2_map.
15931593
eapply All2_impl'. eassumption.
15941594
eapply All_impl. eassumption.
1595-
cbn. apply All2_length in H3 as e. rewrite e.
1595+
cbn. apply All2_length in X0 as e. rewrite e.
15961596
intros x [] y []; now split.
15971597
- constructor.
15981598
eapply All2_map.
15991599
eapply All2_impl'. eassumption.
16001600
eapply All_impl. eassumption.
1601-
cbn. apply All2_length in H3 as e. rewrite e.
1601+
cbn. apply All2_length in X0 as e. rewrite e.
16021602
intros x [] y []; now split.
16031603
Qed.
16041604

@@ -1638,7 +1638,7 @@ Lemma subst_eq_context `{checker_flags} φ l l' n k :
16381638
Proof.
16391639
induction l in l', n, k |- *; inversion 1. constructor.
16401640
rewrite !subst_context_snoc. constructor.
1641-
apply All2_length in H5 as e. rewrite e.
1641+
apply All2_length in X1 as e. rewrite e.
16421642
now apply subst_eq_decl.
16431643
now apply IHl.
16441644
Qed.

0 commit comments

Comments
 (0)