Skip to content

Commit 5fe7ba3

Browse files
committed
attribute @using! (fix #210)
1 parent bf1b142 commit 5fe7ba3

File tree

8 files changed

+31
-3
lines changed

8 files changed

+31
-3
lines changed

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
Requires Elpi 1.13 and Coq 8.13.
66

7-
- Fix `elpi.loc` computation when run in interactive mode
7+
### API
8+
- Fix `elpi.loc` computation when run in interactive mode.
9+
- New `@using! S` attribute for `coq.env.add-const` akin to Coq's `#[using=S]`.
810

911
## [1.9.1] - 11-02-2021
1012

coq-builtin.elpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ macro @ppwidth! N :- get-option "coq:ppwidth" N. % printing width
302302
macro @ppall! :- get-option "coq:pp" "all". % printing all
303303
macro @ppmost! :- get-option "coq:pp" "most". % printing most of contents
304304

305+
macro @using! S :- get-option "coq:using" S. % like the #[using=S] attribute
306+
305307
% both arguments are strings eg "8.12.0" "use foo instead"
306308
macro @deprecated! Since Msg :-
307309
get-option "coq:deprecated" (pr Since Msg).
@@ -568,6 +570,7 @@ external pred coq.env.current-path o:list string.
568570
% instead.
569571
% Supported attributes:
570572
% - @local! (default: false)
573+
% - @using! (default: section variables actually used)
571574
external pred coq.env.add-const i:id, i:term, i:term, i:opaque?,
572575
o:constant.
573576

elpi/coq-HOAS.elpi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ macro @ppwidth! N :- get-option "coq:ppwidth" N. % printing width
287287
macro @ppall! :- get-option "coq:pp" "all". % printing all
288288
macro @ppmost! :- get-option "coq:pp" "most". % printing most of contents
289289

290+
macro @using! S :- get-option "coq:using" S. % like the #[using=S] attribute
291+
290292
% both arguments are strings eg "8.12.0" "use foo instead"
291293
macro @deprecated! Since Msg :-
292294
get-option "coq:deprecated" (pr Since Msg).

src/coq_elpi_HOAS.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type options = {
8282
failsafe : bool; (* don't fail, e.g. we are trying to print a term *)
8383
ppwidth : int;
8484
pp : ppoption;
85+
using : string option;
8586
}
8687

8788
let default_options = {
@@ -92,6 +93,7 @@ let default_options = {
9293
failsafe = false;
9394
ppwidth = 80;
9495
pp = Normal;
96+
using = None;
9597
}
9698

9799
type 'a coq_context = {
@@ -645,6 +647,7 @@ let get_options ~depth hyps state =
645647
failsafe = false;
646648
ppwidth = ppwidth @@ get_int_option "coq:ppwidth";
647649
pp = pp @@ get_string_option "coq:pp";
650+
using = get_string_option "coq:using";
648651
}
649652

650653
let mk_coq_context ~options state =

src/coq_elpi_HOAS.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type options = {
2424
failsafe : bool; (* readback is resilient to illformed terms *)
2525
ppwidth : int;
2626
pp : ppoption;
27+
using : string option;
2728
}
2829

2930
type 'a coq_context = {

src/coq_elpi_builtins.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,8 @@ if a section is open and @local! is used). Omitting the body and the type is
11781178
an error. Note: using this API for declaring an axiom or a section variable is
11791179
deprecated, use coq.env.add-axiom or coq.env.add-section-variable instead.
11801180
Supported attributes:
1181-
- @local! (default: false)|})))))),
1181+
- @local! (default: false)
1182+
- @using! (default: section variables actually used)|})))))),
11821183
(fun id body types opaque _ ~depth {options} _ -> on_global_state "coq.env.add-const" (fun state ->
11831184
let local = options.local = Some true in
11841185
let sigma = get_sigma state in
@@ -1207,7 +1208,12 @@ Supported attributes:
12071208
let scope = if local
12081209
then Locality.Discharge
12091210
else Locality.(Global ImportDefaultBehavior) in
1210-
let cinfo = Declare.CInfo.make ~name:(Id.of_string id) ~typ:types ~impargs:[] () in
1211+
let using = Option.map Proof_using.(fun s ->
1212+
let types = Option.List.cons types [] in
1213+
let expr = using_from_string s in
1214+
let names = process_expr (get_global_env state) sigma expr types in
1215+
List.fold_right Names.Id.Set.add names Names.Id.Set.empty) options.using in
1216+
let cinfo = Declare.CInfo.make ?using ~name:(Id.of_string id) ~typ:types ~impargs:[] () in
12111217
let info = Declare.Info.make ~scope ~kind ~poly:false ~udecl () in
12121218
let gr = Declare.declare_definition ~cinfo ~info ~opaque:(opaque = Given true) ~body sigma in
12131219
state, !: (global_constant_of_globref gr), []))),

src/coq_elpi_builtins_HOAS.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ macro @ppwidth! N :- get-option "coq:ppwidth" N. % printing width
289289
macro @ppall! :- get-option "coq:pp" "all". % printing all
290290
macro @ppmost! :- get-option "coq:pp" "most". % printing most of contents
291291
292+
macro @using! S :- get-option "coq:using" S. % like the #[using=S] attribute
293+
292294
% both arguments are strings eg "8.12.0" "use foo instead"
293295
macro @deprecated! Since Msg :-
294296
get-option "coq:deprecated" (pr Since Msg).

tests/test_API.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,12 @@ main _ :- std.do! [
774774
}}.
775775
Elpi Typecheck.
776776
Elpi test.pp.
777+
778+
(************* using ********************)
779+
Section Using.
780+
Variable A : bool.
781+
Elpi Query lp:{{ coq.env.add-const "foo" {{ 3 }} {{ nat }} @transparent! _ }}.
782+
Elpi Query lp:{{ @using! "All" => coq.env.add-const "bar" {{ 3 }} {{ nat }} @transparent! _ }}.
783+
End Using.
784+
Check foo : nat.
785+
Check bar : bool -> nat.

0 commit comments

Comments
 (0)