Skip to content

Commit 8a249be

Browse files
proux01gares
andcommitted
Compile without Stdlib
Co-authored-by: Enrico Tassi <[email protected]>
1 parent 210c7cb commit 8a249be

File tree

21 files changed

+264
-68
lines changed

21 files changed

+264
-68
lines changed

Makefile

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,52 @@
11
dune = dune $(1) $(DUNE_$(1)_FLAGS)
22

3-
elpi/dune: elpi/dune.in
4-
@rm -f $@
5-
@echo "; generated by make, do not edit" > $@
6-
@if $$(coqc --version | grep -q "8.19\|8.20") ; then \
7-
sed -e 's/@@STDLIB_THEORY@@//' $< >> $@ ; \
8-
else \
9-
sed -e 's/@@STDLIB_THEORY@@/(theories Stdlib)/' $< >> $@ ; \
10-
fi
11-
@chmod a-w $@
12-
13-
all: elpi/dune theories-stdlib/dune
3+
all: theories-stdlib/dune
144
$(call dune,build)
155
$(call dune,build) builtin-doc
166
.PHONY: all
177

18-
build-core: elpi/dune theories-stdlib/dune
8+
build-core: theories-stdlib/dune
199
$(call dune,build) theories
2010
$(call dune,build) builtin-doc
2111
.PHONY: build-core
2212

23-
build-apps: elpi/dune theories-stdlib/dune
13+
build-apps: theories-stdlib/dune
2414
$(call dune,build) $$(find apps -type d -name theories)
2515
.PHONY: build-apps
2616

27-
build: elpi/dune theories-stdlib/dune
17+
build: theories-stdlib/dune
2818
$(call dune,build) -p coq-elpi @install
2919
$(call dune,build) builtin-doc
3020
.PHONY: build
3121

3222
all-tests: test-core test-stdlib test-apps test-apps-stdlib
3323
.PHONY: all-tests
3424

35-
test-core: elpi/dune theories-stdlib/dune
25+
test-core: theories-stdlib/dune
3626
$(call dune,runtest) tests
3727
$(call dune,build) tests
3828
.PHONY: test-core
3929

40-
test-apps: elpi/dune theories-stdlib/dune
30+
test-apps: theories-stdlib/dune
4131
$(call dune,build) $$(find apps -type d -name tests)
4232
.PHONY: test-apps
4333

44-
test-apps-stdlib: elpi/dune theories-stdlib/dune
34+
test-apps-stdlib: theories-stdlib/dune
4535
$(call dune,build) $$(find apps -type d -name tests-stdlib)
4636
.PHONY: test-apps-stdlib
4737

48-
test-stdlib: elpi/dune theories-stdlib/dune
38+
test-stdlib: theories-stdlib/dune
4939
$(call dune,build) tests-stdlib
5040
.PHONY: test-stdlib
5141

5242
all-examples: examples examples-stdlib
5343
.PHONY: all-examples
5444

55-
examples: elpi/dune theories-stdlib/dune
45+
examples: theories-stdlib/dune
5646
$(call dune,build) examples
5747
.PHONY: examples
5848

59-
examples-stdlib: elpi/dune theories-stdlib/dune
49+
examples-stdlib: theories-stdlib/dune
6050
$(call dune,build) examples-stdlib
6151
.PHONY: examples-stdlib
6252

@@ -88,7 +78,7 @@ clean:
8878
$(call dune,clean)
8979
.PHONY: clean
9080

91-
install: elpi/dune
81+
install:
9282
$(call dune,install) coq-elpi
9383
.PHONY: install
9484

apps/derive/elpi/eqbOK.elpi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ add-reflect (type-param F) Correct Refl {{
1515
fun (a : lp:Type) (eqA: a -> a -> bool) (heqA : lp:(HeqA a eqA)) => lp:(R a eqA heqA)
1616
}} :-
1717
Type = sort (typ {coq.univ.new}),
18-
HeqA = (a\eqA\ {{ forall x1 x2 : lp:a, reflect (@eq lp:a x1 x2) (lp:eqA x1 x2) }}),
18+
HeqA = (a\eqA\ {{ forall x1 x2 : lp:a, lib:elpi.reflect (@eq lp:a x1 x2) (lp:eqA x1 x2) }}),
1919
@pi-trm `a` Type aa\a\
2020
@pi-decl `eqA` {{ lp:a -> lp:a -> bool }} eqA\
2121
@pi-decl `heqA` (HeqA a eqA) heqA\
@@ -56,7 +56,7 @@ main (const C) Prefix [CL] :- std.do! [
5656
std.assert-ok! (coq.typecheck Breflect _) "eqbOK generates illtyped term",
5757
coq.ensure-fresh-global-id (Prefix ^ "eqb_OK") Namerf,
5858
X = (global (const C) : term),
59-
coq.env.add-const Namerf Breflect {{ forall a b : lp:X, Bool.reflect (@eq lp:X a b) (lp:F a b) }} @opaque! Reflect,
59+
coq.env.add-const Namerf Breflect {{ forall a b : lp:X, lib:elpi.reflect (@eq lp:X a b) (lp:F a b) }} @opaque! Reflect,
6060
CL = eqbok-for (const C) Reflect,
6161
coq.elpi.accumulate _ "derive.eqbOK.db" (clause _ _ CL),
6262
].

