Skip to content

Commit 2d729c7

Browse files
authored
Merge pull request #719 from LPCIC/elpi-2.0
port to Elpi 2.0
2 parents a7b9cfb + 4bbf233 commit 2d729c7

File tree

193 files changed

+2900
-2286
lines changed

Some content is hidden

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

193 files changed

+2900
-2286
lines changed

.nix/config.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let master = [
3232
coq.override.version = "8.20";
3333
};
3434
ocamlPackages = {
35-
elpi.override.version = "1.20.0";
35+
elpi.override.version = "v2.0.3";
3636
};
3737
};
3838

@@ -42,7 +42,7 @@ let master = [
4242
coqeal.job = false; # broken in master, c.f. https://github.com/coq/coq/pull/19228
4343
};
4444
ocamlPackages = {
45-
elpi.override.version = "1.20.0";
45+
elpi.override.version = "v2.0.3";
4646
};
4747
};
4848

@@ -54,7 +54,7 @@ let master = [
5454
ocamlPackages = {
5555
# when updating this, don't forget to update dune-project
5656
# then use it to regenerate coq-elpi.opam
57-
elpi.override.version = "1.18.2";
57+
elpi.override.version = "v2.0.3";
5858
};
5959
};
6060

Changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Development version
22

3+
### Vernacular
4+
- `Elpi Accumulate Db Header <db>` to accumulate just the `Db` declaration
5+
but no code added after that
6+
- `Elpi Typecheck` is deprecated and is a no-op since `Elpi Accumulate`
7+
performs type checking incrementally
8+
39
### Build system
410
- Support dune workspace build with `elpi`
511

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ dune = dune $(1) $(DUNE_$(1)_FLAGS)
22

33
all:
44
$(call dune,build)
5+
$(call dune,build) builtin-doc
56
.PHONY: all
67

78
build-core:
89
$(call dune,build) theories
10+
$(call dune,build) builtin-doc
911
.PHONY: build-core
1012

1113
build-apps:
@@ -14,6 +16,7 @@ build-apps:
1416

1517
build:
1618
$(call dune,build) -p coq-elpi @install
19+
$(call dune,build) builtin-doc
1720
.PHONY: build
1821

1922
test-core:
@@ -46,7 +49,7 @@ doc: build
4649
-R $(shell pwd)/_build/install/default/lib/coq/user-contrib/elpi_elpi elpi_elpi \
4750
-R $(shell pwd)/_build/install/default/lib/coq/user-contrib/elpi elpi \
4851
$(tut) &&) true
49-
@cp _build/default/examples/stlc.html doc/
52+
@cp ./_build/default/examples/stlc.txt doc/
5053
@cp etc/tracer.png doc/
5154

5255
clean:

README.md

+34-8
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,39 @@ In order to load Coq-Elpi use `From elpi Require Import elpi`.
182182
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands).
183183
- `Elpi Program <qname> <code>` lower level primitive letting one crate a
184184
command/tactic with a custom preamble `<code>`.
185-
- `From some.load.path Extra Dependency <filename> as <fname>`.
186-
- `Elpi Accumulate [<dbname>|<qname>] [<code>|File <fname>|Db <dbname>]`
185+
- `From some.load.path Extra Dependency <filename> as <fname>` declares `<fname>`
186+
as a piece of code that can be accumulated via `Elpi Accumulate File`.
187+
The content is given in the external file `<filename>` to be found in
188+
the Coq load path `some.load.path`.
189+
- `Elpi File <fname> <code>.` declares `<fname>`
190+
as a piece of code that can be accumulated via `Elpi Accumulate File`.
191+
This time the code is given in the .v file.
192+
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands).
193+
- `Elpi Accumulate [<dbname>|<qname>] [<code>|File [Signature] <fname>|Db [Header] <dbname>]`
187194
adds code to the current program (or `<dbname>` or `<qname>` if specified).
188195
The code can be verbatim, from a file or a Db.
189-
File names `<fname>` must have been previously declared with the above command.
196+
File names `<fname>` must have been previously declared with
197+
`Extra Dependency` or `Elpi File`.
198+
Accumulating `File Signature <fname>` only adds the signautre declarations
199+
(kinds, types, modes, type abbreviations) from `<fname>` skipping the code
200+
(clauses/rules).
201+
Accumulating `Db Header <dbname>`, instead of `Db <dbname>`, accumulates
202+
only the first chunk of code associated with Db, typically the type
203+
declaration of the predicates that live in the Db. When defining a command
204+
or tactic it can be useful to first accumulate the Db header, then some
205+
code (possibly calling the predicate living in the Db), and finally
206+
accumulating the (full) Db.
207+
Note that when a command is executed it may need to be (partially)
208+
recompiled, e.g. if the Db was updated. In this case all the code accumulated
209+
after the Db (but not after its header) may need to be recompiled. Hence
210+
we recommend to accumulate Dbs last.
190211
It understands the `#[skip="rex"]` and `#[only="rex"]` which make the command
191212
a no op if the Coq version is matched (or not) by the given regular expression.
192-
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
213+
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands).
214+
It understands the `#[local]`, `#[global]`, and `#[superglobal]` scope attributes,
215+
although only when accumulating to a `<dbname>` (all accumulations to a program
216+
are `#[superglobal]`). Default accumulation to db is the equivalent of `#[export]`.
217+
See the Coq reference manual for the meaning of these scopes.
193218
- `Elpi Typecheck [<qname>]` typechecks the current program (or `<qname>` if
194219
specified).
195220
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
@@ -204,10 +229,9 @@ In order to load Coq-Elpi use `From elpi Require Import elpi`.
204229
tracing for Elpi's [trace browser]().
205230
- `Elpi Bound Steps <number>` limits the number of steps an Elpi program can
206231
make.
207-
- `Elpi Print <qname> [<string> <filter>*]` prints the program `<qname>` to an
208-
HTML file named `<qname>.html` and a text file called `<qname>.txt`
209-
(or `<string>` if provided) filtering out clauses whose file or clause-name
210-
matches `<filter>`.
232+
- `Elpi Print <qname> [<string> <filter>*]` prints the program `<qname>` to
233+
a text file called `<qname>.txt` (or `<string>` if provided) filtering out
234+
clauses whose file or clause-name matches `<filter>`.
211235
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
212236

