Skip to content

Commit 5af3600

Browse files
committed
fixed tests & bugs, removed debug msgs
1 parent ef72547 commit 5af3600

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

apps/cs/src/coq_elpi_cs_hook.mlg

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,30 @@ let elpi_cs_hook program env sigma lhs rhs =
1818
then begin
1919
let loc = API.Ast.Loc.initial "(unknown)" in
2020
let atts = [] in
21-
(*let sigma, ty = Typing.type_of env sigma lhs in*)
22-
let sigma, (ty, _) = Evarutil.new_type_evar env sigma Evd.univ_flexible in
23-
let { Coqlib.eq } = Coqlib.build_coq_eq_data () in
24-
let sigma, eq = EConstr.fresh_global env sigma eq in
25-
let t = EConstr.mkApp (eq,[|ty;lhs;rhs|]) in
26-
let sigma, goal = Evarutil.new_evar env sigma t in
21+
let (proji, u), arg =
22+
match Termops.global_app_of_constr sigma t1 with
23+
| (Names.GlobRef.ConstRef proji, u), arg -> (proji, u), arg
24+
| (proji, _), _ -> raise Not_found in
25+
let structure = Structures.Structure.find_from_projection proji in
26+
let params1, c1, extra_args1 =
27+
match arg with
28+
| Some c -> (* A primitive projection applied to c *)
29+
let ty = Retyping.get_type_of ~lax:true env sigma c in
30+
let (i,u), ind_args =
31+
(* Are we sure that ty is not an evar? *)
32+
Inductiveops.find_mrectype env sigma ty
33+
in ind_args, c, sk1
34+
| None ->
35+
match Reductionops.Stack.strip_n_app structure.nparams sk1 with
36+
| Some (params1, c1, extra_args1) -> (Option.get @@ Reductionops.Stack.list_of_app_stack params1), c1, extra_args1
37+
| _ -> raise Not_found in
38+
let sk2, extra_args2 =
39+
if Reductionops.Stack.args_size sk2 = Reductionops.Stack.args_size extra_args1 then [], sk2
40+
else match Reductionops.Stack.strip_n_app (Reductionops.Stack.args_size sk2 - Reductionops.Stack.args_size extra_args1 - 1) sk2 with
41+
| None -> raise Not_found
42+
| Some (l',el,s') -> ((Option.get @@ Reductionops.Stack.list_of_app_stack l') @ [el],s') in
43+
let rhs = Reductionops.Stack.zip sigma (t2, Reductionops.Stack.append_app_list sk2 Reductionops.Stack.empty) in
44+
let sigma, goal = Evarutil.new_evar env sigma (Retyping.get_type_of env sigma c1) in
2745
let goal_evar, _ = EConstr.destEvar sigma goal in
2846
let query ~depth state =
2947
let state, (loc, q), gls =
@@ -36,7 +54,7 @@ let elpi_cs_hook program env sigma lhs rhs =
3654
match Interp.get_and_compile program with
3755
| None -> None
3856
| Some (cprogram, _) ->
39-
match Interp.run ~static_check:false cprogram (`Fun query) with
57+
begin match Interp.run ~static_check:false cprogram (`Fun query) with
4058
| API.Execute.Success solution ->
4159
let gls = Evar.Set.singleton goal_evar in
4260
let sigma, _, _ = Coq_elpi_HOAS.solution2evd sigma solution gls in
@@ -45,16 +63,13 @@ let elpi_cs_hook program env sigma lhs rhs =
4563
let lhs = Reductionops.whd_const proji env sigma lhs in
4664
let lhs = Reductionops.whd_betaiotazeta env sigma lhs in
4765
let hh, sk1 = EConstr.decompose_app sigma lhs in
48-
let () = Feedback.msg_info Pp.(str "aha" ++ Printer.pr_econstr_env env sigma lhs) in
4966
let h2, sk2 = EConstr.decompose_app sigma rhs in
5067
let _, params = EConstr.decompose_app sigma (Retyping.get_type_of env sigma goal) in
5168
Some (sigma, (hh, h2), goal, [], (Array.to_list params, params1), (Array.to_list sk1, Array.to_list sk2), (extra_args1, extra_args2), c1, (None, rhs))
5269
else None
5370
| API.Execute.NoMoreSteps
5471
| API.Execute.Failure -> None
55-
| exception (Coq_elpi_utils.LtacFail (level, msg)) -> None
56-
end
57-
else None
72+
end
5873

5974
let add_cs_hook =
6075
let cs_hook_program = Summary.ref ~name:"elpi-cs" None in

apps/cs/tests/test_cs.v

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,15 @@ Elpi Typecheck canonical_solution.
1515

1616
Check 1.
1717
Check eq_refl _ : (sort nat _) = @id nat.
18+
Check 11.
1819
Check eq_refl _ : (sort nat _) 1 = @id nat 1.
19-
Definition nat1 := nat.
20+
Definition id1 := id.
2021
Check 2.
21-
Check eq_refl _ : (sort _) = nat1.
22+
Check eq_refl _ : (sort nat _) = @id1 nat.
2223
Definition sort1 := sort.
2324
Check 3.
24-
Check eq_refl _ : (sort1 _) = nat.
25+
Check eq_refl _ : (sort1 nat _) = @id nat.
2526
Check 4.
26-
Check eq_refl _ : (sort1 _) = nat1.
27-
28-
29-
Elpi Accumulate cs.db lp:{{
30-
31-
cs _ {{ sort lp:Sol }} {{ bool }} :-
32-
% typing is wired in, do we want this?
33-
std.spy(Sol = {{ Prop }}).
34-
35-
}}.
36-
Elpi Typecheck canonical_solution.
27+
Check eq_refl _ : (sort1 nat _) = @id1 nat.
3728

3829

0 commit comments

Comments
 (0)