Skip to content

Commit eef191f

Browse files
authored
Merge pull request #527 from gares/elpi-3.0
port to elpi 3.0
2 parents 0d929ab + 4edff0a commit eef191f

20 files changed

+849
-691
lines changed

HB/about.elpi

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
namespace about {
55

6-
pred main i:string.
6+
func main string ->.
77
main S :-
88
coq.locate-all S All,
9-
std.filter All (x\sigma gr a\x = loc-gref gr ; x = loc-abbreviation a) L,
9+
std.filter All (x\sigma gr a\ std.once (x = loc-gref gr ; x = loc-abbreviation a)) L,
1010
if (L = []) (coq.error "HB: unable to locate" S) true,
1111
std.forall L (about.main-located S).
1212

13-
pred main-located i:string, i:located.
13+
func main-located string, located ->.
1414
main-located S (loc-gref GR) :- class-def (class Class GR MLwP), !,
1515
private.main-structure S Class GR MLwP.
1616

@@ -20,10 +20,10 @@ main-located _ (loc-gref Class) :- class-def (class Class GR MLwP), !,
2020
S is M ^ "." ^ St,
2121
private.main-structure S Class GR MLwP.
2222

23-
main-located S (loc-gref (indt I)) :- factory-constructor (indt I) _, !,
23+
main-located S (loc-gref (indt I)) :- factory->constructor (indt I) _, !,
2424
private.main-factory S I.
2525

26-
main-located S (loc-gref (const C)) :- factory-constructor (const C) _, !,
26+
main-located S (loc-gref (const C)) :- factory->constructor (const C) _, !,
2727
private.main-factory-alias S C.
2828

2929
main-located S (loc-gref (const C)) :- exported-op M _ C, !,
@@ -32,8 +32,8 @@ main-located S (loc-gref (const C)) :- exported-op M _ C, !,
3232
main-located S (loc-gref GR) :- factory-alias->gref GR F ok, not (F = GR), !,
3333
main-located S (loc-gref F).
3434

35-
main-located S (loc-abbreviation A) :- phant-abbrev GR PhB A, factory-constructor (indt F) GR, !,
36-
private.main-factory-constructor S F PhB GR.
35+
main-located S (loc-abbreviation A) :- phant-abbrev GR PhB A, factory->constructor (indt F) GR, !,
36+
private.main-factory->constructor S F PhB GR.
3737

3838
main-located S (loc-abbreviation A) :-
3939
coq.notation.abbreviation-body A NArgs _,
@@ -61,23 +61,24 @@ main-located S (loc-abbreviation _) :- coq.error "HB: unknown abbreviation" S.
6161

6262
shorten coq.pp.{ v , h, hv, hov , spc , str , box , glue , brk , empty }.
6363

64-
pred bulletize1 i:(A -> coq.pp -> prop), i:A, o:coq.pp.
64+
func bulletize1 (func A -> coq.pp), A -> coq.pp.
6565
bulletize1 F X (glue [str "- ", M]) :- F X M.
6666

67-
pred bulletize i:list A, i:(A -> coq.pp -> prop), o:coq.pp.
68-
bulletize [] _ empty.
67+
% @gares
68+
func bulletize list A, (func A -> coq.pp) -> coq.pp.
69+
bulletize [] _ empty :- !.
6970
bulletize L F (glue [brk 0 0 | PLB]) :-
7071
std.map L (bulletize1 F) PL,
7172
std.intersperse (brk 0 0) PL PLB.
7273

7374
% Print shortest qualified identifier of the module containing a gref
74-
pred pp-module i:gref, o:coq.pp.
75+
func pp-module gref -> coq.pp.
7576
pp-module GR (str ID) :- gref->modname_short GR "." ID.
7677

77-
pred unif-hint? i:cs-instance.
78+
func unif-hint? cs-instance -> .
7879
unif-hint? (cs-instance _ (cs-gref GR) _) :- coq.CS.db-for GR _ [_|_].
7980

80-
pred not1 i:(A -> prop), i:A.
81+
func not1 (pred i:A), A.
8182
not1 P X :- not (P X).
8283

8384

@@ -89,12 +90,12 @@ namespace private {
8990

9091
shorten coq.pp.{ v , h, hv, hov , spc , str , box , glue , brk , empty }.
9192

92-
pred docstring-for-file i:string, o:prop.
93+
func docstring-for-file string -> prop.
9394
docstring-for-file Rex (docstring Loc Doc) :- docstring Loc Doc,
9495
loc.fields Loc File _ _ _ _,
95-
rex.match {calc(".*" ^ Rex)} File.
96+
rex.match {calc(".*" ^ Rex)} File, !.
9697

97-
pred main-canonical-value i:string, i:list cs-instance.
98+
func main-canonical-value string, list cs-instance ->.
9899
main-canonical-value S CanonicalValues :-
99100
group-by-loc CanonicalValues CanonicalValuesL,
100101
%format
@@ -105,29 +106,29 @@ main-canonical-value S CanonicalValues :-
105106
coq.say {coq.pp->string PpCanonicalValues},
106107
coq.say.
107108

108-
pred group-by-loc i:list cs-instance, o:list (pair (option loc) (list cs-instance)).
109+
func group-by-loc list cs-instance -> list (pair (option loc) (list cs-instance)).
109110
group-by-loc [] [].
110111
group-by-loc [cs-instance P V GR|L] [pr (some Loc) [cs-instance P V GR|SameLoc]|Rest1] :- decl-location GR Loc, !,
111112
std.partition L (x\ sigma GR1\ x = cs-instance _ _ GR1, decl-location GR1 Loc) SameLoc Rest,
112113
group-by-loc Rest Rest1.
113114
group-by-loc [I|Rest] [pr none [I]|Rest1] :- group-by-loc Rest Rest1.
114115

115-
pred pp-canonical-solution-list i:pair (option loc) (list cs-instance), o:coq.pp.
116+
func pp-canonical-solution-list pair (option loc) (list cs-instance) -> coq.pp.
116117
pp-canonical-solution-list (pr none [CS]) Pp :-
117118
pp-canonical-solution CS Pp.
118119
pp-canonical-solution-list (pr (some Loc) L) Pp :-
119120
Pp = box (v 0)
120121
{ std.append {std.intersperse spc {std.map L pp-canonical-solution}}
121122
[ spc, {pp-loc Loc} ] }.
122123

123-
pred pp-canonical-solution i:cs-instance, o:coq.pp.
124+
func pp-canonical-solution cs-instance -> coq.pp.
124125
pp-canonical-solution (cs-instance _Proj _Pat GR) Pp :-
125126
coq.env.typeof GR T,
126127
coq.prod-tgt->gref T F,
127128
if (class-def (class _ F _)) (gref->modname_short F "." ID) (coq.gref->string F ID),
128129
Pp = box (hov 0) [ str ID ].
129130

130-
pred main-canonical-projection i:string, i:gref, i:list cs-instance.
131+
func main-canonical-projection string, gref, list cs-instance.
131132
main-canonical-projection S Proj CanonicalProjectionValues :-
132133
%format
133134
PpCanonicalProjectionOrigin = box (hov 4) [
@@ -141,12 +142,12 @@ main-canonical-projection S Proj CanonicalProjectionValues :-
141142
coq.say {coq.pp->string PpCanonicalProjectionValues},
142143
coq.say.
143144

144-
pred pp-canonical-value i:cs-instance, o:coq.pp.
145+
func pp-canonical-value cs-instance -> coq.pp.
145146
pp-canonical-value (cs-instance _Proj (cs-gref GR) _Sol) Pp :-
146147
coq.term->pp (global GR) V,
147148
Pp = box (hov 2) [ V , spc, {pp-loc-of GR} ].
148149

149-
pred main-coercion i:string, i:list coercion.
150+
func main-coercion string, list coercion.
150151
main-coercion S [coercion GR _ Src Tgt|_] :-
151152
% format
152153
if (class-def (class _ Src _) ; class-def (class Src _ _))
@@ -166,11 +167,11 @@ main-coercion S [coercion GR _ Src Tgt|_] :-
166167
coq.say {coq.pp->string PpCoercionOrigin},
167168
coq.say.
168169

169-
pred main-operation i:string, i:mixinname, i:constant.
170+
func main-operation string, mixinname, constant -> .
170171
main-operation S MixinSource _ :-
171172
% fetch
172-
mixin-first-class MixinSource Class,
173-
class-def (class Class Structure _),
173+
mixin->first-class MixinSource Class,
174+
class-def (class Class Structure _), !,
174175
% format
175176
PpOriginStructure = box (hov 4) [
176177
str "HB:", spc, str S, spc, str "is an operation of structure", spc,
@@ -183,12 +184,12 @@ main-operation S MixinSource _ :-
183184
coq.say {coq.pp->string PpOriginMixin},
184185
coq.say.
185186

186-
pred main-structure i:string, i:classname, i:structure, i:mixins.
187+
func main-structure string, classname, structure, mixins.
187188
main-structure S Class Structure MLwP :-
188189
% fetch
189190
list-w-params_list MLwP ML,
190191
std.map-filter ML (m\r\ sigma P O OPS\
191-
mixin-first-class m Class,
192+
mixin->first-class m Class,
192193
std.findall (exported-op m P O) OPS,
193194
std.map OPS (c\out\ sigma p\ c = exported-op m p out) r) OPLL,
194195
std.flatten OPLL Operations,
@@ -206,7 +207,7 @@ main-structure S Class Structure MLwP :-
206207
PpClass = box (v 4) [
207208
str "HB: ", {pp-module Class}, str " is a factory for the following mixins:",
208209
{bulletize ML (m\r\ sigma tmp\
209-
if (mixin-first-class m Class)
210+
if (mixin->first-class m Class)
210211
(pp-module m tmp, r = glue [tmp, str " (* new, not from inheritance *)"])
211212
(pp-module m r))}],
212213
PpSubClasses = box (v 4) [
@@ -224,10 +225,10 @@ main-structure S Class Structure MLwP :-
224225
print-docstring Structure,
225226
coq.say.
226227

227-
pred main-factory-constructor i:string, i:inductive, i:gref, i:gref.
228-
main-factory-constructor S F PhBuild Build :-
228+
func main-factory->constructor string, inductive, gref, gref.
229+
main-factory->constructor S F PhBuild Build :-
229230
% fetch
230-
gref-deps Build DMLwP,
231+
gref->deps Build DMLwP,
231232
list-w-params_list DMLwP DML,
232233
factory-provides (indt F) PMLwP,
233234
list-w-params_list PMLwP PML,
@@ -263,14 +264,16 @@ main-factory-constructor S F PhBuild Build :-
263264
print-docstring Build,
264265
coq.say.
265266

266-
pred compute-arg-type i:list-w-params mixinname, i:list constant, i:list term, o:list id, o:id, o:list id, o:list (pair id coq.pp).
267+
func compute-arg-type list-w-params mixinname, list constant, list term -> list id, id, list id, list (pair id coq.pp).
267268
compute-arg-type (w-params.cons ID Ty Rest) F Acc [ID|PN] TN FN [pr ID PPTy |Xs] :-
268269
coq.term->pp Ty PPTy,
269270
@pi-parameter ID Ty x\ compute-arg-type (Rest x) F [x|Acc] PN TN FN Xs.
270271
compute-arg-type (w-params.nil ID Ty Rest) F Acc [] ID FN [pr ID PPTy|Xs] :-
271272
coq.term->pp Ty PPTy,
272273
@pi-parameter ID Ty x\ compute-arg-type.fields F {std.length (Rest x)} {std.rev [x|Acc]} Xs FN.
273-
pred compute-arg-type.fields i:list constant, i:int, i:list term, o:list (pair id coq.pp), o:list id.
274+
275+
:index(1)
276+
func compute-arg-type.fields list constant, int, list term -> list (pair id coq.pp), list id.
274277
compute-arg-type.fields [] _ _ [] [].
275278
compute-arg-type.fields [C|Cs] NDeps Args [pr ID PPTy|Xs] [ID|FN] :- exported-op _ C OP, !,
276279
coq.env.typeof (const OP) Ty,
@@ -291,15 +294,15 @@ compute-arg-type.fields [OP|Cs] NDeps Args [pr ID PPTy|Xs] [ID|FN] :-
291294
(@pplevel! 200 => coq.term->pp TyArgsDepsRecord PPTy),
292295
@pi-parameter ID TyArgsDepsRecord op\
293296
(pi L L1 X\
294-
copy (app[global(const OP)|L]) X :- std.drop ToDrop L L1, coq.mk-app op L1 X) =>
297+
copy (app[global(const OP)|L]) X :- std.drop ToDrop L L1, coq.mk-app op L1 X, !) =>
295298
compute-arg-type.fields Cs NDeps Args Xs FN.
296299

297-
pred main-factory i:string, i:inductive.
300+
func main-factory string, inductive.
298301
main-factory S Factory :-
299302
% fetch
300303
coq.env.projections Factory Ps,
301304
std.map-filter Ps (x\r\ x = some r) Fields,
302-
gref-deps (indt Factory) DMLwP,
305+
gref->deps (indt Factory) DMLwP,
303306
list-w-params_list DMLwP DML,
304307
factory-provides (indt Factory) PMLwP,
305308
list-w-params_list PMLwP PML,
@@ -324,16 +327,16 @@ main-factory S Factory :-
324327
print-docstring (indt Factory),
325328
coq.say.
326329

327-
pred main-factory-alias i:string, i:constant.
330+
func main-factory-alias string, constant.
328331
main-factory-alias S _Const :-
329332
coq.say "HB: todo HB.about for factory alias" S.
330333

331-
pred main-builder i:string, i:factoryname, i:mixinname.
334+
func main-builder string, factoryname, mixinname.
332335
main-builder _S From To :-
333336
coq.say "HB: todo HB.about for builder from"
334337
{gref->modname_short From "."} "to" {gref->modname_short To "."}.
335338

336-
pred compute-field-info.aux i:list id, i:list implicit_kind, o:list coq.pp.
339+
func compute-field-info.aux list id, list implicit_kind -> list coq.pp.
337340
compute-field-info.aux [] _ [].
338341
compute-field-info.aux [Name|NS] [explicit|IS] [str Name|PS] :-
339342
compute-field-info.aux NS IS PS.
@@ -343,48 +346,50 @@ compute-field-info.aux [Name|NS] [maximal|IS] [glue[str"{",str Name,str"}"]|PS]
343346
compute-field-info.aux NS IS PS.
344347
compute-field-info.aux [Name|NS] [] [str Name|PS] :-
345348
compute-field-info.aux NS [] PS.
346-
pred compute-field-info i:list id, i:list implicit_kind, o:list coq.pp.
349+
350+
func compute-field-info list id, list implicit_kind -> list coq.pp.
347351
compute-field-info Names Impls O :-
348352
compute-field-info.aux {std.rev Names} {std.rev Impls} Pp,
349353
std.intersperse spc {std.rev Pp} O.
350354

351-
pred pp-const i:constant, o:coq.pp.
355+
func pp-const constant -> coq.pp.
352356
pp-const F (str ID) :- coq.gref->id (const F) ID.
353357

354-
pred pp-arg-type i:pair id coq.pp, o:coq.pp.
358+
func pp-arg-type pair id coq.pp -> coq.pp.
355359
pp-arg-type (pr ID PPTy) (box (hov 2) [str ID, str" :", spc, PPTy]).
356360

357-
pred pp-if-verbose o:coq.pp, i:(coq.pp -> prop).
361+
:functional
362+
pred pp-if-verbose o:coq.pp, i:(func -> coq.pp).
358363
pp-if-verbose V P :- get-option "verbose" tt, !, P V.
359364
pp-if-verbose empty _.
360365

361-
pred pp-loc-of i:gref, o:coq.pp.
366+
func pp-loc-of gref -> coq.pp.
362367
pp-loc-of GR PP :- decl-location GR Loc, !, pp-loc Loc PP.
363368
pp-loc-of _ coq.pp.empty.
364369

365-
pred pp-loc i:loc, o:coq.pp.
370+
func pp-loc loc -> coq.pp.
366371
pp-loc Loc (coq.pp.glue PP) :-
367372
loc.fields Loc File _ _ Line _,
368373
QFile is "\"" ^ File ^ "\", line " ^ {std.any->string Line},
369374
PP = [str "(from ", str QFile, str")"].
370375

371-
pred docstring->pp i:string, o:coq.pp.
376+
func docstring->pp string -> coq.pp.
372377
docstring->pp Txt (glue Doc) :-
373378
rex.replace "\n" " " Txt PlainTxt,
374379
rex.split " " PlainTxt Words,
375380
std.filter Words (w\not (w = "")) NEWords,
376381
std.map NEWords (w\r\ r = str w) PpWords,
377382
std.intersperse spc PpWords Doc.
378383

379-
pred docstring-of i:gref, o:option coq.pp.
384+
func docstring-of gref -> option coq.pp.
380385
docstring-of GR (some Doc) :- decl-location GR Loc, docstring Loc Txt, !, docstring->pp Txt Doc.
381386
docstring-of _ none.
382387

383-
pred pp-docstring-of i:gref, o:coq.pp.
388+
func pp-docstring-of gref -> coq.pp.
384389
pp-docstring-of GR D :- docstring-of GR (some D), !.
385390
pp-docstring-of _ coq.pp.empty.
386391

387-
pred print-docstring i:gref.
392+
func print-docstring gref ->.
388393
print-docstring GR :-
389394
if (docstring-of GR (some Doc))
390395
(coq.say {coq.pp->string (box (hov 5) [str"Doc: ",Doc])})

0 commit comments

Comments
 (0)