Skip to content

Commit 983f0dc

Browse files
committed
Allow specifying the implicit binding kind of new section variables
1 parent 185416f commit 983f0dc

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

builtin-doc/coq-builtin.elpi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,18 @@ external pred coq.env.add-const i:id, i:term, i:term, i:opaque?,
804804
% - @inline-at! N (default: no inlining)
805805
external pred coq.env.add-axiom i:id, i:term, o:constant.
806806

807-
% [coq.env.add-section-variable Name Ty C] Declare a new section variable: C
808-
% gets a constant derived from Name
807+
% [coq.env.add-section-variable-two Name I Ty C] Declare a new section
808+
% variable: C gets a constant derived from Name
809809
% and the current module.
810810
%
811-
external pred coq.env.add-section-variable i:id, i:term, o:constant.
811+
external pred coq.env.add-section-variable-two i:id, i:implicit_kind,
812+
i:term, o:constant.
813+
814+
815+
pred coq.env.add-section-variable i:id, i:term, o:constant.
816+
coq.env.add-section-variable Name Ty C :-
817+
coq.env.add-section-variable-two Name explicit Ty C.
818+
812819

813820
% [coq.env.add-indt Decl I] Declares an inductive type.
814821
% Supported attributes:

src/coq_elpi_builtins.ml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -897,13 +897,13 @@ let warns_of_options options = options.user_warns
897897
[%%else]
898898
let warns_of_options options = options.user_warns |> Option.map UserWarn.with_empty_qf
899899
[%%endif]
900-
let add_axiom_or_variable api id ty local options state =
900+
let add_axiom_or_variable api id ty local_bkind options state =
901901
let state, poly, cumul, udecl, _ = poly_cumul_udecl_variance_of_options state options in
902902
let used = universes_of_term state ty in
903903
let sigma = restricted_sigma_of used state in
904904
if cumul then
905905
err Pp.(str api ++ str": unsupported attribute @udecl-cumul! or @univpoly-cumul!");
906-
if poly && local then
906+
if poly && Option.has_some local_bkind then
907907
err Pp.(str api ++ str": section variables cannot be universe polymorphic");
908908
let univs = UState.check_univ_decl (Evd.evar_universe_context sigma) udecl ~poly in
909909
let kind = Decls.Logical in
@@ -914,14 +914,16 @@ let add_axiom_or_variable api id ty local options state =
914914
if not (is_ground sigma ty) then
915915
err Pp.(str"coq.env.add-const: the type must be ground. Did you forge to call coq.typecheck-indt-decl?");
916916
let gr, _ =
917-
if local then begin
918-
Dumpglob.dump_definition name true "var";
919-
comAssumption_declare_variable id Vernacexpr.NoCoercion ~kind (EConstr.to_constr sigma ty) ~univs ~impargs Glob_term.Explicit ~name
920-
end else begin
917+
match local_bkind with
918+
| Some implicit_kind -> begin
919+
Dumpglob.dump_definition name true "var";
920+
comAssumption_declare_variable id Vernacexpr.NoCoercion ~kind (EConstr.to_constr sigma ty) ~univs ~impargs implicit_kind ~name
921+
end
922+
| None -> begin
921923
Dumpglob.dump_definition name false "ax";
922924
comAssumption_declare_axiom Vernacexpr.NoCoercion ~local:Locality.ImportDefaultBehavior ~kind (EConstr.to_constr sigma ty)
923925
~univs ~impargs ~inline:options.inline ~name ~id
924-
end
926+
end
925927
in
926928
let ucsts = match univs with UState.Monomorphic_entry x, _ -> x | _ -> Univ.ContextSet.empty in
927929
gr, ucsts
@@ -1960,7 +1962,7 @@ Supported attributes:
19601962
- @dropunivs! (default: false, drops all universe constraints from the store after the definition)
19611963
|})))))),
19621964
(fun id body types opaque _ ~depth {options} _ -> grab_global_env__drop_sigma_univs_if_option_is_set options "coq.env.add-const" (fun state ->
1963-
let local = options.local = Some true in
1965+
let local_bkind = if options.local = Some true then Some Glob_term.Explicit else None in
19641966
let state = minimize_universes state in
19651967
(* Maybe: UState.nf_universes on body and type *)
19661968
match body with
@@ -1970,7 +1972,7 @@ Supported attributes:
19701972
err Pp.(str "coq.env.add-const: both Type and Body are unspecified")
19711973
| B.Given ty ->
19721974
warn_deprecated_add_axiom ();
1973-
let gr, uctx = add_axiom_or_variable "coq.env.add-const" id ty local options state in
1975+
let gr, uctx = add_axiom_or_variable "coq.env.add-const" id ty local_bkind options state in
19741976
uctx, state, !: (global_constant_of_globref gr), []
19751977
end
19761978
| B.Given body ->
@@ -1993,7 +1995,7 @@ Supported attributes:
19931995
let state, poly, cumul, udecl, _ = poly_cumul_udecl_variance_of_options state options in
19941996
if cumul then err Pp.(str"coq.env.add-const: unsupported attribute @udecl-cumul! or @univpoly-cumul!");
19951997
let kind = Decls.(IsDefinition Definition) in
1996-
let scope = if local
1998+
let scope = if Option.has_some local_bkind
19971999
then Locality.Discharge
19982000
else Locality.(Global ImportDefaultBehavior) in
19992001
let cinfo = cinfo_make state types options.using ~name:(Id.of_string id) ~typ:types ~impargs:[] () in
@@ -2035,22 +2037,29 @@ Supported attributes:
20352037
- @inline! (default: no inlining)
20362038
- @inline-at! N (default: no inlining)|})))),
20372039
(fun id ty _ ~depth {options} _ -> grab_global_env "coq.env.add-axiom" (fun state ->
2038-
let gr, uctx = add_axiom_or_variable "coq.env.add-axiom" id ty false options state in
2040+
let gr, uctx = add_axiom_or_variable "coq.env.add-axiom" id ty None options state in
20392041
uctx, state, !: (global_constant_of_globref gr), []))),
20402042
DocAbove);
20412043

2042-
MLCode(Pred("coq.env.add-section-variable",
2044+
MLCode(Pred("coq.env.add-section-variable-two",
20432045
In(id, "Name",
2046+
In(implicit_kind, "I",
20442047
CIn(closed_ground_term, "Ty",
20452048
Out(constant, "C",
20462049
Full (global, {|Declare a new section variable: C gets a constant derived from Name
20472050
and the current module.
2048-
|})))),
2049-
(fun id ty _ ~depth {options} _ -> grab_global_env_drop_sigma_keep_univs "coq.env.add-section-variable" (fun state ->
2050-
let gr, uctx = add_axiom_or_variable "coq.env.add-section-variable" id ty true options state in
2051+
|}))))),
2052+
(fun id bkind ty _ ~depth {options} _ -> grab_global_env_drop_sigma_keep_univs "coq.env.add-section-variable" (fun state ->
2053+
let gr, uctx = add_axiom_or_variable "coq.env.add-section-variable" id ty (Some bkind) options state in
20512054
uctx, state, !: (global_constant_of_globref gr), []))),
20522055
DocAbove);
20532056

2057+
LPCode {|
2058+
pred coq.env.add-section-variable i:id, i:term, o:constant.
2059+
coq.env.add-section-variable Name Ty C :-
2060+
coq.env.add-section-variable-two Name explicit Ty C.
2061+
|};
2062+
20542063
MLCode(Pred("coq.env.add-indt",
20552064
CIn(indt_decl_in, "Decl",
20562065
Out(inductive, "I",

0 commit comments

Comments
 (0)