Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coercion hook #545

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/coercion/src/coq_elpi_coercion_hook.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ open Coq_elpi_vernacular
let elpi_coercion_hook program env sigma ~flags v ~inferred ~expected =
let loc = API.Ast.Loc.initial "(unknown)" in
let atts = [] in
let (env, sigma, expected, retype) =
match expected with
| Coercion.Type t -> (env, sigma, t, false)
| Coercion.Product -> begin let (sigma, (source, _)) = Evarutil.new_type_evar env sigma Evd.univ_flexible in
let (sigma, (target, _)) = let env = EConstr.push_rel (Context.Rel.Declaration.LocalAssum (Context.annotR (Names.Name (Namegen.default_dependent_ident)) , source)) env in Evarutil.new_type_evar env sigma Evd.univ_flexible in
(env, sigma, EConstr.mkProd (Context.annotR (Names.Name (Namegen.default_type_ident)), source, target), true) end
| Coercion.Sort -> let (sigma, t) = Evarutil.new_Type sigma in (env, sigma, t, true) in
let sigma, goal = Evarutil.new_evar env sigma expected in
let goal_evar, _ = EConstr.destEvar sigma goal in
let query ~depth state =
Expand All @@ -28,7 +35,9 @@ let elpi_coercion_hook program env sigma ~flags v ~inferred ~expected =
| API.Execute.Success solution ->
let gls = Evar.Set.singleton goal_evar in
let sigma, _, _ = Coq_elpi_HOAS.solution2evd sigma solution gls in
if Evd.is_defined sigma goal_evar then Some (sigma, goal) else None
if Evd.is_defined sigma goal_evar
then let t = if retype then Retyping.get_type_of env sigma goal else expected in Some (sigma, goal, t)
else None
| API.Execute.NoMoreSteps
| API.Execute.Failure -> None
| exception (Coq_elpi_utils.LtacFail (level, msg)) -> None
Expand Down Expand Up @@ -57,4 +66,4 @@ VERNAC COMMAND EXTEND ElpiCoercion CLASSIFIED AS SIDEFF
let () = ignore_unknown_attributes atts in
add_coercion_hook (snd p) }

END
END
17 changes: 17 additions & 0 deletions apps/coercion/tests/test_coercion.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ Check natmul R n : ringType_sort R.
Check n : ringType_sort R.

End TestNatMul.

Elpi Accumulate coercion.db lp:{{

coercion _ V T E {{ Nat.mul lp:V }} :-
coq.unify-eq T {{ nat }} ok,
coq.unify-eq E {{ nat -> nat }} ok.

coercion _ V T E {{ { m : nat | m < lp:V } }} :-
coq.unify-eq T {{ nat }} ok,
coq.unify-eq E {{ Type }} ok.

}}.
Elpi Typecheck coercion.

Check 3 2.
Check forall (x : 3), proj1_sig x < 3.

Loading