Skip to content

Commit f5bf472

Browse files
authored
Merge pull request #399 from LPCIC/fix-394
try harder to recover parameters
2 parents 90fef70 + ad27deb commit f5bf472

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

src/coq_elpi_arg_HOAS.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -656,22 +656,22 @@ let to_list v =
656656

657657
(* if we make coq elaborate an arity, we get a type back. here we try to
658658
recoved an arity to pass that to elpi *)
659-
let best_effort_recover_arity ~depth state typ bl =
660-
let rec aux ~depth state typ bl =
661-
match bl with
662-
| Constrexpr.CLocalAssum(x :: y :: more,k,e)::bl ->
663-
aux ~depth state typ (Constrexpr.CLocalAssum([x],k,e) :: Constrexpr.CLocalAssum(y :: more,k,e) :: bl)
664-
| Constrexpr.CLocalAssum([CAst.{ v = name }],(Constrexpr.Default ik|Constrexpr.Generalized(ik,_)),_)::bl ->
665-
begin match Coq_elpi_HOAS.is_prod ~depth typ with
666-
| None -> state, in_elpi_arity typ
667-
| Some(ty,bo) ->
668-
let state, imp = in_elpi_imp ~depth state ik in
669-
let state, bo = aux ~depth:(depth+1) state bo bl in
670-
state, in_elpi_parameter name ~imp ty bo
671-
end
659+
let best_effort_recover_arity ~depth state glob_sign typ bl =
660+
let _, grouped_bl = intern_global_context glob_sign ~intern_env:Constrintern.empty_internalization_env bl in
661+
662+
let rec aux ~depth state typ gbl =
663+
match gbl with
664+
| (name,ik,_,_) :: gbl ->
665+
begin match Coq_elpi_HOAS.is_prod ~depth typ with
666+
| None -> state, in_elpi_arity typ
667+
| Some(ty,bo) ->
668+
let state, imp = in_elpi_imp ~depth state ik in
669+
let state, bo = aux ~depth:(depth+1) state bo gbl in
670+
state, in_elpi_parameter name ~imp ty bo
671+
end
672672
| _ -> state, in_elpi_arity typ
673673
in
674-
aux ~depth state typ bl
674+
aux ~depth state typ (List.rev grouped_bl)
675675

676676
let in_elpi_string_arg ~depth state x =
677677
state, E.mkApp strc (CD.of_string x) [], []
@@ -796,7 +796,7 @@ let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
796796
let state, typ, gls1 = constr2lp_closed ~depth ?calldepth coq_ctx E.no_constraints state typ in
797797
let state, body, gls2 =
798798
option_map_acc2 (constr2lp_closed ~depth ?calldepth coq_ctx E.no_constraints) state body in
799-
let state, typ = best_effort_recover_arity ~depth state typ bl in
799+
let state, typ = best_effort_recover_arity ~depth state glob_sign typ bl in
800800
let state, body, _ = in_option ~depth state body in
801801
let c = decl_name2lp (raw_decl_name_to_glob name) in
802802
begin match udecl with

tests/test_arg_HOAS.v

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,45 @@ Elpi declarations Definition f7''@{x} := f6@{x}.
331331
Elpi raw_declarations Definition f8''@{x} := f6@{x}.
332332

333333
(* ******************** *)
334+
Unset Universe Polymorphism.
335+
336+
Class I := {}.
337+
Class L (i : I) := {}.
338+
339+
(*#[arguments(raw)] *)
340+
Elpi Command bug_394.
341+
Elpi Accumulate lp:{{
342+
main [A,B,C] :-
343+
coq.say A B C,
344+
std.assert! (A =
345+
const-decl "D"
346+
(some (fun `i` _ c0 \ fun `l` (app [{{ L }}, c0]) c1 \ {{ True }}))
347+
(parameter "i" maximal _ c0 \
348+
parameter "l" maximal (app [{{ L }}, c0]) c1 \
349+
arity (sort prop)))
350+
"not ok 1",
351+
std.assert! (B =
352+
const-decl "D"
353+
(some (fun `i` _ c0 \ fun `l` (app [{{ L }}, c0]) c1 \ {{ True }}))
354+
(parameter "i" maximal _ c0 \
355+
parameter _ maximal (app [{{ L }}, c0]) c1 \
356+
arity (sort prop)))
357+
"not ok 2",
358+
std.assert! (C =
359+
const-decl "D"
360+
(some (fun `i` _ c0 \ fun `l` (app [{{ L }}, c0]) c1 \ fun _ {{nat}} c2\ {{ True }}))
361+
(parameter "i" maximal _ c0 \
362+
parameter _ maximal (app [{{ L }}, c0]) c1 \
363+
parameter "n" explicit {{ nat }} c2\
364+
arity (sort prop)))
365+
"not ok 3"
366+
.
367+
368+
}}.
369+
Elpi Typecheck.
370+
371+
Elpi bug_394
372+
Definition D `{l : L} : Prop := True
373+
Definition D `{L} : Prop := True
374+
Definition D `{L} (n:nat) : Prop := True
375+
.

0 commit comments

Comments
 (0)