213237
where:
@@ -220,6 +244,8 @@ where:
220244
`lp:{{ coq.say "hello!" }}` becomes `" coq.say ""hello!"" "`).
221245
- `<filename>` is a string containing the path of an external file, e.g.
222246
`"this_file.elpi"`.
247+
- `<fname>` is a qualified Coq name, eg `foo.elpi` (note that `Extra Dependency`
248+
only allows simple identifiers).
223249
- `<start>` and `<stop>` are numbers, e.g. `17 24`.
224250
- `<predicate-filter>` is a regexp against which the predicate name is matched,
225251
e.g. `"derive.*"`.

_CoqProject

+2-63
Original file line numberDiff line numberDiff line change
@@ -57,72 +57,11 @@
5757
-Q _build/default/apps/tc/elpi elpi.apps.tc.elpi
5858
-Q apps/tc/examples elpi.apps.tc.examples
5959
-Q _build/default/apps/tc/examples elpi.apps.tc.examples
60-
-Q apps/tc/tests elpi.apps.tc.tests
6160
-Q _build/default/apps/tc/tests elpi.apps.tc.tests
6261
-Q apps/tc/theories elpi.apps.tc
6362
-Q _build/default/apps/tc/theories elpi.apps.tc
6463

6564
# Cram tests.
6665

