Skip to content

Commit 0335f27

Browse files
CohenCyrilgares
authored andcommitted
wip
1 parent a04d35b commit 0335f27

File tree

7 files changed

+43
-16
lines changed

7 files changed

+43
-16
lines changed

.nix/coq-overlays/coq-elpi/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ with builtins; with lib; let
1212
{ case = "8.18"; out = { version = "v1.18.1"; };}
1313
{ case = "8.19"; out = { version = "v1.18.2"; };}
1414
] {} );
15+
dot-merlin-reader = coq.ocamlPackages.dot-merlin-reader;
16+
dune = coq.ocamlPackages.dune_3;
1517
in mkCoqDerivation {
1618
pname = "elpi";
1719
repo = "coq-elpi";
@@ -64,7 +66,7 @@ in mkCoqDerivation {
6466
buildFlags = [ "OCAMLWARN=" ];
6567

6668
mlPlugin = true;
67-
propagatedBuildInputs = [ coq.ocamlPackages.findlib elpi ];
69+
propagatedBuildInputs = [ coq.ocamlPackages.findlib elpi dot-merlin-reader dune ];
6870

6971
meta = {
7072
description = "Coq plugin embedding ELPI.";

.nix/ocaml-overlays/elpi/default.nix

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{ lib
22
, buildDunePackage, camlp5
33
, ocaml
4+
, ocaml-lsp
45
, menhir, menhirLib
56
, atdgen
67
, stdlib-shims
@@ -47,10 +48,11 @@ buildDunePackage rec {
4748
buildInputs = [ ncurses ]
4849
++ lib.optional (lib.versionAtLeast version "1.16" || version == "dev") atdgen;
4950

50-
propagatedBuildInputs = [ re stdlib-shims ]
51-
++ [ menhirLib ]
52-
++ [ ppxlib ppx_deriving ]
53-
;
51+
propagatedBuildInputs = [ re stdlib-shims ocaml-lsp ]
52+
++ (if versionAtLeast version "1.15" || version == "dev"
53+
then [ menhirLib ]
54+
else [ camlp5 ] )
55+
++ [ ppxlib ppx_deriving atdgen ];
5456

5557
meta = with lib; {
5658
description = "Embeddable λProlog Interpreter";

coq-builtin.elpi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ typeabbrev opaque? bool. macro @opaque! :- tt. macro @transparent! :- ff.
452452

453453
%%%%%%% Attributes to be passed to APIs as in @local! => coq.something %%%%%%%%
454454

455+
macro @keep-alg-univs! :-
456+
get-option "coq:algunivs" "keep-algunivs".
457+
macro @purge-alg-univs! :-
458+
get-option "coq:algunivs" "purge-algunivs".
459+
455460
macro @primitive! :- get-option "coq:primitive" tt. % primitive records
456461
macro @reversible! :- get-option "coq:reversible" tt. % coercions
457462
macro @no-tc! :- get-option "coq:no_tc" tt. % skip typeclass inference

elpi/coq-HOAS.elpi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ typeabbrev opaque? bool. macro @opaque! :- tt. macro @transparent! :- ff.
301301

302302
%%%%%%% Attributes to be passed to APIs as in @local! => coq.something %%%%%%%%
303303

304+
macro @keep-alg-univs! :-
305+
get-option "coq:algunivs" "keep-algunivs".
306+
macro @purge-alg-univs! :-
307+
get-option "coq:algunivs" "purge-algunivs".
308+
304309
macro @primitive! :- get-option "coq:primitive" tt. % primitive records
305310
macro @reversible! :- get-option "coq:reversible" tt. % coercions
306311
macro @no-tc! :- get-option "coq:no_tc" tt. % skip typeclass inference

src/coq_elpi_HOAS.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ type options = {
347347
keepunivs : bool option;
348348
redflags : RedFlags.reds option;
349349
no_tc: bool option;
350+
algunivs : bool option;
350351
}
351352

352353
let default_options () = {
@@ -366,6 +367,7 @@ let default_options () = {
366367
keepunivs = None;
367368
redflags = None;
368369
no_tc = None;
370+
algunivs = None;
369371
}
370372

371373
type 'a coq_context = {
@@ -1147,6 +1149,12 @@ let get_options ~depth hyps state =
11471149
let _, rd, gl = reduction_flags.Elpi.API.Conversion.readback ~depth state t in
11481150
assert (gl = []);
11491151
Some rd in
1152+
let keeping_algebraic_universes s =
1153+
if s = Some "default" then None
1154+
else if s = Some "keep-alguniv" then Some true
1155+
else if s = Some "purge-alguniv" then Some false
1156+
else if s = None then None
1157+
else err Pp.(str"Unknown algebraic universes attribute: " ++ str (Option.get s)) in
11501158
{
11511159
hoas_holes =
11521160
begin match get_bool_option "HOAS:holes" with
@@ -1169,8 +1177,6 @@ let get_options ~depth hyps state =
11691177
keepunivs = get_bool_option "coq:keepunivs";
11701178
redflags = get_redflags_option ();
11711179

1172-
}
1173-
11741180
let mk_coq_context ~options state =
11751181
let env = get_global_env state in
11761182
let section = section_ids env in

src/coq_elpi_HOAS.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type options = {
4747
keepunivs : bool option;
4848
redflags : RedFlags.reds option;
4949
no_tc: bool option;
50+
algunivs : bool option;
5051
}
5152

5253
type 'a coq_context = {

src/coq_elpi_builtins.ml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,29 +2280,35 @@ phase unnecessary.|};
22802280
MLCode(Pred("coq.sort.leq",
22812281
InOut(B.ioarg_flex sort, "S1",
22822282
InOut(B.ioarg_flex sort, "S2",
2283-
Full(unit_ctx, "constrains S1 <= S2"))),
2284-
(fun u1 u2 ~depth _ _ state ->
2283+
Full(global, "constrains S1 <= S2"))),
2284+
(fun u1 u2 ~depth { options } _ -> on_global_state "coq.sort.leq"
2285+
(fun state ->
22852286
match u1, u2 with
22862287
| Data u1, Data u2 ->
22872288
if Sorts.equal u1 u2 then state, !: u1 +! u2,[]
22882289
else
2289-
(* let state, u2 = purge_algebraic_univs_sort state (EConstr.ESorts.make u2) in *)
2290-
add_universe_constraint state (constraint_leq u1 u2), !: u1 +! u2,[]
2291-
| _ -> err Pp.(str"coq.sort.leq: called with _ as argument"))),
2290+
let state, u2 = if true (* options.algunivs != Some true *)
2291+
then purge_algebraic_univs_sort state (EConstr.ESorts.make u2)
2292+
else state, u2 in
2293+
add_universe_constraint state (constraint_leq u1 u2), !: u1 +! u2,[]
2294+
| _ -> err Pp.(str"coq.sort.leq: called with _ as argument")))),
22922295
DocAbove);
22932296
22942297
MLCode(Pred("coq.sort.eq",
22952298
InOut(B.ioarg_flex sort, "S1",
22962299
InOut(B.ioarg_flex sort, "S2",
2297-
Full(unit_ctx, "constrains S1 = S2"))),
2298-
(fun u1 u2 ~depth _ _ state ->
2300+
Full(global, "constrains S1 = S2"))),
2301+
(fun u1 u2 ~depth { options } _ -> on_global_state "coq.sort.eq"
2302+
(fun state ->
22992303
match u1, u2 with
23002304
| Data u1, Data u2 ->
23012305
if Sorts.equal u1 u2 then state, !: u1 +! u2,[]
23022306
else
2303-
(* let state, u2 = purge_algebraic_univs_sort state (EConstr.ESorts.make u2) in *)
2307+
let state, u2 = if true (* options.algunivs != Some true *)
2308+
then purge_algebraic_univs_sort state (EConstr.ESorts.make u2)
2309+
else state, u2 in
23042310
add_universe_constraint state (constraint_eq u1 u2), !: u1 +! u2, []
2305-
| _ -> err Pp.(str"coq.sort.eq: called with _ as argument"))),
2311+
| _ -> err Pp.(str"coq.sort.eq: called with _ as argument")))),
23062312
DocAbove);
23072313
23082314
MLCode(Pred("coq.sort.sup",

0 commit comments

Comments
 (0)