Skip to content

Commit e638b58

Browse files
committed
make primitive-projection? bidirectional and adds canonical-projection?
1 parent 47417ac commit e638b58

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/rocq_elpi_builtins.ml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,10 +2361,27 @@ 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 primitive projection to its compatibility constant.")),
2367-
(fun p _ ~depth -> !: (Constant (Projection.constant p)))),
2364+
InOut(B.ioarg projection, "Projection",
2365+
InOut(B.ioarg constant, "Compatibility constant",
2366+
Read(global, "Relates a primitive projection to its compatibility constant."))),
2367+
(fun p c ~depth coq_context _ _ ->
2368+
match p, c with
2369+
| _, Data (Variable c) -> raise No_clause
2370+
| Data p, Data (Constant c) ->
2371+
if Constant.equal (Projection.constant p) c then ?: None +? None else raise No_clause
2372+
| NoData, NoData -> U.type_error "coq.env.primitive-projection?: got no input data"
2373+
| Data p, NoData -> ?: None +! (Constant (Projection.constant p))
2374+
| NoData, Data (Constant c) ->
2375+
(match Environ.constant_opt_value_in coq_context.env (UVars.in_punivs c) with
2376+
| None -> raise No_clause
2377+
| Some p ->
2378+
let rec get_proj c =
2379+
match Constr.kind c with
2380+
| Lambda (_, _, t) -> get_proj t
2381+
| App (hd, _) -> get_proj hd
2382+
| Proj (p, _, _) -> p
2383+
| _ -> raise No_clause
2384+
in !: (get_proj p) +? None))),
23682385
DocAbove);
23692386

23702387
LPDoc "-- Sorts (and their universe level, if applicable) ----------------";
@@ -2760,6 +2777,17 @@ Supported attributes:
27602777
with Not_found -> !: [])),
27612778
DocAbove);
27622779

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

0 commit comments

Comments
 (0)