123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778(************************************************************************)(* * 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) *)(************************************************************************)openContext.Named.DeclarationopenVernacentries.DefAttributesopenConstrexprletcheck_allowed_implicit?loc=function|Generalized_|Default(MaxImplicit|NonMaxImplicit)->CErrors.user_err?loc(Pp.str"Unexpected implicit argument annotation.")|DefaultExplicit->()letcheck_allowed_binders=function|CLocalAssum(n::_,_,impl,_)->check_allowed_implicit?loc:n.CAst.locimpl|CLocalPattern_->()(* a priori acceptable, but interp_named_context_evars_as_arguments does not support it *)|CLocalDef(n,_,_,_)->()|CLocalAssum([],_,_,_)->assertfalseletrecfill_assumptionsenvsigma=function|[]->sigma,env,[]|LocalAssum(na,t)::ctx->letsigma,ev=Evarutil.new_evarenvsigma~src:(Loc.tag@@Evar_kinds.GoalEvar)~typeclass_candidate:falsetinletdecl=LocalDef(na,ev,t)inletsigma,env,ctx=fill_assumptions(EConstr.push_nameddeclenv)sigmactxinsigma,env,decl::ctx|LocalDef_asdecl::ctx->letsigma,env,ctx=fill_assumptions(EConstr.push_nameddeclenv)sigmactxinsigma,env,decl::ctx(** [start_deriving f suchthat lemma] starts a proof of [suchthat]
(which can contain references to [f]) in the context extended by
[f:=?x]. When the proof ends, [f] is defined as the value of [?x]
and [lemma] as the proof. *)letstart_deriving~attsblsuchthatname:Declare.Proof.t=letscope,_local,poly,program_mode,user_warns,typing_flags,using,clearbody=atts.scope,atts.locality,atts.polymorphic,atts.program,atts.user_warns,atts.typing_flags,atts.using,atts.clearbodyinifprogram_modethenCErrors.user_err(Pp.str"Program mode not supported.");letenv=Global.env()inletsigma=Evd.from_envenvinlet()=List.itercheck_allowed_bindersblinletsigma,(impls_env,((env',ctx'),_))=Constrintern.interp_named_context_evarsenvsigmablinletsigma,env',ctx'=fill_assumptionsenvsigmactx'inletsigma=Evd.shelvesigma(List.mapfst(Evar.Map.bindings(Evd.undefined_mapsigma)))inletsigma,(suchthat,impargs)=Constrintern.interp_type_evars_implsenv'sigma~impls:impls_envsuchthatin(* create the initial goals for the proof: |- Type ; |- ?1 ; f:=?2 |- suchthat *)letgoals=letopenProofviewinletrecauxenvsigma=function|[]->TCons(env,sigma,suchthat,(funsigma_->TNilsigma))|LocalAssum(id,t)::_->assertfalse|LocalDef(id,c,t)asd::ctx->TCons(env,sigma,t,(funsigmaef'->letsigma=Evd.define(fst(EConstr.destEvarsigmaef'))csigmainaux(EConstr.push_nameddenv)sigmactx))inauxenvsigmactx'inletkind=Decls.(IsDefinitionDefinition)inletinfo=Declare.Info.make~poly:(Attributes.is_universe_polymorphism())~kind()inletextract_manual=functionSomeImpargs.{impl_pos=(na,_,_);impl_expl=Manual;impl_max}->Some(na,impl_max)|_->Noneinletcinfo=letopenDeclare.CInfoinList.map(fund->letname=get_iddinletimpargs=Constrintern.implicits_of_decl_in_internalization_envnameimpls_envinletimpargs=List.mapCAst.make(List.mapextract_manualimpargs)inmake~name~typ:()~impargs())ctx'@[make~name~typ:()~impargs()]inletlemma=Declare.Proof.start_derive~name~info~cinfogoalsinDeclare.Proof.maplemma~f:(funp->Util.pi1@@Proof.run_tacticenvProofview.(tclFOCUS11shelve)p)