123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259(******************************************************************************)(* This file is part of Waterproof-lib. *)(* *)(* Waterproof-lib is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as published by *)(* the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* Waterproof-lib is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public License *)(* along with Waterproof-lib. If not, see <https://www.gnu.org/licenses/>. *)(* *)(******************************************************************************)(** Functions that should be available from Ltac2 can be made available from here
*)moduleTac2ffi=Ltac2_plugin.Tac2ffimoduleTac2env=Ltac2_plugin.Tac2envmoduleTac2expr=Ltac2_plugin.Tac2expropenProofviewopenProofview.NotationsopenTac2expropenTac2ffiopenExceptionsopenHint_dataset_declarationsopenWaterproveopenWp_evars(** Creates a name used to define the function interface *)letpname(s:string):ml_tactic_name={mltac_plugin="coq-core.plugins.coq-waterproof";mltac_tactic=s}(** Wrapper around {! Tac2env.define_primitive} to make easier the primitive definition *)letdefine_primitive(name:string)(arity:'aarity)(f:'a):unit=Tac2env.define_primitive(pnamename)(mk_closurearityf)(**
Defines a function of arity 0 (that only takes a [unit] as an argument)
This function will be callable in Ltac2 with [Ltac2 @ external <ltac2_name>: unit := "coq-waterproof" "<name>".]
*)letdefine0(name:string)(f:valexprtactic):unit=define_primitivenamearity_one(fun_->f)(**
Defines a function of arity 1 (that only takes one argument)
This function will be callable in Ltac2 with [Ltac2 @ external <ltac2_name>: <type> -> unit := "coq-waterproof" "<name>".]
*)letdefine1(name:string)(r0:'arepr)(f:'a->valexprtactic):unit=define_primitivenamearity_one@@funx->f(repr_tor0x)(**
Defines a function of arity 2 in the same way as {! define1}
*)letdefine2(name:string)(r0:'arepr)(r1:'brepr)(f:'a->'b->valexprtactic):unit=define_primitivename(arity_sucarity_one)@@funxy->f(repr_tor0x)(repr_tor1y)(**
Defines a function of arity 3 in the same way as {! define1}
*)letdefine3(name:string)(r0:'arepr)(r1:'brepr)(r2:'crepr)(f:'a->'b->'c->valexprtactic):unit=define_primitivename(arity_suc(arity_sucarity_one))@@funxyz->f(repr_tor0x)(repr_tor1y)(repr_tor2z)(**
Defines a function of arity 4 in the same way as {! define1}
*)letdefine4(name:string)(r0:'arepr)(r1:'brepr)(r2:'crepr)(r3:'drepr)(f:'a->'b->'c->'d->valexprtactic):unit=define_primitivename(arity_suc(arity_suc(arity_sucarity_one)))@@funx0x1x2x3->f(repr_tor0x0)(repr_tor1x1)(repr_tor2x2)(repr_tor3x3)(**
Defines a function of arity 5 in the same way as {! define1}
*)letdefine5(name:string)(r0:'arepr)(r1:'brepr)(r2:'crepr)(r3:'drepr)(r4:'erepr)(f:'a->'b->'c->'d->'e->valexprtactic):unit=define_primitivename(arity_suc(arity_suc(arity_suc(arity_sucarity_one))))@@funx0x1x2x3x4->f(repr_tor0x0)(repr_tor1x1)(repr_tor2x2)(repr_tor3x3)(repr_tor4x4)(**
Defines a function of arity 6 in the same way as {! define1}
*)letdefine6(name:string)(r0:'arepr)(r1:'brepr)(r2:'crepr)(r3:'drepr)(r4:'erepr)(r5:'frepr)(f:'a->'b->'c->'d->'e->'f->valexprtactic):unit=define_primitivename(arity_suc(arity_suc(arity_suc(arity_suc(arity_sucarity_one)))))@@funx0x1x2x3x4x5->f(repr_tor0x0)(repr_tor1x1)(repr_tor2x2)(repr_tor3x3)(repr_tor4x4)(repr_tor5x5)(**
Defines a function of arity 7 in the same way as {! define1}
*)letdefine7(name:string)(r0:'arepr)(r1:'brepr)(r2:'crepr)(r3:'drepr)(r4:'erepr)(r5:'frepr)(r6:'grepr)(f:'a->'b->'c->'d->'e->'f->'g->valexprtactic):unit=define_primitivename(arity_suc(arity_suc(arity_suc(arity_suc(arity_suc(arity_sucarity_one))))))@@funx0x1x2x3x4x5x6->f(repr_tor0x0)(repr_tor1x1)(repr_tor2x2)(repr_tor3x3)(repr_tor4x4)(repr_tor5x5)(repr_tor6x6)(** Comes from [coq/plugins/ltac2/tac2tactics.ml] *)letthaw(r:'arepr)(f:(unit,'a)fun1):'atactic=app_fun1funitr()(** Comes from [coq/plugins/ltac2/tac2tactics.ml] *)letdelayed_of_tactic(tac:'atactic)(env:Environ.env)(sigma:Evd.evar_map):(Evd.evar_map*'a)=let_,pv=Proofview.initsigma[]inletname,poly=Names.Id.of_string"ltac2_delayed",falseinletc,pv,_,_=Proofview.apply~name~polyenvtacpvinlet_,sigma=Proofview.proofviewpvin(sigma,c)(**
Utility function to cast OCaml types into Ltac2-compatibles types
Comes from [coq/plugins/ltac2/tac2tactics.ml]
*)letdelayed_of_thunk(r:'arepr)(tac:(unit,'a)fun1)(env:Environ.env)(sigma:Evd.evar_map):(Evd.evar_map*'a)=delayed_of_tactic(thawrtac)envsigma(** Converts a ['a repr] into a [(unit -> 'a) repr] *)letthunk(r:'arepr):(unit,'a)fun1repr=fun1unitrlet_=define0let_=define1let_=define2let_=define3let_=define5let_=define7(** Converts a {! Hint_dataset_declarations.database_type} into a [valexpr] *)letdatabase_type_to_valexp(database_type:database_type):valexpr=matchdatabase_typewith|Main->ValInt0|Decidability->ValInt1|Shorten->ValInt2(** Converts a [valexpr] into a {! Hint_dataset_declarations.database_type} *)letdatabase_type_from_valexp(value:valexpr):database_type=matchvaluewith|ValIntn->letdatabase_type=matchnwith|0->Main|1->Decidability|2->Shorten|_->throw(CastError"cannot cast something an [int] greater than 3 into a [database_type]")indatabase_type|_->throw(CastError"cannot cast something different than an [int] into a [database_type]")(* Exports {! Hint_dataset_declarations.database_type} to Ltac2 *)let()=define0"database_type_main"@@tclUNIT@@database_type_to_valexpMain;define0"database_type_decidability"@@tclUNIT@@database_type_to_valexpDecidability;define0"database_type_shorten"@@tclUNIT@@database_type_to_valexpShorten(** Converts a {! Feedback.level} into a [valexpr] *)letfeedback_lvl_to_valexpr(feedback_lvl:Feedback.level):valexpr=matchfeedback_lvlwith|Debug->ValInt(-1)|Info->ValInt0|Notice->ValInt1|Warning->ValInt2|Error->ValInt3(** Converts a [valexpr] into a {! Feedback.level} *)letfeedback_lvl_from_valexpr(value:valexpr):Feedback.level=matchvaluewith|ValIntn->letfeedback_lvl=matchnwith|-1->Feedback.Debug|0->Info|1->Notice|2->Warning|3->Error|_->throw(CastError"cannot cast an [int] outside {-1, 0, 1, 2, 3} into a [Feedback.level]")infeedback_lvl|_->throw(CastError"cannot cast something different from an [int] into a [Feedback.level]")(** Pack the conversion functions for feedback levels into a representation *)letfeedback_lvl_repr=make_reprfeedback_lvl_to_valexprfeedback_lvl_from_valexpr(** Exports {! Feedback.level} to Ltac2 *)let()=define0"feedback_lvl_debug"@@tclUNIT@@feedback_lvl_to_valexprFeedback.Debug;define0"feedback_lvl_info"@@tclUNIT@@feedback_lvl_to_valexprFeedback.Info;define0"feedback_lvl_notice"@@tclUNIT@@feedback_lvl_to_valexprFeedback.Notice;define0"feedback_lvl_warning"@@tclUNIT@@feedback_lvl_to_valexprFeedback.Warning;define0"feedback_lvl_error"@@tclUNIT@@feedback_lvl_to_valexprFeedback.Error(* Exports {! Waterprove.waterprove} to Ltac2 *)let()=define4"waterprove"intbool(list(thunkconstr))(make_reprdatabase_type_to_valexpdatabase_type_from_valexp)@@fundepthshieldlemsdatabase_type->beginwaterprovedepth~shield(List.map(funlem->delayed_of_thunkconstrlem)lems)database_typeend>>=fun()->tclUNIT@@of_unit()(* Exports {! Waterprove.rwaterprove} to Ltac2 *)let()=define6"rwaterprove"intbool(list(thunkconstr))(make_reprdatabase_type_to_valexpdatabase_type_from_valexp)(listconstr)(listconstr)@@fundepthshieldlemsdatabase_typemust_useforbidden->beginrwaterprovedepth~shield(List.map(funlem->delayed_of_thunkconstrlem)lems)database_typemust_useforbiddenend>>=fun()->tclUNIT@@of_unit()let()=define1"warn_external"pp@@funinput->warninput>>=fun()->tclUNIT@@of_unit()let()=define1"notice_external"pp@@funinput->noticeinput>>=fun()->tclUNIT@@of_unit()let()=define1"throw_external"pp@@funinput->errinput>>=fun()->tclUNIT@@of_unit()let()=define1"inform_external"pp@@funinput->informinput>>=fun()->tclUNIT@@of_unit()let()=define2"message_external"feedback_lvl_reprpp@@funlvlinput->messagelvlinput>>=fun()->tclUNIT@@of_unit()let()=define1"refine_goal_with_evar_external"string@@funinput->refine_goal_with_evarinput>>=fun()->tclUNIT@@of_unit()let()=define1"blank_evars_in_term_external"constr@@funterm->blank_evars_in_termterm>>=funevars->tclUNIT@@(of_listof_evarevars)let()=define1"get_print_hypothesis_flag_external"unit@@funinput->tclUNIT@@of_bool!print_hypothesis_helplet()=define1"get_redirect_errors_flag_external"unit@@funinput->tclUNIT@@of_bool!redirect_errorslet()=define1"get_last_warning_external"unit@@funinput->get_last_warninginput>>=funpp_option->tclUNIT@@of_optionof_pppp_optionlet()=define1"get_feedback_log_external"feedback_lvl_repr@@funinput->tclUNIT@@of_listof_pp!(feedback_loginput)