Skip to content

Commit 65929f7

Browse files
authored
Merge pull request LPCIC#791 from Tragicus/primgref
Give constant to every primitive projection
2 parents 5cd165a + 0a43023 commit 65929f7

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

elpi/coq-lib.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ coq.term->gref (global GR) GR :- !.
510510
coq.term->gref (pglobal GR _) GR :- !.
511511
coq.term->gref (app [Hd|_]) GR :- !, coq.term->gref Hd GR.
512512
coq.term->gref (let _ _ T x\x) GR :- !, coq.term->gref T GR.
513-
coq.term->gref (primitive (proj Proj _)) (const C) :- coq.env.primitive-projection? Proj C, !.
513+
coq.term->gref (primitive (proj Proj _)) (const C) :- coq.env.primitive-projection? Proj C _, !.
514514
:name "term->gref:fail"
515515
coq.term->gref Term _ :-
516516
fatal-error-w-data "term->gref: input has no global reference" Term.

src/rocq_elpi_builtins.ml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,13 +2361,30 @@ denote the same x as before.|};
23612361
DocAbove);
23622362

23632363
MLCode(Pred("coq.env.primitive-projection?",
2364-
In(projection, "Projection",
2365-
Out(constant, "Compatibility constant",
2366-
Easy "relates a projection to its compatibility constant.")),
2367-
(fun p _ ~depth ->
2368-
let c = Projection.constant p in
2369-
try !: (ignore (Structures.Structure.find_from_projection c); Constant c)
2370-
with Not_found -> raise No_clause)),
2364+
InOut(B.ioarg projection, "Projection",
2365+
InOut(B.ioarg constant, "Compatibility constant",
2366+
Out(int, "Index",
2367+
Read(global, "Relates a primitive projection to its compatibility constant. Index is set to the constructor argument extracted by the projection (starting from 0).")))),
2368+
(fun p c _ ~depth coq_context _ _ ->
2369+
match p, c with
2370+
| _, Data (Variable c) -> raise No_clause
2371+
| Data p, Data (Constant c) ->
2372+
if Constant.equal (Projection.constant p) c then ?: None +? None +! Names.Projection.(arg p + npars p) else raise No_clause
2373+
| NoData, NoData -> U.type_error "coq.env.primitive-projection?: got no input data"
2374+
| Data p, NoData -> ?: None +! (Constant (Projection.constant p)) +! Names.Projection.(arg p + npars p)
2375+
| NoData, Data (Constant c) ->
2376+
(match Environ.constant_opt_value_in coq_context.env (UVars.in_punivs c) with
2377+
| None -> raise No_clause
2378+
| Some p ->
2379+
let rec get_proj c =
2380+
match Constr.kind c with
2381+
| Lambda (_, _, t) -> get_proj t
2382+
| App (hd, _) -> get_proj hd
2383+
| Proj (p, _, _) -> p
2384+
| _ -> raise No_clause
2385+
in
2386+
let p = get_proj p in
2387+
!: p +? None +! Names.Projection.(arg p + npars p)))),
23712388
DocAbove);
23722389

23732390
LPDoc "-- Sorts (and their universe level, if applicable) ----------------";
@@ -2763,6 +2780,17 @@ Supported attributes:
27632780
with Not_found -> !: [])),
27642781
DocAbove);
27652782

2783+
MLCode(Pred("coq.CS.canonical-projection?",
2784+
In(constant, "Projection",
2785+
Easy "Tells if the projection can be used for CS inference."),
2786+
(fun c ~depth ->
2787+
match c with
2788+
| Variable _ -> raise No_clause
2789+
| Constant c ->
2790+
try ignore (Structures.Structure.find_from_projection c)
2791+
with Not_found -> raise No_clause)),
2792+
DocAbove);
2793+
27662794
MLCode(Pred("coq.TC.declare-class",
27672795
In(gref, "GR",
27682796
Full(global, {|Declare GR as a type class|})),

tests/test_HOAS.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Module P''.
221221

222222
Elpi Query lp:{{
223223
app[primitive (proj P _) | _] = {{X.(proj1 _)}},
224-
coq.env.primitive-projection? P C,
224+
coq.env.primitive-projection? P C _,
225225
global (const C) = {{proj1}}.
226226
}}.
227227

0 commit comments

Comments
 (0)