Skip to content

Commit 9ae1653

Browse files
garesFissoreD
andauthored
Fix for new compiler (#692)
Mainly declare types before clauses --------- Co-authored-by: Davide Fissore <[email protected]>
1 parent c9eb00e commit 9ae1653

24 files changed

+140
-56
lines changed

apps/derive/elpi/param1.elpi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
/* ------------------------------------------------------------------------- */
44

55
% Author: Cyril Cohen
6+
pred reali-done i:gref.
7+
8+
:index(3)
9+
pred reali i:term, o:term.
10+
type realiR term -> term -> prop.
611

712
shorten std.{forall, forall2, do!, rev, map2, map}.
813

apps/derive/elpi/param1_functor.elpi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* map over a container */
22
/* license: GNU Lesser General Public License Version 2.1 or later */
33
/* ------------------------------------------------------------------------- */
4+
pred param1-functor-db i:term, i:term, o:term.
5+
pred param1-functor-for i:inductive, o:gref, o:list bool.
46

57
shorten std.{assert!, do!, length, split-at, drop-last, rev, append}.
68

apps/derive/elpi/param2.elpi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
/* ------------------------------------------------------------------------- */
44

55
% Author: Cyril Cohen
6+
pred param-done i:gref.
7+
:index(3)
8+
pred param i:term, o:term, o:term.
9+
type paramR term -> term -> term -> prop.
610

711
shorten std.{forall, forall2, do!, rev, map2, map}.
812

apps/derive/tests/test_derive.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ Inductive rtree A : Type :=
121121
Leaf (n : A) | Node (l : list rtree).
122122

123123
Module XXX.
124-
Elpi derive rtree.
124+
derive list.
125+
derive rtree.
125126
End XXX.
126127

127128
Fail Check XXX.rtree_is_rtree_map.
@@ -161,8 +162,10 @@ Redirect "tmp" Check Pred.Pred_to_Predinv : forall T, Pred T -> Pred.Predinv T.
161162
(* #286 *)
162163
Module Import derive_container.
163164
Unset Implicit Arguments.
165+
Import XXX.
164166
derive
165167
Inductive wimpls {A} `{rtree A} := Kwi (x:A) (y : x = x) : wimpls | Kwa.
168+
166169
End derive_container.
167170
About wimpls.wimpls.
168171
About wimpls.Kwi.

apps/derive/theories/derive/param1.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Elpi Accumulate lp:{{
9292
usage :- coq.error "Usage: derive.param1 <object name>".
9393
}}.
9494
Elpi Typecheck.
95-
9695
Module Export exports.
9796
Elpi derive.param1 eq.
9897
End exports.

apps/tc/elpi/compiler1.elpi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace tc {
2828
tc.get-full-path Inst ClauseName,
2929
Locality => (
3030
tc.add-tc-db ClauseName Grafting Clause,
31-
tc.add-tc-db _ Grafting (tc.instance SectionPath Inst TC)).
31+
tc.add-tc-db _ Grafting (tc.instance SectionPath Inst TC Locality)).
3232
add-inst.aux Inst _ _ _ :-
3333
@global! => tc.add-tc-db _ _ (tc.banned Inst),
3434
coq.error "Not-added" "TC_solver" "[TC] Not yet able to compile" Inst "...".
@@ -51,7 +51,7 @@ namespace tc {
5151
% TC.AddAllInstances or TC.AddInstances InstName
5252
if (is-local; has-context-deps Inst)
5353
(LocalityStr = "Local")
54-
(LocalityStr = "Global"),
54+
(LocalityStr = "Export"),
5555
add-inst Inst TC LocalityStr Prio.
5656

5757
% [add-inst->db IgnoreClassDepL ForceAdd Inst] compiles and add the Inst to
@@ -61,7 +61,7 @@ namespace tc {
6161
add-inst->db _ tt Inst :- !, add-inst>db.aux Inst.
6262
add-inst->db _ _ Inst :-
6363
tc.banned Inst, !, (coq.warning "tc.banned-inst" "TC-warning" Inst "is tc.banned").
64-
add-inst->db _ _ Inst :- tc.instance _ Inst _, !. % the instance has already been added
64+
add-inst->db _ _ Inst :- tc.instance _ Inst _ _, !. % the instance has already been added
6565
add-inst->db IgnoreClassDepL _ Inst :-
6666
get-class-dependencies Inst Dep,
6767
std.exists Dep (std.mem IgnoreClassDepL), !,
@@ -85,11 +85,19 @@ namespace tc {
8585
(coq.warning "not-inst-nor-tc" "TC-warning" GR "is neither a TC nor a instance")
8686
).
8787

88+
pred build-args i:term, o:list term.
89+
build-args (prod _ _ Bo) [{{0}} | TL] :- !, build-args (Bo _) TL.
90+
build-args _ [{{0}}].
91+
8892
% [remove-inst GR] remove an instance from the DB by replacing it with `dummy`
8993
pred remove-inst i:gref.
9094
remove-inst InstGR :-
9195
tc.get-full-path InstGR ClauseName,
92-
tc.remove-clause ClauseName.
96+
tc.instance _ InstGR ClassGR Locality,
97+
tc.gref->pred-name ClassGR PredName,
98+
coq.env.typeof ClassGR ClassTy,
99+
coq.elpi.predicate PredName {build-args ClassTy} Clause,
100+
tc.remove-clause ClauseName Clause Locality.
93101

94102
pred is-in-path i:string, i:gref.
95103
is-in-path Path GR :-

apps/tc/elpi/modes.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace tc {
6666

6767
pred remove-pending-mode.
6868
remove-pending-mode :-
69-
tc.remove-clause @pending-mode!.
69+
tc.remove-clause @pending-mode! (pending-mode []) [].
7070

7171
pred check-pending-mode-arity i:gref, i:list A.
7272
check-pending-mode-arity GR L :-

apps/tc/elpi/tc_aux.elpi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ namespace tc {
4242
:name "MySectionEndHook"
4343
instances-of-current-section InstsFiltered :-
4444
coq.env.current-section-path SectionPath,
45-
std.findall (tc.instance SectionPath _ _) Insts,
45+
std.findall (tc.instance SectionPath _ _ _) Insts,
4646
coq.env.section SectionVars,
47-
std.map-filter Insts (x\r\ sigma X\ tc.instance _ r _ = x, const X = r, not(std.mem SectionVars X)) InstsFiltered.
47+
std.map-filter Insts (x\r\ sigma X\ tc.instance _ r _ _ = x, const X = r, not(std.mem SectionVars X)) InstsFiltered.
4848

4949
pred is-instance-gr i:gref.
5050
is-instance-gr GR :-
@@ -156,9 +156,9 @@ namespace tc {
156156

157157
pred dummy.
158158

159-
pred remove-clause i:string.
160-
remove-clause ClauseName :-
161-
add-tc-db _ (replace ClauseName) dummy.
159+
pred remove-clause i:string, i:prop, i:list prop.
160+
remove-clause ClauseName P Locality :-
161+
Locality => add-tc-db _ (remove ClauseName) P.
162162

163163
% [section-var->decl.aux L R] auxiliary function for `section-var->decl`
164164
pred section-var->decl.aux i:list constant, o:list prop.

apps/tc/elpi/tc_same_order.elpi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pred correct_instance_order i:(list gref), i:(list prop).
1212
correct_instance_order [] _.
1313
correct_instance_order [TC | TL] ElpiInst :-
1414
coq.TC.db-for TC CoqInst,
15-
std.map-filter ElpiInst (x\r\ sigma I\ x = tc.instance _ I TC, r = I) ElpiInstTC,
15+
std.map-filter ElpiInst (x\r\ sigma I\ x = tc.instance _ I TC _, r = I) ElpiInstTC,
1616
if (correct_instance_order_aux TC CoqInst ElpiInstTC)
1717
(correct_instance_order TL ElpiInst)
1818
(coq.error "Error in import order\n"
1919
"Expected :" CoqInst "\nFound :" ElpiInstTC).
2020

2121
:name "tc-same-order-main"
2222
main _ :-
23-
std.findall (tc.instance _ _ _) ElpiInst,
23+
std.findall (tc.instance _ _ _ _) ElpiInst,
2424
correct_instance_order {coq.TC.db-tc} ElpiInst.

apps/tc/tests/auto_compile.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Goal M.B 10. apply _. Qed.
4848
Elpi Query TC.Solver lp:{{
4949
% Small test for instance order
5050
sigma I L\
51-
std.findall (tc.instance _ _ _) I,
52-
std.map-filter I (x\y\ x = tc.instance _ y {{:gref M.B}})
51+
std.findall (tc.instance _ _ _ _) I,
52+
std.map-filter I (x\y\ x = tc.instance _ y {{:gref M.B}} _)
5353
[{{:gref M.W}}, {{:gref M.Y}}, {{:gref M.Z}}].
5454
}}.
5555

apps/tc/tests/hook_test.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Instance Inst2 : A 100 | 1512. Qed.
1010

1111
Elpi Query TC.Solver lp:{{
1212
sigma InstL GrefL\
13-
std.findall (tc.instance _ _ {{:gref A}}) InstL,
14-
std.map InstL (x\r\ x = tc.instance _ r _) GrefL,
13+
std.findall (tc.instance _ _ {{:gref A}} _) InstL,
14+
std.map InstL (x\r\ x = tc.instance _ r _ _) GrefL,
1515
GrefL = [{{:gref Inst2}}, {{:gref Inst1}}].
1616
}}.
1717

apps/tc/tests/section_in_out.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Elpi Accumulate lp:{{
1212
% contains the number of instances that are not
1313
% imported from other files
1414
main [int Len] :-
15-
std.findall (tc.instance _ _ _) Insts,
16-
std.map Insts (x\r\ tc.instance _ r _ = x) R,
15+
std.findall (tc.instance _ _ _ _) Insts,
16+
std.map Insts (x\r\ tc.instance _ r _ _ = x) R,
1717
WantedLength is {origial_tc} + Len,
1818
std.assert! ({std.length R} = WantedLength)
1919
"Unexpected number of instances",
@@ -22,7 +22,7 @@ Elpi Accumulate lp:{{
2222
}}.
2323

2424
Elpi Query TC.Solver lp:{{
25-
std.findall (tc.instance _ _ _) Rules,
25+
std.findall (tc.instance _ _ _ _) Rules,
2626
std.length Rules Len,
2727
coq.elpi.accumulate _ "tc.db" (clause _ _ (origial_tc Len)).
2828
}}.

apps/tc/tests/test_coercion.v

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,60 @@ Module Vehicle.
4949

5050
Class Wheels (i: nat).
5151

52-
Class Boat.
53-
54-
Class NoWheels `{Wheels 0} := {
52+
Class NoWheels := {
5553
(* the first argument of no_wheels is implicit! *)
56-
no_wheels : Boat;
54+
wheels0 :: Wheels 0;
5755
}.
5856

59-
Arguments no_wheels {_}.
60-
61-
Instance f `{H : Wheels 0} : NoWheels. Admitted.
57+
Class Boat := {
58+
wheels :: NoWheels
59+
}.
6260

63-
Goal Wheels 0 -> Boat.
61+
Goal Boat -> Wheels 0.
6462
intros.
65-
apply no_wheels.
6663
apply _.
6764
Qed.
6865

6966
End Vehicle.
67+
68+
Module foo.
69+
Class B (i : nat).
70+
71+
Section s.
72+
(* Class with coercion depending on section parameters *)
73+
Context (A : Type).
74+
Class C (i : nat) : Set := {
75+
f (x : A) :: B i
76+
}.
77+
End s.
78+
End foo.
79+
80+
Module foo1.
81+
Class B (i : nat).
82+
83+
Section s.
84+
(* Class with coercion not depending on section parameters *)
85+
Class C (i : nat) : Set := {
86+
f :: B i
87+
}.
88+
End s.
89+
90+
Goal C 3 -> B 3.
91+
apply _.
92+
Abort.
93+
End foo1.
94+
95+
Module localCoercion.
96+
Class B (i : nat).
97+
Section s.
98+
Class C (i : nat) : Set := {
99+
#[local] f :: B i
100+
}.
101+
Goal C 3 -> B 3.
102+
apply _.
103+
Qed.
104+
End s.
105+
Goal C 3 -> B 3.
106+
Fail apply _.
107+
Abort.
108+
End localCoercion.

apps/tc/tests/test_coercion_import.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
From elpi.apps.tc.tests Require Import test_coercion.
2+
3+
Import Animals.Bird1.
4+
5+
6+
Elpi Query TC.Solver lp:{{
7+
true.
8+
}}.

apps/tc/tests/test_commands_API.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Elpi Accumulate lp:{{
77
pred count i:gref, i:int.
88
count GR Len :-
99
if (const _ = GR)
10-
(std.findall (tc.instance _ _ GR) Cl,
10+
(std.findall (tc.instance _ _ GR _) Cl,
1111
std.assert! ({std.length Cl} = Len)
1212
"Unexpected number of instances")
1313
true.

apps/tc/tests/test_unfold.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Module NAT.
55
TC.Unfold Nat.succ.
66
Class nat2 (T : nat -> nat).
77

8-
Elpi Accumulate tc.db lp:{{
8+
Elpi Accumulate TC.Solver lp:{{
99
% Just to print what is beeing normalized
1010
:after "firstHook"
1111
tc.normalize-ty T _ :- coq.say "Normalizing" T, fail.

apps/tc/theories/db.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ Elpi Db tc.db lp:{{
7373
type deterministic search-mode.
7474
type classic search-mode.
7575

76-
% [instance Path InstGR ClassGR], ClassGR is the class implemented by InstGR
77-
pred instance o:list string, o:gref, o:gref.
76+
% [instance Path InstGR ClassGR Locality], ClassGR is the class implemented by InstGR
77+
% Locality is either the empty list, or [@local!], or [@global!]
78+
pred instance o:list string, o:gref, o:gref, o:list prop.
7879

7980
% [class ClassGR PredName SearchMode Modes], for each class GR, it contains
8081
% the name of its predicate and its SearchMode

apps/tc/theories/tc.v

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ Set Warnings "+elpi".
2323
Elpi Command TC.Print_instances.
2424
Elpi Accumulate Db tc.db.
2525
Elpi Accumulate lp:{{
26+
pred tc.list-printer-aux i:prop.
27+
tc.list-printer-aux (tc.instance _ InstGR _ Locality) :-
28+
coq.say InstGR "with locality" Locality.
29+
2630
pred tc.list-printer i:gref, i:list prop.
2731
tc.list-printer _ [].
2832
tc.list-printer ClassGR Instances :-
29-
std.map Instances (x\r\ x = tc.instance _ r _) InstancesGR,
3033
coq.say "Instances list for" ClassGR "is:",
31-
std.forall InstancesGR (x\ coq.say " " x).
34+
std.forall Instances tc.list-printer-aux.
3235

3336
main [str Class] :-
3437
std.assert! (coq.locate Class ClassGR) "The entered TC not exists",
35-
std.findall (tc.instance _ _ ClassGR) Rules,
38+
std.findall (tc.instance _ _ ClassGR _) Rules,
3639
tc.list-printer ClassGR Rules.
3740
main [] :-
3841
std.forall {coq.TC.db-tc} (ClassGR\ sigma Rules\
39-
std.findall (tc.instance _ _ ClassGR) Rules,
42+
std.findall (tc.instance _ _ ClassGR _) Rules,
4043
tc.list-printer ClassGR Rules
4144
).
4245
}}.
@@ -141,7 +144,7 @@ Elpi Accumulate lp:{{
141144
coq.locate ClassStr ClassGR,
142145
std.assert! (coq.TC.class? ClassGR) "Should pass the name of a type class",
143146
std.assert! (tc.class ClassGR PredName _ Modes) "Cannot find `class ClassGR _ _` in the db",
144-
std.assert! (not (tc.instance _ _ ClassGR)) "Cannot set deterministic a class with an already existing instance",
147+
std.assert! (not (tc.instance _ _ ClassGR _)) "Cannot set deterministic a class with an already existing instance",
145148
tc.add-tc-db _ (after "0") (tc.class ClassGR PredName tc.deterministic Modes :- !).
146149
}}.
147150
Elpi Typecheck.

builtin-doc/coq-builtin-synterp.elpi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ type clause id -> grafting -> prop -> clause.
314314
kind grafting type.
315315
type before id -> grafting.
316316
type after id -> grafting.
317+
type remove id -> grafting.
317318
type replace id -> grafting.
318319

319320
% Specify to which module the clause should be attached to

builtin-doc/coq-builtin.elpi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ external pred coq.version o:string, o:int, o:int, o:int.
558558

559559
% To make the API more precise we use different data types for the names
560560
% of global objects.
561-
% Note: [ctype \"bla\"] is an opaque data type and by convention it is
562-
% written [@bla].
561+
% Note: [ctype "bla"] is an opaque data type and by convention it is written
562+
% [@bla].
563563

564564
% Global constant name
565565
typeabbrev constant (ctype "constant").
@@ -1758,6 +1758,7 @@ type clause id -> grafting -> prop -> clause.
17581758
kind grafting type.
17591759
type before id -> grafting.
17601760
type after id -> grafting.
1761+
type remove id -> grafting.
17611762
type replace id -> grafting.
17621763

17631764
% Specify to which module the clause should be attached to

builtin-doc/elpi-builtin.elpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ pred ignore-failure! i:prop.
449449
ignore-failure! P :- P, !.
450450
ignore-failure! _.
451451

452+
pred once i:prop.
453+
once P :- P, !.
454+
452455
% [assert! C M] takes the first success of C or fails with message M
453456
pred assert! i:prop, i:string.
454457
assert! Cond Msg :- (Cond ; fatal-error-w-data Msg Cond), !.

0 commit comments

Comments
 (0)