67-
-Q tests/link_order5.t elpi.test
68-
-Q tests/checker.t elpi.test
69-
-Q tests/query_extra_dep.t elpi.test
70-
-Q tests/libobject_C.t elpi.test
71-
-Q tests/link_order3.t elpi.test
72-
-Q tests/ltac3.t elpi.test
73-
-Q tests/synterp.t elpi.test
74-
-Q tests/link_order6.t elpi.test
75-
-Q tests/API2.t elpi.test
76-
-Q tests/glob.t elpi.test
77-
-Q tests/require_bad_order.t elpi.test
78-
-Q tests/API_arguments.t elpi.test
79-
-Q tests/link_order9.t elpi.test
80-
-Q tests/API_typecheck.t elpi.test
81-
-Q tests/link_order7.t elpi.test
82-
-Q tests/libobject_A.t elpi.test
83-
-Q tests/libobject_B.t elpi.test
84-
-Q tests/vernacular1.t elpi.test
85-
-Q tests/API_section.t elpi.test
86-
-Q tests/tactic.t elpi.test
87-
-Q tests/link_perf.t elpi.test
88-
-Q tests/API_elaborate.t elpi.test
89-
-Q tests/link_order_import3.t elpi.test
90-
-Q tests/COQ_ELPI_ATTRIBUTES.t elpi.test
91-
-Q tests/elaborator.t elpi.test
92-
-Q tests/HOAS.t elpi.test
93-
-Q tests/API_notations.t elpi.test
94-
-Q tests/arg_HOAS.t elpi.test
95-
-Q tests/link_order_import2.t elpi.test
96-
-Q tests/link_order2.t elpi.test
97-
-Q tests/link_order8.t elpi.test
98-
-Q tests/cache_async.t elpi.test
99-
-Q tests/API_new_pred.t elpi.test
100-
-Q tests/quotation.t elpi.test
101-
-Q tests/ltac2.t elpi.test
102-
-Q tests/perf_calls.t elpi.test
103-
-Q tests/link_order1.t elpi.test
104-
-Q tests/link_order_import0.t elpi.test
105-
-Q tests/ltac.t elpi.test
106-
-Q tests/link_order4.t elpi.test
107-
-Q tests/API_env.t elpi.test
108-
-Q tests/toposort.t elpi.test
109-
-Q tests/link_order_import1.t elpi.test
110-
-Q tests/API_module.t elpi.test
111-
-Q tests/vernacular2.t elpi.test
112-
-Q tests/API.t elpi.test
113-
-Q tests/ctx_cache.t elpi.test
114-
-Q tests/API_TC_CS.t elpi.test
115-
-Q tests/example_abs_evars.t elpi.test
116-
-Q tests/example_curry_howard_tactics.t elpi.test
117-
-Q tests/example_data_base.t elpi.test
118-
-Q tests/example_fuzzer.t elpi.test
119-
-Q tests/example_generalize.t elpi.test
120-
-Q tests/example_import_projections.t elpi.test
121-
-Q tests/example_record_expansion.t elpi.test
122-
-Q tests/example_record_to_sigma.t elpi.test
123-
-Q tests/example_reduction_surgery.t elpi.test
124-
-Q tests/example_reflexive_tactic.t elpi.test
125-
-Q tests/tutorial_coq_elpi_command.t elpi.test
126-
-Q tests/tutorial_coq_elpi_HOAS.t elpi.test
127-
-Q tests/tutorial_coq_elpi_tactic.t elpi.test
128-
-Q tests/tutorial_elpi_lang.t elpi.test
66+
-Q tests elpi.tests
67+
-Q _build/default/tests elpi.tests

apps/NES/tests/test_NES_lib.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Elpi Command Make.
2323
nes.end-path,
2424
].
2525
}}.
26-
Elpi Typecheck.
26+
2727
Elpi Export Make.
2828

2929
Make Cats.And.Dogs.

apps/NES/theories/NES.v

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ main _ :-
3131
coq.say "NES: registered namespaces" NS.
3232

3333
}}.
34-
Elpi Typecheck.
34+
3535
Elpi Export NES.Status.
3636

3737
Elpi Command NES.Begin.
@@ -45,7 +45,7 @@ Elpi Command NES.Begin.
4545

4646
}}.
4747
#[interp] Elpi Accumulate lp:{{ main _ :- nes.begin-path. }}.
48-
Elpi Typecheck.
48+
4949
Elpi Export NES.Begin.
5050

5151
Elpi Command NES.End.
@@ -59,7 +59,7 @@ Elpi Command NES.End.
5959

6060
}}.
6161
#[interp] Elpi Accumulate lp:{{ main _ :- nes.end-path. }}.
62-
Elpi Typecheck.
62+
6363
Elpi Export NES.End.
6464

6565

@@ -74,7 +74,7 @@ Elpi Command NES.Open.
7474

7575
}}.
7676
#[interp] Elpi Accumulate lp:{{ main _ :- nes.open-path. }}.
77-
Elpi Typecheck.
77+
7878
Elpi Export NES.Open.
7979

8080
(* List the contents a namespace *)
@@ -93,7 +93,7 @@ Elpi Command NES.List.
9393
main _ :- coq.error "usage: NES.List <DotSeparatedPath>".
9494

9595
}}.
96-
Elpi Typecheck.
96+
9797
Elpi Export NES.List.
9898

9999
(* NES.List with types *)
@@ -118,5 +118,5 @@ Elpi Accumulate lp:{{
118118
main _ :- coq.error "usage: NES.Print <DotSeparatedPath>".
119119

120120
}}.
121-
Elpi Typecheck.
121+
122122
Elpi Export NES.Print.

