123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117(************************************************************************)(* * 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) *)(************************************************************************)openUtilopenNamesopenContextopenTermopsopenEnvironopenEConstropenInductiveopsopenReductionopsletrecmk_holesenvsigma=function|[]->(sigma,[])|arg::rem->let(sigma,arg)=Evarutil.new_evarenvsigmaarginlet(sigma,rem)=mk_holesenvsigmaremin(sigma,arg::rem)letreccheck_mutindenvsigmakcl=matchEConstr.kindsigma(strip_outer_castsigmacl)with|Prod(na,c1,b)->ifInt.equalk1thentryignore(find_inductiveenvsigmac1)withNot_found->TacticErrors.fixpoint_on_non_inductive_type()elseletopenContext.Rel.Declarationincheck_mutind(push_rel(LocalAssum(na,c1))env)sigma(predk)b|LetIn(na,c1,t,b)->letopenContext.Rel.Declarationincheck_mutind(push_rel(LocalDef(na,c1,t))env)sigmakb|_->TacticErrors.not_enough_products()letmutual_fixfnothers=Proofview.Goal.enterbeginfungl->letenv=Proofview.Goal.envglinletsigma=Proofview.Goal.sigmaglinletconcl=Proofview.Goal.conclglinlet()=check_mutindenvsigmanconclinletall=(f,n,concl)::othersinletall=List.map(fun(f,n,ar)->letr=Retyping.relevance_of_typeenvsigmaarin(f,r,n,ar))allinletrecmk_signsign=function|[]->sign|(f,r,n,ar)::oth->letopenContext.Named.Declarationinlet()=check_mutindenvsigmanarinifmem_named_context_valfsignthenTacticErrors.intro_already_declaredf;mk_sign(push_named_context_val(LocalAssum(make_annotfr,ar))sign)othinletnenv=reset_with_named_context(mk_sign(named_context_valenv)all)envinRefine.refine~typecheck:falsebeginfunsigma->let(sigma,evs)=mk_holesnenvsigma(List.map(fun(_,_,_,ar)->ar)all)inletids,rs,_,ars=List.split4allinletevs=List.map(Vars.subst_varssigma(List.revids))evsinletindxs=Array.of_list(List.map(funn->n-1)(List.map(fun(_,_,n,_)->n)all))inletfunnames=Array.of_list(List.map2(funir->make_annot(Namei)r)idsrs)inletbodies=Array.of_listevsinlettyparray=Array.of_listarsinletoterm=mkFix((indxs,0),(funnames,typarray,bodies))in(sigma,oterm)endendletfixidn=mutual_fixidn[]letreccheck_is_mutcoindenvsigmacl=letb=whd_allenvsigmaclinmatchEConstr.kindsigmabwith|Prod(na,c1,b)->letopenContext.Rel.Declarationincheck_is_mutcoind(push_rel(LocalAssum(na,c1))env)sigmab|_->trylet_=find_coinductiveenvsigmabin()withNot_found->TacticErrors.all_methods_in_coinductive_type()letmutual_cofixfothers=Proofview.Goal.enterbeginfungl->letenv=Proofview.Goal.envglinletsigma=Proofview.Goal.sigmaglinletconcl=Proofview.Goal.conclglinletall=(f,concl)::othersinList.iter(fun(_,c)->check_is_mutcoindenvsigmac)all;letall=List.map(fun(id,t)->(id,Retyping.relevance_of_typeenvsigmat,t))allinletrecmk_signsign=function|[]->sign|(f,r,ar)::oth->letopenContext.Named.Declarationinifmem_named_context_valfsignthenTacticErrors.already_usedf;mk_sign(push_named_context_val(LocalAssum(make_annotfr,ar))sign)othinletnenv=reset_with_named_context(mk_sign(named_context_valenv)all)envinRefine.refine~typecheck:falsebeginfunsigma->let(ids,rs,types)=List.split3allinlet(sigma,evs)=mk_holesnenvsigmatypesinletevs=List.map(Vars.subst_varssigma(List.revids))evsin(* TODO relevance *)letfunnames=Array.of_list(List.map2(funir->make_annot(Namei)r)idsrs)inlettyparray=Array.of_listtypesinletbodies=Array.of_listevsinletoterm=mkCoFix(0,(funnames,typarray,bodies))in(sigma,oterm)endendletcofixid=mutual_cofixid[]