123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169(************************************************************************)(* * The Coq Proof Assistant / The Coq 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=letopenEConstrinletopenCoqlibinletgr=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))letwarning_deprecated_hint_constr=CWarnings.create_warning~from:[CWarnings.CoreCategories.automation;Deprecation.Version.v8_20]~name:"fragile-hint-constr"~default:AsError()letwarn_deprecated_hint_constr=CWarnings.create_inwarning_deprecated_hint_constr(fun()->Pp.strbrk"Declaring arbitrary terms as hints is fragile and deprecated; it is \
recommended to declare a toplevel constant instead")(* 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.HintsReference_->h|Vernacexpr.HintsConstrc->letopenConstrexprinmatchc.CAst.vwith|CAppExpl((qid,None),[])->Vernacexpr.HintsReferenceqid|_->Vernacexpr.HintsConstrcletinterp_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=letopenHintsinletopenVernacexprinmatchrectify_hint_constrcwith|HintsReferencec->letgr=Smartlocate.global_with_aliascin(hint_globrefgr)|HintsConstrc->let()=warn_deprecated_hint_constr()inletenv=Global.env()inletsigma=Evd.from_envenvinletc,uctx=Constrintern.interp_constrenvsigmacinletuctx=UState.normalize_variablesuctxinletc=Evarutil.nf_evar(Evd.from_ctxuctx)cinletc=ifpolythen(c,Some(UState.sort_context_setuctx))elselet()=Global.push_context_set~strict:true(UState.context_setuctx)in(c,None)in(Hints.hint_constrc)[@ocaml.warning"-3"]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,_)->linletenv=Genintern.{(empty_glob_sign~strict:trueenv)withltacvars}inlet_,tacexp=Genintern.generic_internenvtacexpinHintsExternEntry({Typeclasses.hint_priority=Somepri;hint_pattern=pat},tacexp)