Skip to content

Commit 3895594

Browse files
authored
Merge branch 'master' into tracer
2 parents 882a602 + c114619 commit 3895594

File tree

103 files changed

+2408
-1613
lines changed

Some content is hidden

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

103 files changed

+2408
-1613
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
if: runner.os == 'Windows'
125125
run: |
126126
opam exec -- ls -l tests/sources/*.elpi
127-
opam exec -- make tests PWD=${{ env.workspace }} RUNNERS='dune ${{ env.workspace }}/elpi-${{ matrix.ocaml-compiler }}-${{ runner.os }}.exe ${{ env.workspace }}/elpi-trace-elaborator-${{ matrix.ocaml-compiler }}-${{ runner.os }}.exe' TIME=--time=D:/cygwin/bin/time.exe
127+
opam exec -- make tests PWD=${{ env.workspace }} RUNNERS='dune ${{ env.workspace }}/elpi-${{ matrix.ocaml-compiler }}-${{ runner.os }}.exe ${{ env.workspace }}/elpi-trace-elaborator-${{ matrix.ocaml-compiler }}-${{ runner.os }}.exe' TIME=--time=C:/cygwin/bin/time.exe
128128
129129
# Artifacts 2 ################################################################
130130

.github/workflows/users.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
env:
3131
OPAMWITHTEST: false
3232

33-
- run: opam pin --ignore-constraints-on elpi add rocq-elpi https://github.com/LPCIC/coq-elpi.git#fix-elpi-3.0
34-
- run: opam pin --ignore-constraints-on elpi add coq-elpi https://github.com/LPCIC/coq-elpi.git#fix-elpi-3.0
33+
- run: opam pin --ignore-constraints-on elpi add rocq-elpi https://github.com/LPCIC/coq-elpi.git#master
34+
- run: opam pin --ignore-constraints-on elpi add coq-elpi https://github.com/LPCIC/coq-elpi.git#master
3535
- run: opam pin --ignore-constraints-on elpi add rocq-stdlib https://github.com/rocq-prover/stdlib.git#master
36-
- run: opam pin --ignore-constraints-on elpi add rocq-hierarchy-builder https://github.com/gares/hierarchy-builder.git#elpi-3.0
36+
- run: opam pin --ignore-constraints-on elpi add rocq-hierarchy-builder https://github.com/math-comp/hierarchy-builder.git#master
3737
- run: opam pin --ignore-constraints-on elpi add rocq-mathcomp-boot https://github.com/math-comp/math-comp.git#master
3838
- run: opam pin --ignore-constraints-on elpi add rocq-mathcomp-order https://github.com/math-comp/math-comp.git#master
3939
- run: opam pin --ignore-constraints-on elpi add rocq-mathcomp-fingroup https://github.com/math-comp/math-comp.git#master

CHANGES.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,71 @@
1+
# v3.4.2 (October 2025)
2+
3+
Requires Menhir 20211230 and OCaml 4.13 or above.
4+
5+
- Runtime:
6+
- Fix bug concerning CHR rules firing on non-fully-dereffed terms
7+
8+
# v3.4.1 (September 2025)
9+
10+
Requires Menhir 20211230 and OCaml 4.13 or above.
11+
12+
- Compiler:
13+
- Fix extend_signature, was not updating the symbol table
14+
15+
# v3.4.0 (September 2025)
16+
17+
- Parser:
18+
- New `->`-based syntax for `pred`, analogous to the new `func` one. E.g.
19+
```
20+
func append list A, list A -> list A.
21+
pred appendR -> list A, list A, list A.
22+
```
23+
24+
- Compiler:
25+
- Fix `=!=>` that was adding a head cut, rather than a tail cut, in some
26+
cases
27+
- Fix compilation bug concerning `Loc.t` being erroneously compared
28+
29+
# v3.3.1 (September 2025)
30+
31+
Requires Menhir 20211230 and OCaml 4.13 or above.
32+
33+
- Tests:
34+
- compare json files semantically
35+
36+
# v3.3.0 (September 2025)
37+
38+
Requires Menhir 20211230 and OCaml 4.13 or above.
39+
40+
- Tooling:
41+
- port to ppxlib 0.36.0
42+
43+
# v3.2.0 (September 2025)
44+
45+
Requires Menhir 20211230 and OCaml 4.13 or above.
46+
47+
- Language:
48+
- Remove: the `fprop` sort, use `(func)` instead
49+
50+
# v3.1.0 (August 2025)
51+
52+
Requires Menhir 20211230 and OCaml 4.13 or above.
53+
54+
- Language:
55+
- Change: constraints must be functions. Hence `declare_constraint` only
56+
suspends functional predicated and CHR rules can only generate
57+
determinitic goals.
58+
- New: the `func` syntax now supports variadic functions as in
59+
```prolog
60+
func f int, int -> int.. .
61+
f N D Q :- Q is N div D.
62+
f N D Q R :- f N D Q, R is N mod D.
63+
```
64+
165
# v3.0.1 (July 2025)
266
67+
Requires Menhir 20211230 and OCaml 4.13 or above.
68+
369
- Language:
470
- Improve error message for non deterministic atom
571
- Fix overlap check for `uvar F L as X`

ELPI.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ is very welcome. Questions or feature requests are welcome as well.
5555
- [Accumulate with paths](#accumulate-with-paths) accepts `accumulate "path".`
5656
so that one can use `.` in a file/path name.
5757

58+
- [Variadic functions](#variadic-functions)
59+
5860
- [Tracing facility](#tracing-facility) to debug your programs.
5961

6062
- [Macros](#macros) are expanded at compilation time
@@ -662,10 +664,10 @@ goal> pi x\ sigma Y\ even x => (declare_constraint (even Y) [Y], Y = x).
662664
Success:
663665
```
664666

665-
The `declare_constraint` built in is typically used in conjunction with `mode`
666-
as follows:
667+
The `declare_constraint` built requires functions, and is typically
668+
used as follows:
667669
```prolog
668-
mode (even i).
670+
func even int -> .
669671
even (uvar as X) :- !, declare_constraint (even X) [X].
670672
even 0.
671673
even X :- X > 1, Y is X - 2, even Y.
@@ -751,8 +753,8 @@ It is used only in debug output.
751753

752754
#### Example
753755
```prolog
754-
mode (odd i).
755-
mode (even i).
756+
func odd int -> .
757+
func even int -> .
756758
757759
even (uvar as X) :- !, declare_constraint (even X) [X].
758760
odd (uvar as X) :- !, declare_constraint (odd X) [X].
@@ -801,7 +803,7 @@ we can compute GCDs of 2 sets of numbers: 99, 66 and 22 named X;
801803
14 and 77 called Y.
802804

803805
```prolog
804-
mode (gcd i i).
806+
func gcd int ,int -> .
805807
806808
gcd A (uvar as Group) :- declare_constraint (gcd A Group) Group.
807809
@@ -825,7 +827,7 @@ Constraints are resumed as regular delayed goals are.
825827
#### Example of higher order rules
826828

827829
```prolog
828-
mode (term i o).
830+
func term tm -> ty.
829831
term (app HD ARG) TGT :- term HD (arrow SRC TGT), term ARG SRC.
830832
term (lam F) (arrow SRC TGT) :- pi x\ term x SRC => term (F x) TGT.
831833
term (uvar as X) T :- declare_constraint (term X T) [X].
@@ -1033,6 +1035,21 @@ Here `main` calls `std.list.map`, `std.string.concat` and finally
10331035
Elpi accepts `accumulate "path".` (i.e. a string rather than an indent)
10341036
so that one can use `.` in a file or path name.
10351037

1038+
## Variadic functions
1039+
1040+
Functions, both external and written in Elpi, can be variadic.
1041+
1042+
```prolog
1043+
func f int, int -> int.. .
1044+
f N D Q :- Q is N div D.
1045+
f N D Q R :- f N D Q, R is N mod D.
1046+
```
1047+
1048+
Here `f` takes 3 or 4 argument: when 4 are passed it also returns the
1049+
reminder of the division. Only the last output can be variadic.
1050+
1051+
This feature is mainly used for external functions.
1052+
10361053
## Tracing facility
10371054

10381055
Elpi comes with a tracing facility. The feature was designed to debug

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(lang dune 2.8)
1+
(lang dune 2.9)
22
(name elpi)
33
(using menhir 2.0)

elpi.opam

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ bug-reports: "https://github.com/LPCIC/elpi/issues"
1010
build: [
1111
["dune" "subst"] {dev}
1212
["dune" "build" "-p" name "-j" jobs]
13-
[make "tests" "DUNE_OPTS=-p %{name}%" "SKIP=performance_HO" "SKIP+=performance_FO" "SKIP+=elpi_api_performance"] {with-test & os != "macos" & os-distribution != "alpine" & os-distribution != "freebsd"}
13+
[make "tests" "DUNE_OPTS=-p %{name}%" "SKIP=performance_HO" "SKIP+=performance_FO" "SKIP+=elpi_api_performance"] {with-test & os != "macos" & os-distribution != "alpine" & os-distribution != "freebsd" & arch != "arm32" & arch != "x86_32"}
1414
]
1515
x-maintenance-intent: ["(latest)"]
1616
depends: [
1717
"ocaml" {>= "4.13.0" }
1818
"stdlib-shims"
19-
"ppxlib" {>= "0.12.0" & < "0.36.0"}
19+
"ppxlib" {>= "0.12.0"}
20+
"ppx_optcomp"
2021
"menhir" {>= "20211230" }
2122
"re" {>= "1.7.2"}
2223
"ppx_deriving" {>= "4.3"}
2324
"ANSITerminal" {with-test}
24-
"cmdliner" {with-test}
25+
"cmdliner" {with-test & < "2.0"}
2526
"fileutils" {with-test}
26-
"dune" {>= "2.8.0"}
27+
"yojson" {with-test}
28+
"dune" {>= "2.9.0"}
2729
"conf-time" {with-test}
2830
"atdgen" {>= "2.10.0"}
2931
"atdts" {>= "2.10.0"}

src/API.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ end
518518

519519
module Elpi = struct
520520

521-
type t = ED.uvar_body
521+
type t = ED.uvar
522522

523523
let pp = Compiler.pp_uvar_body
524524
let show m = Format.asprintf "%a" pp m
@@ -535,7 +535,7 @@ module Elpi = struct
535535

536536
let alloc_Elpi name state =
537537
let module R = (val !r) in
538-
state, (ED.oref ED.dummy)
538+
state, (ED.oref ~depth:0 ED.dummy)
539539

540540
let make ?name state =
541541
match name with
@@ -577,11 +577,11 @@ module RawData = struct
577577
let module R = (val !r) in let open R in
578578
match deref_head ~depth t with
579579
| ED.Term.Arg _ | ED.Term.AppArg _ -> assert false
580-
| ED.Term.AppUVar(ub,0,args) -> UnifVar (ub,args)
581-
| ED.Term.AppUVar(ub,lvl,args) -> look ~depth (R.expand_appuv ub ~depth ~lvl ~args)
582-
| ED.Term.UVar(ub,lvl,ano) -> look ~depth (R.expand_uv ub ~depth ~lvl ~ano)
580+
| ED.Term.AppUVar(ub,args) when ub.vardepth == 0 -> UnifVar (ub,args)
581+
| ED.Term.AppUVar(ub,args) -> look ~depth (R.expand_appuv ub ~depth ~args)
582+
| ED.Term.UVar(ub,ano) -> look ~depth (R.expand_uv ub ~depth ~ano)
583583
| ED.Term.Discard ->
584-
let ub = ED.oref ED.dummy in
584+
let ub = ED.oref ~depth:0 ED.dummy in
585585
UnifVar (ub,R.mkinterval 0 depth 0)
586586
| ED.Term.Lam _ as t ->
587587
begin match R.eta_contract_flex ~depth t with
@@ -591,7 +591,7 @@ module RawData = struct
591591
| x -> Obj.magic x (* HACK: view is a "subtype" of Term.term *)
592592

593593
let kool = function
594-
| UnifVar(ub,args) -> ED.Term.AppUVar(ub,0,args)
594+
| UnifVar(ub,args) -> ED.Term.AppUVar(ub,args)
595595
| x -> Obj.magic x
596596
[@@ inline]
597597

@@ -680,7 +680,8 @@ module RawData = struct
680680
let no_constraints = []
681681

682682
let mkUnifVar ub ~args state =
683-
ED.Term.mkAppUVar ub 0 args
683+
if args = [] then ED.Term.mkUVar ub 0
684+
else ED.Term.mkAppUVar ub args
684685

685686
type Conversion.extra_goal +=
686687
| RawGoal = ED.Conversion.RawGoal
@@ -905,7 +906,7 @@ module BuiltInPredicate = struct
905906

906907
let beta ~depth t args =
907908
let module R = (val !r) in let open R in
908-
deref_appuv ~from:depth ~to_:depth ?avoid:None args t
909+
deref_apparg ~from:depth ~to_:depth ?avoid:None t args
909910

910911
module HOAdaptors = struct
911912

@@ -915,7 +916,7 @@ module BuiltInPredicate = struct
915916
type ('a,'b,'c) pred3 = Data.term * 'a Conversion.t * 'b Conversion.t * 'c Conversion.t
916917
type ('a,'b) pred3a = Data.term * 'a Conversion.t * 'b Conversion.t
917918

918-
let pred1_ty x = Conversion.TyApp("->",x.Conversion.ty,[Conversion.TyName"prop"])
919+
let pred1_ty x = Conversion.TyApp("->",x.Conversion.ty,[Conversion.TyName"(func)"])
919920
let pred1 x = { Conversion.ty = pred1_ty x; readback = (fun ~depth state e -> state,(e,x),[]); embed = (fun ~depth state (x,_) -> state,x,[]); pp = (fun fmt (x,_) -> Format.fprintf fmt "<pred1>"); pp_doc = (fun fmt () -> ()) }
920921
let pred2_ty x y = Conversion.(TyApp("->",x.Conversion.ty,[TyApp("->",y.Conversion.ty,[Conversion.TyName"prop"])]))
921922
let pred2 x y = { Conversion.ty = pred2_ty x y; readback = (fun ~depth state e -> state,(e,x,y),[]); embed = (fun ~depth state (x,_,_) -> state,x,[]); pp = (fun fmt (x,_,_) -> Format.fprintf fmt "<pred2>"); pp_doc = (fun fmt () -> ()) }

src/API.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,8 @@ module RawData : sig
11701170
| UnifVar of FlexibleData.Elpi.t * term list
11711171

11721172
(** Terms must be inspected after dereferencing their head.
1173-
If the resulting term is UVar then its uvar_body is such that
1174-
get_assignment uvar_body = None *)
1173+
If the resulting term is UVar then its uvar is such that
1174+
get_assignment uvar = None *)
11751175
val look : depth:int -> term -> view
11761176

11771177
(* to reuse a term that was looked at *)

0 commit comments

Comments
 (0)