123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147(************************************************************************)(* * The Rocq Prover / The Rocq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openUtilopenNames(** (Partial) implementation of the [Hint] command; some more
functionality still lives in tactics/hints.ml *)letproject_hint~polypril2rr=letopenEConstrinletopenRocqlibinletgr=Smartlocate.global_with_aliasrinletenv=Global.env()inletsigma=Evd.from_envenvinletsigma,c=Evd.fresh_globalenvsigmagrinlett=Retyping.get_type_ofenvsigmacinlett=Tacred.reduce_to_quantified_refenvsigma(lib_ref"core.iff.type")tinletsign,ccl=decompose_prod_declssigmatinleta,b=matchsnd(decompose_appsigmaccl)with|[|a;b|]->(a,b)|_->assertfalseinletp=ifl2rthenlib_ref"core.iff.proj1"elselib_ref"core.iff.proj2"inletsigma,p=Evd.fresh_globalenvsigmapinletc=Reductionops.whd_betaenvsigma(mkApp(c,Context.Rel.instancemkRel0sign))inletc=it_mkLambda_or_LetIn(mkApp(p,[|mkArrowaERelevance.relevant(Vars.lift1b);mkArrowbERelevance.relevant(Vars.lift1a);c|]))signinletname=Nameops.add_suffix(Nametab.basename_of_globalgr)("_proj_"^ifl2rthen"l2r"else"r2l")inletctx=Evd.univ_entry~polysigmainletc=EConstr.to_constrsigmacinletcb=Declare.(DefinitionEntry(definition_entry~univs:ctx~opaque:falsec))inletc=Declare.declare_constant~local:Locality.ImportDefaultBehavior~name~kind:Decls.(IsDefinitionDefinition)cbinletinfo={Typeclasses.hint_priority=pri;hint_pattern=None}in(info,true,Hints.hint_globref(GlobRef.ConstRefc))(* Only error when we have to (axioms may be instantiated if from functors)
XXX maybe error if not from a functor argument?
*)letsoft_evaluable=Tacred.soft_evaluable_of_global_reference(* Slightly more lenient global hint syntax for backwards compatibility *)letrectify_hint_constrh=matchhwith|Vernacexpr.HintsReferenceqid->Someqid|Vernacexpr.HintsConstrc->letopenConstrexprinmatchc.CAst.vwith|CAppExpl((qid,None),[])->Someqid|_->Noneletinterp_hints~polyh=letenv=Global.env()inletsigma=Evd.from_envenvinletfrefr=letgr=Smartlocate.global_with_aliasrinDumpglob.add_glob?loc:r.CAst.locgr;grinletfrr=soft_evaluable?loc:r.CAst.loc(frefr)inletfic=letopenHintsinmatchrectify_hint_constrcwith|Somec->letgr=Smartlocate.global_with_aliascin(hint_globrefgr)|None->CErrors.user_err(Pp.strbrk"Declaring arbitrary terms as hints is forbidden. You must declare a \
toplevel constant instead.")inletfp=Constrintern.intern_constr_patternenvsigmainletfres(info,b,r)=letgr=firinletinfo={infowithTypeclasses.hint_pattern=Option.mapfpinfo.Typeclasses.hint_pattern}in(info,b,gr)inletopenHintsinletopenVernacexprinletft=function|HintsVariables->HintsVariables|HintsConstants->HintsConstants|HintsProjections->HintsProjections|HintsReferenceslhints->HintsReferences(List.mapfrlhints)inletfp=Constrintern.intern_constr_pattern(Global.env())inmatchhwith|HintsResolvelhints->HintsResolveEntry(List.mapfreslhints)|HintsResolveIFF(l2r,lc,n)->HintsResolveEntry(List.map(project_hint~polynl2r)lc)|HintsImmediatelhints->HintsImmediateEntry(List.mapfilhints)|HintsUnfoldlhints->HintsUnfoldEntry(List.mapfrlhints)|HintsTransparency(t,b)->HintsTransparencyEntry(ftt,b)|HintsMode(r,l)->HintsModeEntry(frefr,l)|HintsConstructorslqid->letconstr_hints_of_indqid=letind=Smartlocate.global_inductive_with_aliasqidinDumpglob.dump_reference?loc:qid.CAst.loc"<>"(Libnames.string_of_qualidqid)"ind";List.init(Inductiveops.nconstructorsenvind)(funi->letc=(ind,i+1)inletgr=GlobRef.ConstructRefcin(empty_hint_info,true,hint_globrefgr))inHintsResolveEntry(List.flatten(List.mapconstr_hints_of_indlqid))|HintsExtern(pri,patcom,tacexp)->letpat=Option.map(fpsigma)patcominletltacvars=matchpatwithNone->Id.Set.empty|Some(l,_)->linlettacexp=Gentactic.intern~ltacvarsenvtacexpinHintsExternEntry({Typeclasses.hint_priority=Somepri;hint_pattern=pat},tacexp)