Skip to content

Commit 363feae

Browse files
committed
Adapt to Elpi 2.0
1 parent 69aac6f commit 363feae

File tree

150 files changed

+1875
-1339
lines changed

Some content is hidden

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

150 files changed

+1875
-1339
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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:

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,23 @@ In order to load Coq-Elpi use `From elpi Require Import elpi`.
183183
- `Elpi Program <qname> <code>` lower level primitive letting one crate a
184184
command/tactic with a custom preamble `<code>`.
185185
- `From some.load.path Extra Dependency <filename> as <fname>`.
186-
- `Elpi Accumulate [<dbname>|<qname>] [<code>|File <fname>|Db <dbname>]`
186+
- `Elpi Accumulate [<dbname>|<qname>] [<code>|File <fname>|Db [Header] <dbname>]`
187187
adds code to the current program (or `<dbname>` or `<qname>` if specified).
188188
The code can be verbatim, from a file or a Db.
189189
File names `<fname>` must have been previously declared with the above command.
190190
It understands the `#[skip="rex"]` and `#[only="rex"]` which make the command
191191
a no op if the Coq version is matched (or not) by the given regular expression.
192192
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
193+
Accumulating `Db Header <dbname>`, instead of `Db <dbname>`, accumulates
194+
only the first chunk of code associated with Db, typically the type
195+
declaration of the predicates that live in the Db. When defining a command
196+
or tactic it can be useful to first accumulate the Db header, then some
197+
code (possibly calling the predicate living in the Db), and finally
198+
accumulating the (full) Db.
199+
Note that when a command is executed it may need to be (partially)
200+
recompiled, e.g. if the Db was updated. In this case all the code accumulated
201+
after the Db (but not after its header) may need to be recompiled. Hence
202+
we recommend to accumulate Dbs last.
193203
- `Elpi Typecheck [<qname>]` typechecks the current program (or `<qname>` if
194204
specified).
195205
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)

apps/NES/tests/test_NES_lib.v

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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/src/coq_elpi_coercion_hook.mlg

Lines changed: 10 additions & 8 deletions
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/theories/coercion.v

Lines changed: 2 additions & 1 deletion
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/src/coq_elpi_cs_hook.mlg

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ open Coq_elpi_arg_syntax
88
open Coq_elpi_vernacular
99

1010
let elpi_cs_hook program env sigma ((proji, u), params1, c1) (t2, args2) =
11-
let loc = API.Ast.Loc.initial "(unknown)" in
1211
let atts = [] in
1312
let rhs = Reductionops.Stack.zip sigma (t2, Reductionops.Stack.append_app_list args2 Reductionops.Stack.empty) in
1413
let sigma, (goal_ty, _) = Evarutil.new_type_evar env sigma Evd.UnivRigid in
1514
let sigma, goal = Evarutil.new_evar env sigma goal_ty in
1615
let goal_evar, _ = EConstr.destEvar sigma goal in
1716
let nparams = Structures.Structure.projection_nparams proji in
18-
let query ~depth state =
19-
let state, (loc, q), gls =
17+
let query state =
18+
let loc = Elpi.API.State.get Coq_elpi_builtins_synterp.invocation_site_loc state in
19+
let state, q, gls =
2020
let lhs = match params1 with
2121
| Some params1 -> EConstr.mkApp (EConstr.mkConstU (proji, u), Array.of_list params1)
2222
| None -> EConstr.mkConstU (proji, u) in
23-
Coq_elpi_HOAS.goals2query sigma [goal_evar] loc ~main:(Coq_elpi_HOAS.Solve [lhs; rhs])
24-
~in_elpi_tac_arg:Coq_elpi_arg_HOAS.in_elpi_tac_econstr ~depth state in
25-
let state, qatts = atts2impl loc Summary.Stage.Interp ~depth state atts q in
23+
Coq_elpi_HOAS.solvegoals2query sigma [goal_evar] loc ~main:[lhs; rhs]
24+
~in_elpi_tac_arg:Coq_elpi_arg_HOAS.in_elpi_tac_econstr ~depth:0 ~base:() state in
25+
let state, qatts = atts2impl loc Summary.Stage.Interp ~depth:0 state atts q in
2626
let state = API.State.set Coq_elpi_builtins.tactic_mode state true in
27-
state, (loc, qatts), gls
28-
in match Interp.get_and_compile program with
27+
state, qatts, gls
28+
in
29+
let loc = Loc.initial Loc.ToplevelInput in
30+
match Interp.get_and_compile ~loc program with
2931
| None -> None
3032
| Some (cprogram, _) ->
31-
begin match Interp.run ~static_check:false cprogram (`Fun query) with
33+
begin match Interp.run ~loc cprogram (Fun query) with
3234
| API.Execute.Success solution ->
3335
let gls = Evar.Set.singleton goal_evar in
3436
let sigma, _, _ = Coq_elpi_HOAS.solution2evd ~eta_contract_solution:false sigma solution gls in

apps/cs/theories/cs.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ solve (goal Ctx _ _Ty Sol [trm Proj, trm Rhs]) _ :-
2424
true.
2525

2626
}}.
27-
Elpi Typecheck canonical_solution.
2827
Elpi CS canonical_solution.

apps/derive/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ Elpi Accumulate lp:{{
525525
pred usage.
526526
usage :- coq.error "Usage: derive.myder <object name>".
527527
}}.
528-
Elpi Typecheck.
528+
529529
```
530530

531531
This is enough to run the derivation via something like

0 commit comments

Comments
 (0)