Skip to content

Commit 657476b

Browse files
committed
fix
1 parent 5e19120 commit 657476b

File tree

10 files changed

+48
-56
lines changed

10 files changed

+48
-56
lines changed

apps/tc/elpi/compile_goal.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace tc {
6666
compile-full-aux (app [global (const C) | _] as G) L G' [tc.link.cs G' G | L] :- coq.env.projection? C _, !.
6767

6868
% Link for primitive projection
69-
compile-full-aux (app [primitive (proj P _) | _] as G) L G' [tc.link.cs G' G | L] :- coq.env.primitive-projection? P _, !.
69+
compile-full-aux (app [primitive (proj P _) | _] as G) L G' [tc.link.cs G' G | L] :- coq.env.primitive-projection? P _ _, !.
7070

7171
% Link for eta-redex
7272
compile-full-aux (fun Name_ Ty Bo as G) L G' [tc.link.eta G' (fun `_` Ty' Bo') | L'] :- maybe-eta G, !,

apps/tc/elpi/compile_instance.elpi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace tc {
101101
(pi x\ get-range-arity-aux T (B x) R1),
102102
min-max-nat R R1 R2.
103103
get-range-arity-aux _ (global _) @max-min :- !.
104-
get-range-arity-aux _ (uvar _) @max-min :- !.
104+
get-range-arity-aux _ uvar @max-min :- !.
105105
get-range-arity-aux _ (sort _) @max-min :- !.
106106
get-range-arity-aux _ (pglobal _ _) @max-min :- !.
107107
get-range-arity-aux A B _ :- coq.error "Count maximal arity failure" A B.
@@ -118,7 +118,7 @@ namespace tc {
118118
precompile-aux _ (primitive _ as C) A C A :- !.
119119
precompile-aux _ T A (tc.coercion T Scope) (s A) :- coq.safe-dest-app T HD _, tc.coercion-unify HD, !, free-var Scope.
120120
precompile-aux _ (app [global (const C) | _] as T) A (tc.canonical-projection T Scope N) (s A) :- coq.env.projection? C N, !, free-var Scope.
121-
precompile-aux _ (app [primitive (proj P _) | _] as T) A (tc.canonical-projection T Scope 0) (s A) :- coq.env.primitive-projection? P _, !, free-var Scope.
121+
precompile-aux _ (app [primitive (proj P _) | _] as T) A (tc.canonical-projection T Scope 0) (s A) :- coq.env.primitive-projection? P _ _, !, free-var Scope.
122122

123123
% Detect maybe-eta term
124124
% TODO: should I precompile also the type of the fun and put it in the output term
@@ -387,8 +387,8 @@ namespace tc {
387387
i:list prop,
388388
o:prop.
389389
compile-premise L L2 P PTy ProofHd IsPositive ITy ProofArgsR PremR Clause :-
390-
(pi a b c\ tc.get-TC-of-inst-type (tc.prod-range a c) b :- tc.get-TC-of-inst-type a b) =>
391-
tc.get-TC-of-inst-type PTy TC, !,
390+
((pi a b c\ tc.get-TC-of-inst-type (tc.prod-range a c) b :- tc.get-TC-of-inst-type a b) =>
391+
tc.get-TC-of-inst-type PTy TC), !,
392392
compile-ty L L1 P {neg IsPositive} PTy [] [] NewPrem,
393393
deterministic-prem TC NewPrem NewPrem',
394394
compile-ty L1 L2 ProofHd IsPositive ITy ProofArgsR [NewPrem' | PremR] Clause.

apps/tc/elpi/link.elpi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace tc {
8383
:index (_ 1)
8484
pred occurs-rigidly i:term, i:term.
8585
occurs-rigidly N N :- name N, !.
86-
occurs-rigidly _ (uvar _) :- !, fail.
86+
occurs-rigidly _ uvar :- !, fail.
8787
occurs-rigidly N (app A) :- exists! A (occurs-rigidly N).
8888
occurs-rigidly N (fun _ _ B) :- pi x\ occurs-rigidly N (B x).
8989

@@ -127,10 +127,10 @@ namespace tc {
127127
rule solve-eta \ (eta A B _) <=> (unify-eta A B).
128128
rule \ solve-eta.
129129
% If two eta links have same lhs they rhs should unify
130-
rule (N1 : G1 ?- eta (uvar X L1) (fun _ T1 B1) _)
131-
\ (N2 : G2 ?- eta (uvar X L2) (fun _ T2 B2) _)
130+
rule (N1 :> G1 ?- eta (uvar X L1) (fun _ T1 B1) _)
131+
\ (N2 :> G2 ?- eta (uvar X L2) (fun _ T2 B2) _)
132132
| (pi x\ relocate L1 L2 (B2 x) (B2' x))
133-
<=> (N1 : G1 ?- B1 = B2').
133+
<=> (N1 :> G1 ?- B1 = B2').
134134
}
135135

136136
:index (0 1)
@@ -139,7 +139,7 @@ namespace tc {
139139
eta A (fun _ _ B as T) _ :- not (var A), not (var B), !, unify-left-right A T.
140140
eta A (fun _ _ B as T) _ :- not (var (B _)), progress-eta-right? T T', !, A = T'.
141141
eta A B _ :- not (var A), !, progress-eta-left A B.
142-
eta (uvar _ as A) B Vars :-
142+
eta (uvar as A) B Vars :-
143143
scope-check A B, std.filter Vars (x\ var x) Vars',
144144
declare_constraint (eta A B Vars') [_,A|Vars'].
145145
}
@@ -154,7 +154,7 @@ namespace tc {
154154
% app[A' x, t] instead of (A' x t).
155155
pred llam i:term, i:term.
156156
llam A (uvar _ S as T) :- distinct_names S, !, A = T.
157-
llam (uvar _ as A) (app [(uvar HD _)|_] as T) :- !,
157+
llam (uvar as A) (app [(uvar as HD)|_] as T) :- !,
158158
declare_constraint (llam A T) [_,A,HD].
159159
llam (fun _ _ _ as F) (app [(uvar _ Scope as H) | TL]) :- !,
160160
std.drop-last 1 TL TL',
@@ -168,10 +168,10 @@ namespace tc {
168168
rule solve-llam \ (llam A B) <=> (A = B).
169169
rule \ solve-llam.
170170
% If two llam links have same lhs they rhs should unify
171-
rule (N1 : G1 ?- llam (uvar X L1) T1)
172-
\ (N2 : G2 ?- llam (uvar X L2) T2)
171+
rule (N1 :> G1 ?- llam (uvar X L1) T1)
172+
\ (N2 :> G2 ?- llam (uvar X L2) T2)
173173
| (pi x\ relocate L1 L2 T2 T2')
174-
<=> (N1 : G1 ?- T1 = T2'). % TODO: instead of elpi unif, should use heuristics...
174+
<=> (N1 :> G1 ?- T1 = T2'). % TODO: instead of elpi unif, should use heuristics...
175175
}
176176
}
177177

@@ -184,19 +184,19 @@ namespace tc {
184184
coq.unify-eq T Record Err, Err = ok,
185185
Q = [coq.redflags.const Proj],
186186
coq.redflags.add coq.redflags.nored [coq.redflags.delta, coq.redflags.beta, coq.redflags.match | Q] RF,
187-
@redflags! RF => coq.reduction.lazy.whd (app [ProjT, Record]) V',
187+
(@redflags! RF => coq.reduction.lazy.whd (app [ProjT, Record]) V'),
188188
not (V' = match _ _ _), !,
189189
cs V V'.
190190
reduce-cs V T _ _ :- V = T.
191191

192192
pred cs i:term, i:term.
193193
cs T1 T2 :- not (var T1), !, coq.unify-eq T1 T2 ok.
194-
cs (uvar _ as V) (app [_, Arg] as T) :- not (ground_term Arg), !, get-vars T Vars, declare_constraint (cs V T) [_, V | Vars].
195-
cs (uvar _ as V) (app [HD, _Arg] as T) :-
194+
cs (uvar as V) (app [_, Arg] as T) :- not (ground_term Arg), !, get-vars T Vars, declare_constraint (cs V T) [_, V | Vars].
195+
cs (uvar as V) (app [HD, _Arg] as T) :-
196196
tc.coercion-unify HD, !,
197197
get-vars T Vars, declare_constraint (cs V T) [_, V | Vars].
198198

199-
cs (uvar _ as V) (app [HD | TL] as T) :-
199+
cs (uvar as V) (app [HD | TL] as T) :-
200200
if (HD = global (const Proj), tc.proj->record Proj Record)
201201
(reduce-cs V T Record Proj)
202202
% Note: Below we cannot unify V and T since T may contain

apps/tc/src/rocq_elpi_tc_register.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let gref2elpi_term (gref: GlobRef.t) : Cmd.raw =
2323
let observer_class (x : Typeclasses.typeclass) : Rocq_elpi_arg_HOAS.Cmd.raw list =
2424
[Cmd.String "new_class"; gref2elpi_term x.cl_impl]
2525

26-
let observer_coercion add (x : Typeclasses.typeclass) : Coq_elpi_arg_HOAS.Cmd.raw list =
26+
let observer_coercion add (x : Typeclasses.typeclass) : Rocq_elpi_arg_HOAS.Cmd.raw list =
2727
let name2str x = Cmd.String (Names.Name.print x |> Pp.string_of_ppcmds) in
2828
let proj = x.cl_projs |> List.map (fun (x: Typeclasses.class_method) -> x.meth_name) in
2929
let mode = if add then "add_coercions" else "remove_coercions" in

apps/tc/tests/importOrder/sameOrderCommand.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Elpi Accumulate Db tc_options.db.
1414
Elpi Accumulate File base.
1515
Elpi Accumulate File tc_aux.
1616
Elpi Accumulate File unif.
17-
Elpi Accumulate File link.
1817
Elpi Accumulate File compile_goal.
18+
Elpi Accumulate File link.
1919
Elpi Accumulate File tc_same_order.
2020

2121

apps/tc/tests/test.v

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Module HO_swap.
119119
Axiom (f : Type -> Type -> Type).
120120
Elpi Query TC.Solver lp:{{
121121
tc.link.eta.maybe-eta (fun `x` _ c0 \ fun `y` _ c1 \ A2 c1 c0),
122-
tc.link.eta.maybe-eta (fun `x` _ c0 \ fun `y` _ c1 \ A2 (A c1) c0),
122+
tc.link.eta.maybe-eta (fun `x` _ c0 \ fun `y` _ c1 \ A2 (A_ c1) c0),
123123
tc.link.eta.maybe-eta {{fun x y => f x y}}.
124124
}}.
125125

@@ -129,7 +129,7 @@ Module HO_swap.
129129
Elpi Query TC.Solver lp:{{
130130
@pi-decl `x` {{Type -> Type}} f\ tc.precomp.instance.is-uvar f =>
131131
sigma T\
132-
tc.precomp.instance {{c1 (fun x y => lp:f y x)}} T N _ _,
132+
tc.precomp.instance {{c1 (fun x y => lp:f y x)}} T N_ _ _,
133133
std.assert! (T = app[{{c1}}, tc.maybe-eta-tm _ _]) "[TC] invalid precomp".
134134
}}.
135135

@@ -204,7 +204,7 @@ Module HO_7.
204204
Qed.
205205
End HO_7.
206206

207-
Module HO_81.
207+
(* Module HO_81.
208208
Class c1 (T : Type).
209209
Instance i1 F : c1 F. Qed.
210210
@@ -223,11 +223,9 @@ Module HO_81.
223223
(* Failure is good, since here we simply check that the number of
224224
uvar-pair built by tc.precomp is zero. This is because the type
225225
of ?X is Type (i.e. it has `arity` zero) *)
226-
apply _.
227-
Unshelve.
228-
apply nat.
229-
Qed.
230-
End HO_81.
226+
Fail apply _.
227+
Abort.
228+
End HO_81. *)
231229

232230
Module HO_8.
233231
Class c1 (T : Type -> Type -> Type).
@@ -249,7 +247,7 @@ Module HO_9.
249247

250248
Elpi Query TC.Solver lp:{{
251249
pi F\ sigma T\ decl F `x` {{Type -> Type}} ==> tc.precomp.instance.is-uvar F ==>
252-
tc.precomp.instance {{c1 (fun x => f (lp:F x) (lp:F x))}} T N _ _,
250+
tc.precomp.instance {{c1 (fun x => f (lp:F x) (lp:F x))}} T _N _ _,
253251
std.assert! (T = app [{{c1}}, tc.maybe-eta-tm _ _]) "Invalid precompilation".
254252
}}.
255253

@@ -293,13 +291,6 @@ Module HO_12.
293291
Instance i : Unit (forall x, x) := {}.
294292
Set Printing Existential Instances.
295293

296-
Elpi Accumulate TC.Solver lp:{{
297-
% TODO: this rule should be removed if https://github.com/LPCIC/elpi/issues/256
298-
% is solved
299-
tc-elpi.apps.tc.tests.test.HO_12.tc-Unit {{forall (x:Prop), lp:(X x)}} {{i}} :-
300-
X = (x\x).
301-
}}.
302-
303294
Goal forall (y: Prop), exists (F: Prop -> Prop), Unit (forall x, F x).
304295
intros.
305296
eexists ?[F].
@@ -328,7 +319,7 @@ Module HO_13.
328319
Qed.
329320

330321
Elpi Query TC.Solver lp:{{
331-
std.spy-do![Goal = {{Unit (forall x y, lp:(F x y))}},
322+
std.spy-do![Goal = {{Unit (forall x y, lp:(F_ x y))}},
332323
tc.build-query-from-goal Goal Proof Q PP,
333324
do PP, Q,
334325
std.assert! (Proof = {{i f j}}) "Error"].
@@ -396,7 +387,7 @@ Module Llam_1.
396387
@pi-decl `x` {{Type -> Type}} f\ tc.precomp.instance.is-uvar f =>
397388
@pi-decl `x` {{Type -> Type}} g\ tc.precomp.instance.is-uvar g =>
398389
sigma T\
399-
tc.precomp.instance {{A (fun x => lp:f (lp:g x))}} T N _ _,
390+
tc.precomp.instance {{A (fun x => lp:f (lp:g x))}} T _N _ _,
400391
std.assert! (T = app[{{A}}, tc.maybe-eta-tm (fun _ _ (x\ tc.maybe-llam-tm _ _)) _]) "[TC] invalid precomp".
401392
}}.
402393

@@ -512,12 +503,12 @@ Module CoqUvar.
512503
Class c1 (i:Type -> Type -> Type).
513504

514505
Elpi Query TC.Solver lp:{{
515-
tc.precomp.instance {{c1 (fun x y => lp:F y x)}} T _ _ _,
506+
tc.precomp.instance {{c1 (fun x y => lp:F_ y x)}} T _ _ _,
516507
coq.say T,
517508
Expected = app[{{c1}}, tc.maybe-eta-tm (fun _ _ Inn) []],
518509
std.assert! (T = Expected) "[TC] invalid precompile1",
519510
pi x\ sigma ExpectedInn\
520-
ExpectedInn = tc.maybe-eta-tm (A x) [x],
511+
ExpectedInn = tc.maybe-eta-tm (A_ x) [x],
521512
std.assert! ((Inn x) = ExpectedInn) "[TC] invalid precompile2".
522513
}}.
523514

@@ -603,10 +594,10 @@ Module CoqUvar4.
603594
Class c1 (T : Type -> Type -> Type).
604595

605596
Elpi Query TC.Solver lp:{{
606-
tc.precomp.instance {{c1 (fun x y => lp:X (lp:A x y) y)}} C _ _ _,
597+
tc.precomp.instance {{c1 (fun x y => lp:X (lp:A_ x y) y)}} C _ _ _,
607598
Expected = app [{{c1}}, tc.maybe-eta-tm (fun _ _ Body1) _],
608599
Body1 = (x\ tc.maybe-eta-tm (fun _ _ (Body2 x)) [x]),
609-
Body2 = (x\y\ app [X, (Y x y), y]),
600+
Body2 = (x\y\ app [X, (Y_ x y), y]),
610601
std.assert! (C = Expected) "[TC] invalid compilation".
611602
}}.
612603

apps/tc/theories/add_commands.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ From elpi.apps.tc.elpi Extra Dependency "compile_goal.elpi" as compile_goal.
1010
From elpi.apps.tc.elpi Extra Dependency "unif.elpi" as unif.
1111
From elpi.apps.tc.elpi Extra Dependency "modes.elpi" as modes.
1212
From elpi.apps.tc.elpi Extra Dependency "link.elpi" as link.
13+
From elpi.apps.tc.elpi Extra Dependency "base.elpi" as base.
1314
From elpi.apps.tc.elpi Extra Dependency "parser_addInstances.elpi" as parser_addInstances.
1415
From elpi.apps.tc.elpi Extra Dependency "solver.elpi" as solver.
1516
From elpi.apps.tc.elpi Extra Dependency "create_tc_predicate.elpi" as create_tc_predicate.
@@ -20,8 +21,8 @@ Elpi Command TC.AddAllInstances.
2021
Elpi Accumulate Db tc.db.
2122
Elpi Accumulate Db tc_options.db.
2223
Elpi Accumulate File base tc_aux.
23-
Elpi Accumulate File unif modes link.
2424
Elpi Accumulate File compile_instance compiler compile_goal.
25+
Elpi Accumulate File unif modes link.
2526
Elpi Accumulate lp:{{
2627
main L :-
2728
args->str-list L L1,
@@ -33,8 +34,8 @@ Elpi Command TC.AddInstances.
3334
Elpi Accumulate Db tc.db.
3435
Elpi Accumulate Db tc_options.db.
3536
Elpi Accumulate File base tc_aux.
36-
Elpi Accumulate File unif modes link.
3737
Elpi Accumulate File compile_instance compiler compile_goal.
38+
Elpi Accumulate File unif modes link.
3839
Elpi Accumulate File parser_addInstances.
3940
Elpi Accumulate lp:{{
4041
main Arguments :-
@@ -155,7 +156,6 @@ Elpi Accumulate lp:{{
155156
main [trm T1, trm T2, int N] :- !, tc.add_tc.records_unif T1 T2 N.
156157
main L :- coq.error L.
157158
}}.
158-
Elpi Typecheck.
159159

160160
Elpi Export TC.AddAllClasses.
161161
Elpi Export TC.AddRecordFields.

apps/tc/theories/db.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ Elpi Db tc.db lp:{{
101101
pred ho-link o:term, i:term, o:A.
102102
pred link.eta i:term, i:term.
103103
pred link.llam i:term, i:term.
104-
104+
pred link.cs i:term, i:term.
105+
pred link.build-eta-llam-links i:term, i:list prop, o:term, o:list prop.
105106

106107
% relates a projection to the its record type fully applied to fresh
107108
% variables, eg, rules have the shape: (pi P1 ... PN\ proj->record {{p}} {{r P1 .. PN}})

apps/tc/theories/tc.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ From elpi.apps.tc.elpi Extra Dependency "modes.elpi" as modes.
99
From elpi.apps.tc.elpi Extra Dependency "unif.elpi" as unif.
1010

1111
From elpi.apps.tc.elpi Extra Dependency "link.elpi" as link.
12+
From elpi.apps.tc.elpi Extra Dependency "base.elpi" as base.
1213
From elpi.apps.tc.elpi Extra Dependency "compiler.elpi" as compiler.
1314
From elpi.apps.tc.elpi Extra Dependency "compile_goal.elpi" as compile_goal.
1415
From elpi.apps.tc.elpi Extra Dependency "compile_instance.elpi" as compile_instance.

builtin-doc/coq-builtin.elpi

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,11 @@ external pred coq.env.projection? i:constant, o:int.
934934
external pred coq.env.primitive-projections i:inductive,
935935
o:list (option (pair projection int)).
936936

937-
% [coq.env.primitive-projection? Projection Compatibility constant] relates
938-
% a projection to its compatibility constant.
939-
external pred coq.env.primitive-projection? i:projection, o:constant.
937+
% [coq.env.primitive-projection? Projection Compatibility constant Index]
938+
% Relates a primitive projection to its compatibility constant. Index is set
939+
% to the constructor argument extracted by the projection (starting from 0).
940+
external pred coq.env.primitive-projection? o:projection, o:constant,
941+
o:int.
940942

941943
% -- Sorts (and their universe level, if applicable) ----------------
942944

@@ -1178,6 +1180,10 @@ external pred coq.CS.db o:list cs-instance.
11781180
% or canonical Value, or both
11791181
external pred coq.CS.db-for i:gref, i:cs-pattern, o:list cs-instance.
11801182

1183+
% [coq.CS.canonical-projection? Projection] Tells if the projection can be
1184+
% used for CS inference.
1185+
external pred coq.CS.canonical-projection? i:constant.
1186+
11811187
% [coq.TC.declare-class GR] Declare GR as a type class
11821188
external pred coq.TC.declare-class i:gref.
11831189

@@ -1372,13 +1378,6 @@ external pred coq.arguments.simplification i:gref,
13721378
external pred coq.arguments.set-simplification i:gref,
13731379
i:simplification_strategy.
13741380

1375-
% [coq.arguments.reset-simplification GR] resets the behavior of the
1376-
% simplification tactics.
1377-
% Also resets the ! and / modifiers for the Arguments command.
1378-
% Supported attributes:
1379-
% - @global! (default: false)
1380-
external pred coq.arguments.reset-simplification i:gref.
1381-
13821381
% [coq.locate-abbreviation Name Abbreviation] locates an abbreviation. It's
13831382
% a fatal error if Name cannot be located.
13841383
external pred coq.locate-abbreviation i:id, o:abbreviation.

0 commit comments

Comments
 (0)