123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297(************************************************************************)(* * 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) *)(************************************************************************)openPpopenUtilopenNamesopenEnvironopenEConstropenEvdopenTactypes(**********************************************************)(** {6 Exceptions.} *)(**********************************************************)exceptionIntroAlreadyDeclaredofId.texceptionClearDependencyofenv*evar_map*Id.toption*Evarutil.clear_dependency_error*GlobRef.toptionexceptionReplacingDependencyofenv*evar_map*Id.t*Evarutil.clear_dependency_error*GlobRef.toptionexceptionAlreadyUsedofId.texceptionUsedTwiceofId.texceptionVariableHasNoValueofId.texceptionConvertIncompatibleTypesofenv*evar_map*constr*constrexceptionConvertNotATypeexceptionNotConvertibleexceptionNotUnfoldableexceptionNoQuantifiedHypothesisofquantified_hypothesis*boolexceptionCannotFindInstanceofId.texceptionNothingToRewriteofId.texceptionIllFormedEliminationTypeexceptionUnableToApplyLemmaofenv*evar_map*constr*constrexceptionDependsOnBodyofId.tlist*Id.Set.t*Id.toptionexceptionNotRightNumberConstructorsofintexceptionNotEnoughConstructorsexceptionConstructorNumberedFromOneexceptionNoConstructorsexceptionUnexpectedExtraPatternofintoption*delayed_open_constrintro_pattern_exprexceptionCannotFindInductiveArgumentexceptionOneIntroPatternExpectedexceptionKeepAndClearModifierOnlyForHypothesesexceptionFixpointOnNonInductiveTypeexceptionNotEnoughProductsexceptionAllMethodsInCoinductiveTypeexceptionReplacementIllTypedofexnexceptionNotEnoughPremisesexceptionNeedDependentProduct(**********************************************************)(** {6 Printing exceptions.} *)(**********************************************************)letclear_in_global_msg=function|None->mt()|Someref->str" implicitly in "++Printer.pr_globalrefletclear_dependency_msgenvsigmaiderringlobal=letppidupper=functionSomeid->Id.printid|None->str"This variable"inletppid=functionSomeid->Id.printid|None->str"this variable"inletpp=clear_in_global_msginglobalinmatcherrwith|Evarutil.OccurHypInSimpleClauseNone->ppidupperid++str" is used"++pp++str" in conclusion."|Evarutil.OccurHypInSimpleClause(Someid')->ppidupperid++strbrk" is used"++pp++str" in hypothesis "++Id.printid'++str"."|Evarutil.EvarTypingBreakev->str"Cannot remove "++ppidid++strbrk" without breaking the typing of "++Printer.pr_leconstr_envenvsigma(mkEvarev)++str"."|Evarutil.NoCandidatesLeftev->str"Cannot remove "++ppidid++str" as it would leave the existential "++Printer.pr_existential_keyenvsigmaev++str" without candidates."letreplacing_dependency_msgenvsigmaiderringlobal=letpp=clear_in_global_msginglobalinmatcherrwith|Evarutil.OccurHypInSimpleClauseNone->str"Cannot change "++Id.printid++str", it is used"++pp++str" in conclusion."|Evarutil.OccurHypInSimpleClause(Someid')->str"Cannot change "++Id.printid++strbrk", it is used"++pp++str" in hypothesis "++Id.printid'++str"."|Evarutil.EvarTypingBreakev->str"Cannot change "++Id.printid++strbrk" without breaking the typing of "++Printer.pr_leconstr_envenvsigma(mkEvarev)++str"."|Evarutil.NoCandidatesLeftev->str"Cannot change "++Id.printid++str" as it would leave the existential "++Printer.pr_existential_keyenvsigmaev++str" without candidates."letmsg_quantified_hypothesis=function|NamedHypid->str"quantified hypothesis named "++Id.printid.CAst.v|AnonHypn->pr_nthn++str" non dependent hypothesis"letexplain_unexpected_extra_patternboundpat=letnb=Option.getboundinlets1,s2,s3=matchpatwith|IntroNaming(IntroIdentifier_)->"name",(String.pluralnb" introduction pattern"),"no"|_->"introduction pattern","","none"instr"Unexpected "++strs1++str" ("++(ifInt.equalnb0then(strs3++strs2)else(str"at most "++intnb++strs2))++spc()++str(ifInt.equalnb1then"was"else"were")++strbrk" expected in the branch)."(** Internal exception used by [tactic_interp_error_handler]. *)exceptionUnhandled(** Top-level exception handler (pretty-prints an exception). *)lettactic_interp_error_handler=function|IntroAlreadyDeclaredid->Id.printid++str" is already declared."|ClearDependency(env,sigma,id,err,inglobal)->clear_dependency_msgenvsigmaiderringlobal|ReplacingDependency(env,sigma,id,err,inglobal)->replacing_dependency_msgenvsigmaiderringlobal|AlreadyUsedid->Id.printid++str" is already used."|UsedTwiceid->Id.printid++str" is used twice."|VariableHasNoValueid->Id.printid++str" is not a defined hypothesis."|ConvertIncompatibleTypes(env,sigma,t1,t2)->str"The first term has type"++spc()++quote(Termops.Internal.print_constr_envenvsigmat1)++spc()++strbrk"while the second term has incompatible type"++spc()++quote(Termops.Internal.print_constr_envenvsigmat2)++str"."|ConvertNotAType->str"Not a type."|NotConvertible->str"Not convertible."|NotUnfoldable->str"Cannot unfold a non-constant."|NoQuantifiedHypothesis(id,red)->str"No "++msg_quantified_hypothesisid++strbrk" in current goal"++(ifredthenstrbrk" even after head-reduction"elsemt())++str"."|CannotFindInstanceid->str"Cannot find an instance for "++Id.printid++str"."|NothingToRewriteid->str"Nothing to rewrite in "++Id.printid++str"."|IllFormedEliminationType->str"The type of elimination clause is not well-formed."|UnableToApplyLemma(env,sigma,thm,t)->str"Unable to apply lemma of type"++brk(1,1)++quote(Printer.pr_leconstr_envenvsigmathm)++spc()++str"on hypothesis of type"++brk(1,1)++quote(Printer.pr_leconstr_envenvsigmat)++str"."|DependsOnBody(idl,ids,where)->letidl=List.filter(funid->Id.Set.memidids)idlinleton_the_bodies=function|[]->assertfalse|[id]->str" depends on the body of "++Id.printid|l->str" depends on the bodies of "++pr_sequenceId.printlin(matchwherewith|None->str"Conclusion"++on_the_bodiesidl|Someid->str"Hypothesis "++Id.printid++on_the_bodiesidl)|NotRightNumberConstructorsn->str"Not an inductive goal with "++intn++str(String.pluraln" constructor")++str"."|NotEnoughConstructors->str"Not enough constructors."|ConstructorNumberedFromOne->str"The constructors are numbered starting from 1."|NoConstructors->str"The type has no constructors."|UnexpectedExtraPattern(bound,pat)->explain_unexpected_extra_patternboundpat|CannotFindInductiveArgument->str"Cannot find inductive argument of elimination scheme."|OneIntroPatternExpected->str"Introduction pattern for one hypothesis expected."|KeepAndClearModifierOnlyForHypotheses->str"keep/clear modifiers apply only to hypothesis names."|FixpointOnNonInductiveType->str"Cannot do a fixpoint on a non inductive type."|NotEnoughProducts->str"Not enough products."|AllMethodsInCoinductiveType->str"All methods must construct elements in coinductive types."|ReplacementIllTypede->str"Replacement would lead to an ill-typed term:"++spc()++CErrors.printe|NotEnoughPremises->str"Applied theorem does not have enough premises."|NeedDependentProduct->str"Needs a non-dependent product."|_->raiseUnhandledletwrap_unhandledfe=trySome(fe)withUnhandled->None(** Register the exception handler so that exceptions are nicely printed to the user. *)let_=CErrors.register_handler(wrap_unhandledtactic_interp_error_handler)(**********************************************************)(** {6 Raising exceptions.} *)(**********************************************************)letintro_already_declared?locid=Loc.raise?loc(IntroAlreadyDeclaredid)letclear_dependency?locenvsigmaiddep_errgref=Loc.raise?loc(ClearDependency(env,sigma,id,dep_err,gref))letreplacing_dependency?locenvsigmaiddep_errgref=Loc.raise?loc(ReplacingDependency(env,sigma,id,dep_err,gref))letalready_used?locid=Loc.raise?loc(AlreadyUsedid)letused_twice?locid=Loc.raise?loc(UsedTwiceid)letvariable_has_no_value?locid=Loc.raise?loc(VariableHasNoValueid)letconvert_incompatible_types?locenvsigmaxy=Loc.raise?loc(ConvertIncompatibleTypes(env,sigma,x,y))letconvert_not_a_type?loc()=Loc.raise?locConvertNotATypeletnot_convertible?loc()=Loc.raise?locNotConvertibleletnot_unfoldable?loc()=Loc.raise?locNotUnfoldableletno_quantified_hypothesis?lochypb=Loc.raise?loc(NoQuantifiedHypothesis(hyp,b))letcannot_find_instance?locid=Loc.raise?loc(CannotFindInstanceid)letnothing_to_rewrite?locid=Loc.raise?loc(NothingToRewriteid)letill_formed_elimination_type?loc()=Loc.raise?locIllFormedEliminationTypeletunable_to_apply_lemma?locenvsigmaxy=Loc.raise?loc(UnableToApplyLemma(env,sigma,x,y))letdepends_on_body?locididsid_opt=Loc.raise?loc(DependsOnBody(id,ids,id_opt))letnot_right_number_constructors?locn=Loc.raise?loc(NotRightNumberConstructorsn)letnot_enough_constructors?loc()=Loc.raise?locNotEnoughConstructorsletconstructors_numbered_from_one?loc()=Loc.raise?locConstructorNumberedFromOneletno_constructors?loc()=Loc.raise?locNoConstructorsletunexpected_extra_pattern?locnpatt=Loc.raise?loc(UnexpectedExtraPattern(n,patt))letcannot_find_inductive_argument?loc()=Loc.raise?locCannotFindInductiveArgumentletone_intro_pattern_expected?loc()=Loc.raise?locOneIntroPatternExpectedletkeep_and_clear_modifier_only_for_hypotheses?loc()=Loc.raise?locKeepAndClearModifierOnlyForHypothesesletfixpoint_on_non_inductive_type?loc()=Loc.raise?locFixpointOnNonInductiveTypeletnot_enough_products?loc()=Loc.raise?locNotEnoughProductsletall_methods_in_coinductive_type?loc()=Loc.raise?locAllMethodsInCoinductiveTypeletreplacement_ill_typed?locexn=Loc.raise?loc(ReplacementIllTypedexn)letnot_enough_premises?loc()=Loc.raise?locNotEnoughPremisesletneed_dependent_product?loc()=Loc.raise?locNeedDependentProduct