Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elpi Compile to fill the cache #694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ In order to load Coq-Elpi use `From elpi Require Import elpi`.
- `Elpi Typecheck [<qname>]` typechecks the current program (or `<qname>` if
specified).
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
- `Elpi Compile <qname list>` forces the compilation (and cache) of a set of programs/tactics.
Running a program or a tactic compiles it on the fly and caches the result.
The cache entries generated in the middle of proofs are lost then the proof ends,
so one may want to cache the compilation of (very large) tactics outside of proofs.
- `Elpi Debug <string>` sets the variable `<string>`, relevant for conditional
clause compilation (the `:if VARIABLE` clause attribute).
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
Expand Down
14 changes: 13 additions & 1 deletion src/coq_elpi_vernacular.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ let compile src =
try
lookup_code 0 h src
with Not_found ->
Coq_elpi_utils.elpitime (fun _ -> Pp.(str(Printf.sprintf "Elpi: compile: cache miss")));
match src with
| Code.Base { base = (k,u) } ->
let elpi = P.ensure_initialized () in
Expand All @@ -166,6 +167,7 @@ let compile src =
try
lookup_chunk bh h src
with Not_found ->
Coq_elpi_utils.elpitime (fun _ -> Pp.(str(Printf.sprintf "Elpi: compile: cache miss")));
match src with
| Chunk.Base { base = (k,u) } ->
let prog = P.extend_w_units ~base [u] in
Expand Down Expand Up @@ -200,6 +202,14 @@ let feedback_error loc ei = Feedback.(feedback (Message(Error,loc,CErrors.iprint
let feedback_error loc ei = Feedback.(feedback (Message(Error,loc,[],CErrors.iprint ei)))
[%%endif]

let compile pl =
let t0 = Unix.gettimeofday () in
Coq_elpi_utils.elpitime (fun _ -> Pp.(str(Printf.sprintf "Elpi: compile: filling cache")));
List.iter (fun p -> ignore(get_and_compile p)) pl;
Coq_elpi_utils.elpitime (fun _ -> Pp.(str(Printf.sprintf "Elpi: compile: filled: %4.3f" (Unix.gettimeofday () -. t0))))

let compile ~atts:ph pl = skip ~ph compile pl

let run_static_check query =
let checker =
let elpi = P.ensure_initialized () in
Expand Down Expand Up @@ -537,11 +547,13 @@ module type Common = sig
val accumulate_db : atts:((Str.regexp list option * Str.regexp list option) * phase option) -> ?program:qualified_name -> qualified_name -> unit
val accumulate_to_db : atts:((Str.regexp list option * Str.regexp list option) * phase option) -> qualified_name -> Elpi.API.Ast.Loc.t * string -> Names.Id.t list -> scope:Coq_elpi_utils.clause_scope -> unit


val load_checker : string -> unit
val load_printer : string -> unit
val load_tactic : string -> unit
val load_command : string -> unit


val compile : atts:phase option -> qualified_name list -> unit
val debug : atts:phase option -> string list -> unit
val trace : atts:phase option -> int -> int -> string list -> string list -> unit
val trace_browser : atts:phase option -> string list -> unit
Expand Down
2 changes: 2 additions & 0 deletions src/coq_elpi_vernacular.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module type Common = sig
val load_tactic : string -> unit
val load_command : string -> unit

val compile : atts:phase option -> qualified_name list -> unit

val debug : atts:phase option -> string list -> unit
val trace : atts:phase option -> int -> int -> string list -> string list -> unit
val trace_browser : atts:phase option -> string list -> unit
Expand Down
8 changes: 8 additions & 0 deletions src/coq_elpi_vernacular_syntax.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ VERNAC COMMAND EXTEND ElpiUnnamed CLASSIFIED AS SIDEFF
} -> {
EV.Interp.accumulate_db ~atts ~program:(snd p) (snd d) }

| #[ atts = any_attribute ] [ "Elpi" "Compile" qualified_name_list(pl) ] SYNTERP AS atts {
let atts = validate_attributes synterp_attribute atts in
EV.Synterp.compile ~atts (pl |> List.map snd);
atts
} -> {
EV.Interp.compile ~atts (pl |> List.map snd) }


| #[ atts = any_attribute ] [ "Elpi" "Debug" string_list(s) ] SYNTERP AS atts {
let atts = validate_attributes synterp_attribute atts in
EV.Synterp.debug ~atts s;
Expand Down
10 changes: 10 additions & 0 deletions tests/test_compile.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
From elpi Require Import elpi.

Elpi Command foo.
Elpi Accumulate lp:{{
main _ :- coq.say "ok".
}}.

Set Debug "elpitime".
Elpi Compile foo.
Elpi foo.
Loading