apps/coercion/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ coercion _ {{ True }} {{ Prop }} {{ bool }} {{ true }}.
3636
coercion _ {{ False }} {{ Prop }} {{ bool }} {{ false }}.
3737
3838
}}.
39-
Elpi Typecheck coercion. (* checks the elpi program is OK *)
4039
4140
Check True && False.
4241
```

apps/coercion/src/coq_elpi_coercion_hook.mlg

+10-8
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ let build_expected_type env sigma expected =
2424
let return s g t = Some (s,g,t)
2525

2626
let elpi_coercion_hook program env sigma ~flags v ~inferred ~expected =
27-
let loc = API.Ast.Loc.initial "(unknown)" in
2827
let atts = [] in
2928
let sigma, expected, retype = build_expected_type env sigma expected in
3029
let sigma, goal = Evarutil.new_evar env sigma expected in
3130
let goal_evar, _ = EConstr.destEvar sigma goal in
32-
let query ~depth state =
33-
let state, (loc, q), gls =
34-
Coq_elpi_HOAS.goals2query sigma [goal_evar] loc ~main:(Coq_elpi_HOAS.Solve [v; inferred])
35-
~in_elpi_tac_arg:Coq_elpi_arg_HOAS.in_elpi_tac_econstr ~depth state in
31+
let query state =
32+
let loc = Elpi.API.State.get Coq_elpi_builtins_synterp.invocation_site_loc state in
33+
let depth = 0 in
34+
let state, q, gls =
35+
Coq_elpi_HOAS.solvegoals2query sigma [goal_evar] loc ~main:[v; inferred]
36+
~in_elpi_tac_arg:Coq_elpi_arg_HOAS.in_elpi_tac_econstr ~depth ~base:() state in
3637
let state, qatts = atts2impl loc Summary.Stage.Interp ~depth state atts q in
3738
let state = API.State.set Coq_elpi_builtins.tactic_mode state true in
38-
state, (loc, qatts), gls
39+
state, qatts, gls
3940
in
40-
match Interp.get_and_compile program with
41+
let loc = Loc.initial Loc.ToplevelInput in
42+
match Interp.get_and_compile ~loc program with
4143
| None -> None
4244
| Some (cprogram, _) ->
43-
match Interp.run ~static_check:false cprogram (`Fun query) with
45+
match Interp.run ~loc cprogram (Fun (query)) with
4446
| API.Execute.Success solution ->
4547
let gls = Evar.Set.singleton goal_evar in
4648
let sigma, _, _ = Coq_elpi_HOAS.solution2evd ~eta_contract_solution:false sigma solution gls in

apps/coercion/tests/coercion.t/test.v

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ coercion _ {{ True }} {{ Prop }} {{ bool }} {{ true }}.
88
coercion _ {{ False }} {{ Prop }} {{ bool }} {{ false }}.
99

1010
}}.
11-
Elpi Typecheck coercion.
1211

1312
Check True && False.
1413

@@ -22,7 +21,6 @@ coercion _ N {{ nat }} {{ ringType_sort lp:R }} {{ natmul lp:R lp:N }} :-
2221
coq.typecheck R {{ ringType }} ok.
2322

2423
}}.
25-
Elpi Typecheck coercion.
2624

2725
Section TestNatMul.
2826

apps/coercion/tests/coercion_open.t/test.v

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ From Coq Require Import Arith ssreflect.
44

55
Ltac my_solver := trivial with arith.
66

7-
Elpi Accumulate coercion.db lp:{{
7+
Elpi Accumulate coercion lp:{{
88

99
coercion _ X Ty {{ @sig lp:Ty lp:P }} Solution :- std.do! [
1010
% we unfold letins since the solve is dumb
@@ -17,7 +17,6 @@ coercion _ X Ty {{ @sig lp:Ty lp:P }} Solution :- std.do! [
1717
].
1818

1919
}}.
20-
Elpi Typecheck coercion.
2120

2221
Goal {x : nat | x > 0}.
2322
apply: 3.

apps/coercion/theories/coercion.v

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ pred coercion i:goal-ctx, i:term, i:term, i:term, o:term.
1515
}}.
1616

1717
Elpi Tactic coercion.
18+
Elpi Accumulate Db Header coercion.db.
1819
Elpi Accumulate lp:{{
1920

2021
solve (goal Ctx _ Ty Sol [trm V, trm VTy]) _ :- coercion Ctx V VTy Ty Sol.
2122

2223
}}.
2324
Elpi Accumulate Db coercion.db.
24-
Elpi Typecheck.
25+
2526
Elpi CoercionFallbackTactic coercion.

apps/cs/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ cs _ {{ sort lp:Sol }} {{ nat }} :-
3838
Sol = {{ Build_S nat }}.
3939
4040
}}.
41-
Elpi Typecheck canonical_solution.
4241
4342
Check eq_refl _ : (sort _) = nat.
4443
```

0 commit comments

Comments
 (0)