| 1 |
/* license: GNU Lesser General Public License Version 2.1 or later */ |
| 2 |
/* ------------------------------------------------------------------------- */ |
| 3 |
main _. |
| 4 |
|
| 5 |
msolve L N :- tc.time-it tc.oTC-time-msolve (coq.ltac.all (coq.ltac.open tc.solve-aux) L N) "msolve". |
| 6 |
msolve L _ :- coq.ltac.fail _ "[TC] fail to solve" L. |
| 7 |
|
| 8 |
namespace tc { |
| 9 |
pred build-query-from-goal i:term, i:term, o:prop, o:list prop. |
| 10 |
build-query-from-goal Goal Proof Q PostProcess :- |
| 11 |
tc.compile.goal Goal Goal' PostProcess, !, |
| 12 |
coq.safe-dest-app Goal' (global TC) TL', |
| 13 |
std.append TL' [Proof] TL, !, |
| 14 |
coq.elpi.predicate {tc.gref->pred-name TC} TL Q. |
| 15 |
|
| 16 |
type tc.mode_fail term. |
| 17 |
|
| 18 |
pred refine-proof i:term, i:goal, o:list sealed-goal. |
| 19 |
refine-proof tc.mode_fail G [seal G] :- !. |
| 20 |
refine-proof Proof G GL :- |
| 21 |
if-true print-solution (coq.say "[TC] The proof is <<<" Proof ">>>"), |
| 22 |
if-true print-solution-pp (coq.say "[TC] The proof is <<<" {coq.term->string Proof} ">>>"), |
| 23 |
|
| 24 |
/*********** CHECK IF THE PROOF TYPECHECKS ***********/ |
| 25 |
tc.time-it tc.oTC-time-refine (@no-tc! => refine.typecheck Proof G GL) "refine.typecheck", |
| 26 |
|
| 27 |
if-true print-solution (coq.say "[TC] The proof typechecks"). |
| 28 |
|
| 29 |
pred solve-under-context i:term, o:term. |
| 30 |
solve-under-context Ty Proof :- |
| 31 |
tc.time-it tc.oTC-time-compile-goal (build-query-from-goal Ty Proof Q PostProcess) "build query", !, |
| 32 |
if-true print-compiled-goal (coq.say "[TC] the compiled goal is" Q), !, |
| 33 |
tc.time-it tc.oTC-time-instance-search ( |
| 34 |
do PostProcess, Q, |
| 35 |
tc.link.solve-eta, % Trigger eta links |
| 36 |
tc.link.solve-llam % Trigger llam links |
| 37 |
) "instance search". |
| 38 |
|
| 39 |
pred solve-aux i:goal, o:list sealed-goal. |
| 40 |
solve-aux (goal Ctx _ Ty P_ Ag_ as G) GL :- |
| 41 |
tc.time-it _ (solve-aux1 Ctx Ty Proof) "full instance search", |
| 42 |
refine-proof Proof G GL. |
| 43 |
|
| 44 |
pred solve-aux1 i:goal-ctx, i:term, o:term. |
| 45 |
:name "solve-aux-intros" |
| 46 |
solve-aux1 Ctx (prod N X T) Proof :- !, |
| 47 |
@pi-decl _ X x\ |
| 48 |
solve-aux1 [decl x N X | Ctx] (T x) (Proof' x), |
| 49 |
if (Proof' x = tc.mode_fail) |
| 50 |
(Proof = tc.mode_fail) |
| 51 |
(Proof = fun N X Proof'). |
| 52 |
|
| 53 |
:name "solve-aux-conclusion" |
| 54 |
solve-aux1 Ctx TyRaw Proof :- |
| 55 |
tc.time-it _ (tc.normalize-ty TyRaw Ty) "normalize ty", |
| 56 |
if-true print-goal (coq.say "The goal is <<<" Ty ">>>"), |
| 57 |
if-true print-goal-pp (coq.say "The goal is <<<" {coq.term->string Ty} ">>>"), |
| 58 |
% tc.time-it tc.oTC-time-mode-check (tc.modes-check Ty) "mode check", !, |
| 59 |
tc.time-it _ (tc.compile.context Ctx CtxClause) "compile context", !, |
| 60 |
CtxClause => solve-under-context Ty Proof. |
| 61 |
solve-aux1 _ _ tc.mode_fail :- if-true (print-solution; print-solution-pp) (coq.say "Invalid mode call"). |
| 62 |
|
| 63 |
pred print-solution. % Print the solution in HOAS |
| 64 |
pred print-solution-pp. % Print the solution in coq pp |
| 65 |
pred print-goal. % Print the goal in HOAS |
| 66 |
pred print-goal-pp. % Print the goal with coq pp |
| 67 |
pred print-compiled-goal. |
| 68 |
|
| 69 |
} |