123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151(************************************************************************)(* * 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) *)(************************************************************************)openUtilopenNamesopenConstropenCErrorsopenEvdopenEvarutilopenEvarsolveopenLocusopenContext.Named.DeclarationopenPpopenLtac_pretypemoduleNamedDecl=Context.Named.Declaration(******************************************)(* Instantiation of existential variables *)(******************************************)letdepends_on_evarsigmaevk_(pbty,_,t1,t2)=tryEvar.equal(head_evarsigmat1)evkwithNoHeadEvar->tryEvar.equal(head_evarsigmat2)evkwithNoHeadEvar->falseletdefine_and_solve_constraintsevkcenvevd=ifTermops.occur_evarevdevkcthenPretype_errors.error_occur_checkenvevdevkc;letevd=defineevkcevdinlet(evd,pbs)=extract_changed_conv_pbsevd(depends_on_evarevdevk)inmatchList.fold_left(funp(pbty,env,t1,t2)->matchpwith|Successevd->Evarconv.evar_conv_x(Evarconv.default_flags_ofTransparentState.full)envevdpbtyt1t2|UnifFailure_asx->x)(Successevd)pbswith|Successevd->evd|UnifFailure_->user_errPp.(str"Instance does not satisfy the constraints.")letw_refineevkrawcenvsigma=letevi=tryEvd.find_undefinedsigmaevkwithNot_found->let()=assert(Evd.memsigmaevk)inuser_errPp.(str"Instantiate called on already-defined evar")inletenv=Evd.evar_filtered_envenveviinletsigma',typed_c=letflags=Pretyping.{use_coercions=true;use_typeclasses=UseTC;solve_unification_constraints=true;fail_evar=false;expand_evars=true;program_mode=false;polymorphic=false;undeclared_evars_patvars=false;patvars_abstract=false;unconstrained_sorts=false;}inletexpected_type=Pretyping.OfType(Evd.evar_conclevi)intryPretyping.understand_uconstr~flags~expected_typeenvsigmarawcwithewhenCErrors.noncriticale->letloc=Glob_ops.loc_of_glob_constrrawc.terminuser_err?loc(str"Instance is not well-typed in the environment of "++Termops.pr_existential_keyenvsigmaevk++str".")indefine_and_solve_constraintsevktyped_cenvsigma'(* The instantiate tactic *)letinstantiate_evarevkrawc=letopenProofview.NotationsinProofview.tclENV>>=funenv->Proofview.Goal.enterbeginfungl->letsigma=Proofview.Goal.sigmaglinletsigma'=w_refineevkrawcenvsigmainProofview.Unsafe.tclEVARSsigma'endletevar_listsigmac=letrecevrecaccc=matchEConstr.kindsigmacwith|Evar(evk,_asev)->ev::acc|_->EConstr.foldsigmaevrecacccinevrec[]cletinstantiate_tacncido=Proofview.Goal.enterbeginfungl->letsigma=Proofview.Goal.sigmaglinletenv=Proofview.Goal.envglinletconcl=Proofview.Goal.conclglinletevl=matchidowith|None->evar_listsigmaconcl|Some(id,hloc)->letdecl=Environ.lookup_namedidenvinmatchhlocwithInHyp->(matchdeclwith|LocalAssum(_,typ)->evar_listsigma(EConstr.of_constrtyp)|_->user_errPp.(str"Please be more specific: in type or value?"))|InHypTypeOnly->evar_listsigma(EConstr.of_constr(NamedDecl.get_typedecl))|InHypValueOnly->(matchdeclwith|LocalDef(_,body,_)->evar_listsigma(EConstr.of_constrbody)|_->user_errPp.(str"Not a defined hypothesis."))inifList.lengthevl<nthenuser_errPp.(str"Not enough uninstantiated existential variables.");ifn<=0thenuser_errPp.(str"Incorrect existential variable index.");letevk,_=List.nthevl(n-1)ininstantiate_evarevkcendletinstantiate_tac_by_nameidc=Proofview.Goal.enterbeginfungl->letsigma=Proofview.Goal.sigmaglinletevk=tryEvd.evar_keyidsigmawithNot_found->user_errPp.(str"Unknown existential variable.")ininstantiate_evarevkcendletlet_evarnametyp=letsrc=(Loc.tagEvar_kinds.GoalEvar)inProofview.Goal.enterbeginfungl->letsigma=Tacmach.projectglinletenv=Proofview.Goal.envglinletsigma,_=Typing.sort_ofenvsigmatypinletid=matchnamewith|Name.Anonymous->letid=Namegen.id_of_name_using_hdcharenvsigmatypnameinNamegen.next_ident_away_in_goalenvid(Termops.vars_of_envenv)|Name.Nameid->idinlet(sigma,evar)=Evarutil.new_evarenvsigma~src~naming:(Namegen.IntroFreshid)typinTacticals.tclTHEN(Proofview.Unsafe.tclEVARSsigma)(Tactics.pose_tac(Name.Nameid)evar)end