apps/derive/elpi/tag.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ do-dummy-branch _ _ _ _ {{ Prop }}. % dummy
5252
% [do-branch InTerm Acc NewTem NewAcc] descends into a branch and puts Acc
5353
% in place of the dummy
5454
pred do-branch i:term, i:term, o:term, o:term.
55-
do-branch {{ Prop }} X X Y :- coq.reduction.lazy.norm {{ lp:X + 1 }} Y.
55+
do-branch {{ Prop }} X X Y :- coq.reduction.lazy.norm {{ Pos.add lp:X 1 }} Y.
5656
do-branch (fun N T F) X (fun N T R) Y :-
5757
@pi-decl N T x\ do-branch (F x) X (R x) Y.
5858

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
(* Borrowed from Stdlib.Logic.EqdepFacts *)
2+
3+
Section Dependent_Equality.
4+
5+
Variables (U : Type) (P : U -> Type).
6+
7+
(** Dependent equality *)
8+
9+
Inductive eq_dep (p : U) (x : P p) : forall q : U, P q -> Prop :=
10+
eq_dep_intro : eq_dep p x p x.
11+
#[local] Hint Constructors eq_dep: core.
12+
13+
Lemma eq_dep_sym (p q : U) (x : P p) (y : P q) :
14+
eq_dep p x q y -> eq_dep q y p x.
15+
Proof. destruct 1; auto. Qed.
16+
17+
Scheme eq_indd := Induction for eq Sort Prop.
18+
19+
Inductive eq_dep1 (p : U) (x : P p) (q : U) (y : P q) : Prop :=
20+
eq_dep1_intro : forall h : q = p, x = eq_rect _ _ y _ h -> eq_dep1 p x q y.
21+
22+
Lemma eq_dep_dep1 (p q : U) (x : P p) (y : P q) :
23+
eq_dep p x q y -> eq_dep1 p x q y.
24+
Proof.
25+
revert q x y; destruct 1.
26+
apply eq_dep1_intro with (eq_refl p).
27+
simpl; trivial.
28+
Qed.
29+
30+
End Dependent_Equality.
31+
32+
Arguments eq_dep [U P] p x q _.
33+
Arguments eq_dep1 [U P] p x q y.
34+
35+
Section Equivalences.
36+
37+
Variable U : Type.
38+
39+
Definition Eq_rect_eq_on (p : U) (Q : U -> Type) (x : Q p) :=
40+
forall (h : p = p), x = eq_rect p Q x p h.
41+
Definition Eq_rect_eq := forall p Q x, Eq_rect_eq_on p Q x.
42+
43+
Definition Eq_dep_eq_on (P : U -> Type) (p : U) (x : P p) :=
44+
forall (y : P p), eq_dep p x p y -> x = y.
45+
Definition Eq_dep_eq := forall P p x, Eq_dep_eq_on P p x.
46+
47+
Definition UIP_on_ (x y : U) (p1 : x = y) := forall (p2 : x = y), p1 = p2.
48+
Definition UIP_ := forall x y p1, UIP_on_ x y p1.
49+
50+
Definition Streicher_K_on_ (x : U) (P : x = x -> Prop) :=
51+
P (eq_refl x) -> forall p : x = x, P p.
52+
Definition Streicher_K_ := forall x P, Streicher_K_on_ x P.
53+
54+
Lemma eq_rect_eq_on__eq_dep1_eq_on (p : U) (P : U -> Type) (y : P p) :
55+
Eq_rect_eq_on p P y -> forall (x : P p), eq_dep1 p x p y -> x = y.
56+
Proof.
57+
intro eq_rect_eq.
58+
simple destruct 1; intro.
59+
rewrite <- eq_rect_eq; auto.
60+
Qed.
61+
Lemma eq_rect_eq__eq_dep1_eq :
62+
Eq_rect_eq -> forall (P:U->Type) (p:U) (x y:P p), eq_dep1 p x p y -> x = y.
63+
Proof.
64+
exact (fun eq_rect_eq P p y x =>
65+
@eq_rect_eq_on__eq_dep1_eq_on p P x (eq_rect_eq p P x) y).
66+
Qed.
67+
68+
Lemma eq_rect_eq_on__eq_dep_eq_on (p : U) (P : U -> Type) (x : P p) :
69+
Eq_rect_eq_on p P x -> Eq_dep_eq_on P p x.
70+
Proof.
71+
intros eq_rect_eq; red; intros y H.
72+
symmetry; apply (eq_rect_eq_on__eq_dep1_eq_on _ _ _ eq_rect_eq).
73+
apply eq_dep_sym in H; apply eq_dep_dep1; trivial.
74+
Qed.
75+
Lemma eq_rect_eq__eq_dep_eq : Eq_rect_eq -> Eq_dep_eq.
76+
Proof.
77+
exact (fun eq_rect_eq P p x y =>
78+
@eq_rect_eq_on__eq_dep_eq_on p P x (eq_rect_eq p P x) y).
79+
Qed.
80+
Lemma eq_dep_eq_on__UIP_on (x y : U) (p1 : x = y) :
81+
Eq_dep_eq_on (fun y => x = y) x eq_refl -> UIP_on_ x y p1.
82+
Proof.
83+
intro eq_dep_eq; red.
84+
elim p1 using eq_indd.
85+
intros p2; apply eq_dep_eq.
86+
elim p2 using eq_indd.
87+
apply eq_dep_intro.
88+
Qed.
89+
Lemma eq_dep_eq__UIP : Eq_dep_eq -> UIP_.
90+
Proof.
91+
exact (fun eq_dep_eq x y p1 =>
92+
@eq_dep_eq_on__UIP_on x y p1 (eq_dep_eq _ _ _)).
93+
Qed.
94+
95+
Lemma Streicher_K_on__eq_rect_eq_on (p : U) (P : U -> Type) (x : P p) :
96+
Streicher_K_on_ p (fun h => x = eq_rect _ P x _ h) -> Eq_rect_eq_on p P x.
97+
Proof.
98+
intro Streicher_K; red; intros.
99+
apply Streicher_K.
100+
reflexivity.
101+
Qed.
102+
Lemma Streicher_K__eq_rect_eq : Streicher_K_ -> Eq_rect_eq.
103+
Proof.
104+
exact (fun Streicher_K p P x =>
105+
@Streicher_K_on__eq_rect_eq_on p P x (Streicher_K p _)).
106+
Qed.
107+
End Equivalences.
108+
109+
Arguments eq_dep U P p x q _ : clear implicits.
110+
111+
Set Implicit Arguments.
112+
113+
Section EqdepDec.
114+
115+
Variable A : Type.
116+
117+
Let comp (x y y' : A) (eq1 : x = y) (eq2 : x = y') : y = y' :=
118+
eq_ind _ (fun a => a = y') eq2 _ eq1.
119+
120+
Remark trans_sym_eq (x y : A) (u : x = y) : comp u u = eq_refl y.
121+
Proof. now case u. Qed.
122+
123+
Variables (x : A) (eq_dec : forall y : A, x = y \/ x <> y).
124+
125+
Let nu (y : A) (u : x = y) : x = y :=
126+
match eq_dec y with
127+
| or_introl eqxy => eqxy
128+
| or_intror neqxy => False_ind _ (neqxy u)
129+
end.
130+
131+
#[local] Lemma nu_constant (y:A) (u v:x = y) : nu u = nu v.
132+
Proof.
133+
unfold nu; destruct (eq_dec y) as [Heq|Hneq]; [reflexivity|].
134+
now case Hneq.
135+
Qed.
136+
137+
Let nu_inv (y : A) (v : x = y) : x = y := comp (nu (eq_refl x)) v.
138+
139+
Remark nu_left_inv_on (y : A) (u : x = y) : nu_inv (nu u) = u.
140+
Proof. case u; unfold nu_inv; apply trans_sym_eq. Qed.
141+
142+
Theorem eq_proofs_unicity_on (y : A) (p1 p2 : x = y) : p1 = p2.
143+
Proof.
144+
elim (nu_left_inv_on p1).
145+
elim (nu_left_inv_on p2).
146+
now elim nu_constant with y p1 p2.
147+
Qed.
148+
149+
Theorem K_dec_on (P : x = x -> Prop) (H : P (eq_refl x)) (p : x = x) : P p.
150+
Proof. now elim eq_proofs_unicity_on with x (eq_refl x) p. Qed.
151+
152+
End EqdepDec.
153+
154+
Theorem K_dec A (eq_dec : forall x y : A, x = y \/ x <> y) (x : A) :
155+
forall P : x = x -> Prop, P (eq_refl x) -> forall p : x = x, P p.
156+
Proof. exact (@K_dec_on A x (eq_dec x)). Qed.
157+
158+
Section Eq_dec.
159+
160+
Variables (A : Type) (eq_dec : forall x y : A, {x = y} + {x <> y}).
161+
162+
Theorem K_dec_type (x : A) (P : x = x -> Prop) (H : P (eq_refl x)) (p : x = x) :
163+
P p.
164+
Proof.
165+
elim p using K_dec; [|now trivial].
166+
now intros x0 y; case (eq_dec x0 y); [left|right].
167+
Qed.
168+
169+
Theorem eq_rect_eq_dec : forall (p : A) (Q : A -> Type) (x : Q p) (h : p = p),
170+
x = eq_rect p Q x p h.
171+
Proof. exact (Streicher_K__eq_rect_eq A K_dec_type). Qed.
172+
173+
Theorem eq_dep_eq_dec : forall (P : A->Type) (p : A) (x y : P p),
174+
eq_dep A P p x p y -> x = y.
175+
Proof. exact (eq_rect_eq__eq_dep_eq A eq_rect_eq_dec). Qed.
176+
177+
End Eq_dec.

apps/derive/theories/derive/bcongr.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ From elpi.apps.derive.elpi Extra Dependency "bcongr.elpi" as bcongr.
88
From elpi.apps.derive.elpi Extra Dependency "derive_hook.elpi" as derive_hook.
99
From elpi.apps.derive.elpi Extra Dependency "derive_synterp_hook.elpi" as derive_synterp_hook.
1010

11-
From Coq Require Export Bool.
1211
From elpi Require Export elpi.
1312
From elpi.apps Require Export derive.
1413
From elpi.apps Require Export derive.projK.

apps/derive/theories/derive/eq.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ From elpi.apps.derive.elpi Extra Dependency "eq.elpi" as eq.
66
From elpi.apps.derive.elpi Extra Dependency "derive_hook.elpi" as derive_hook.
77
From elpi.apps.derive.elpi Extra Dependency "derive_synterp_hook.elpi" as derive_synterp_hook.
88

9-
From Coq Require Import Bool.
109
From elpi Require Import elpi.
1110
From elpi.apps Require Import derive.
1211

13-
From Coq Require Import PrimInt63 PrimFloat.
12+
From elpi.core Require Import PrimInt63 PrimFloat.
1413

1514
Register Coq.Numbers.Cyclic.Int63.PrimInt63.eqb as elpi.derive.eq_unit63.
1615
Register Coq.Floats.PrimFloat.eqb as elpi.derive.eq_float64.

apps/derive/theories/derive/eqK.v

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ From elpi.apps.derive.elpi Extra Dependency "eqK.elpi" as eqK.
88
From elpi.apps.derive.elpi Extra Dependency "derive_hook.elpi" as derive_hook.
99
From elpi.apps.derive.elpi Extra Dependency "derive_synterp_hook.elpi" as derive_synterp_hook.
1010

11+
From elpi.core Require Import Bool. (* remove when requiring Rocq >= 9.0 *)
1112
From elpi Require Import elpi.
1213
From elpi.apps Require Import derive.
1314
From elpi.apps Require Import derive.bcongr derive.eq derive.isK.
1415

1516
Definition eq_axiom T eqb :=
16-
forall (x y : T), Bool.Bool.reflect (x = y) (eqb x y).
17+
forall (x y : T), Datatypes.reflect (x = y) (eqb x y).
1718

1819
Definition eq_axiom_at T eqb (x : T) :=
19-
forall y, Bool.Bool.reflect (x = y) (eqb x y).
20+
forall y, Datatypes.reflect (x = y) (eqb x y).
2021

2122
Definition eq_axiom_on T eqb (x y : T) :=
22-
Bool.Bool.reflect (x = y) (eqb x y).
23+
Datatypes.reflect (x = y) (eqb x y).
2324

2425
Register eq_axiom as elpi.derive.eq_axiom.
2526
Register eq_axiom_at as elpi.derive.eq_axiom_at.

apps/derive/theories/derive/eqType_ast.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
From elpi Require Import elpi.
2-
From Coq Require Import PrimInt63 PrimFloat.
2+
From elpi.core Require Import PrimInt63 PrimFloat.
33
From elpi.apps Require Import derive.
44

55
From elpi.apps.derive.elpi Extra Dependency "eqType.elpi" as eqType.

apps/derive/theories/derive/eqb.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From elpi Require Import elpi.
22
From elpi.apps Require Import derive derive.param1.
3-
From Coq Require Import ssrbool ssreflect Uint63.
4-
From Coq Require Import PArith.
3+
From elpi.core Require Import ssrbool ssreflect PrimInt63.
4+
From elpi.core Require Import PosDef.
55

66
From elpi.apps.derive.elpi Extra Dependency "fields.elpi" as fields.
77
From elpi.apps.derive.elpi Extra Dependency "eqb.elpi" as eqb.

0 commit comments

Comments
 (0)