123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225(************************************************************************)(* * 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) *)(************************************************************************)openCErrorsopenUtilopenPpopenCAstopenVernacextendopenVernacexprletstring_of_vernac_when=function|VtLater->"Later"|VtNow->"Now"letstring_of_vernac_classification=function|VtStartProof_->"StartProof"|VtSideff(_,w)->"Sideff"^" "^(string_of_vernac_whenw)|VtQed(VtKeepVtKeepAxiom)->"Qed(admitted)"|VtQed(VtKeep(VtKeepOpaque|VtKeepDefined))->"Qed(keep)"|VtQedVtDrop->"Qed(drop)"|VtProofStep{proof_block_detection}->"ProofStep "^Option.default""proof_block_detection|VtQuery->"Query"|VtMeta->"Meta "|VtProofMode_->"Proof Mode"letvtkeep_of_opaque=function|Opaque->VtKeepOpaque|Transparent->VtKeepDefinedletidents_of_name:Names.Name.t->Names.Id.tlist=function|Names.Anonymous->[]|Names.Namen->[n]letstm_allow_nested_proofs_option_name=["Nested";"Proofs";"Allowed"]letoptions_affecting_stm_scheduling=[Attributes.universe_polymorphism_option_name;stm_allow_nested_proofs_option_name;Synterp.proof_mode_opt_name;Attributes.program_mode_option_name;Proof_using.proof_using_opt_name;]letclassify_vernace=letstatic_synterp_classifier~attse=matchewith(* Univ poly compatibility: we run it now, so that we can just
* look at Flags in stm.ml. Would be nicer to have the stm
* look at the entire dag to detect this option. *)|VernacSetOption(_,l,_)whenCList.exists(CList.equalString.equall)options_affecting_stm_scheduling->VtSideff([],VtNow)|VernacBeginSection{v=id}->VtSideff([id],VtLater)|VernacChdir_|VernacExtraDependency_|VernacSetOption_->VtSideff([],VtLater)(* (Local) Notations have to disappear *)|VernacEndSegment_->VtSideff([],VtNow)(* Modules with parameters have to be executed: can import notations *)|VernacDeclareModule(exp,{v=id},bl,_)|VernacDefineModule(exp,{v=id},bl,_,_)->VtSideff([id],ifbl=[]&&exp=NonethenVtLaterelseVtNow)|VernacDeclareModuleType({v=id},bl,_,_)->VtSideff([id],ifbl=[]thenVtLaterelseVtNow)(* These commands alter the parser *)|VernacDeclareCustomEntry_|VernacNotation_|VernacReservedNotation_|VernacRequire_|VernacImport_|VernacInclude_|VernacDeclareMLModule_->VtSideff([],VtNow)|VernacProofModepm->(matchPvernac.lookup_proof_modepmwith|None->CErrors.user_errPp.(str(Format.sprintf"No proof mode named \"%s\"."pm))|Someproof_mode->VtProofModeproof_mode)(* Plugins should classify their commands *)|VernacLoad_->VtSideff([],VtNow)|VernacExtend(s,l)->tryVernacextend.get_vernac_classifierslwithNot_found->anomaly(str"No classifier for"++spc()++strs.ext_entry++str".")inletstatic_pure_classifier~attse=matchewith(* Qed *)|VernacAbort->VtQedVtDrop|VernacEndProofAdmitted->VtQed(VtKeepVtKeepAxiom)|VernacEndProof(Proved(opaque,_))->VtQed(VtKeep(vtkeep_of_opaqueopaque))|VernacExactProof_->VtQed(VtKeepVtKeepOpaque)(* Query *)|VernacShow_|VernacPrint_|VernacSearch_|VernacLocate_|VernacGlobalCheck_|VernacCheckMayEval_->VtQuery(* ProofStep *)|VernacProof_|VernacFocus_|VernacUnfocus|VernacSubproof_|VernacCheckGuard|VernacValidateProof|VernacUnfocused|VernacBullet_->VtProofStep{proof_block_detection=Some"bullet"}|VernacEndSubproof->VtProofStep{proof_block_detection=Some"curly"}(* StartProof *)|VernacDefinition((DoDischarge,_),({v=i},_),ProveBody_)->VtStartProof(Doesn'tGuaranteeOpacity,idents_of_namei)|VernacDefinition(_,({v=i},_),ProveBody_)->letpolymorphic=Attributes.(parse_drop_extrapolymorphicatts)inletguarantee=ifpolymorphicthenDoesn'tGuaranteeOpacityelseGuaranteesOpacityinVtStartProof(guarantee,idents_of_namei)|VernacStartTheoremProof(_,l)->letpolymorphic=Attributes.(parse_drop_extrapolymorphicatts)inletids=List.map(fun(({v=i},_),_)->i)linletguarantee=ifpolymorphicthenDoesn'tGuaranteeOpacityelseGuaranteesOpacityinVtStartProof(guarantee,ids)|VernacFixpoint(discharge,l)->letpolymorphic=Attributes.(parse_drop_extrapolymorphicatts)inletguarantee=ifdischarge=DoDischarge||polymorphicthenDoesn'tGuaranteeOpacityelseGuaranteesOpacityinletids,open_proof=List.fold_left(fun(l,b){Vernacexpr.fname={CAst.v=id};body_def}->id::l,b||body_def=None)([],false)linifopen_proofthenVtStartProof(guarantee,ids)elseVtSideff(ids,VtLater)|VernacCoFixpoint(discharge,l)->letpolymorphic=Attributes.(parse_drop_extrapolymorphicatts)inletguarantee=ifdischarge=DoDischarge||polymorphicthenDoesn'tGuaranteeOpacityelseGuaranteesOpacityinletids,open_proof=List.fold_left(fun(l,b){Vernacexpr.fname={CAst.v=id};body_def}->id::l,b||body_def=None)([],false)linifopen_proofthenVtStartProof(guarantee,ids)elseVtSideff(ids,VtLater)(* Sideff: apply to all open branches. usually run on master only *)|VernacAssumption(_,_,l)->letids=List.flatten(List.map(fun(_,(l,_))->List.map(fun(id,_)->id.v)l)l)inVtSideff(ids,VtLater)|VernacSymboll->letids=List.flatten(List.map(fun(_,(l,_))->List.map(fun(id,_)->id.v)l)l)inVtSideff(ids,VtLater)|VernacPrimitive((id,_),_,_)->VtSideff([id.CAst.v],VtLater)|VernacDefinition(_,({v=id},_),DefineBody_)->VtSideff(idents_of_nameid,VtLater)|VernacInductive(_,l)->letids=List.map(fun(((_,({v=id},_)),_,_,cl),_)->id::matchclwith|Constructorsl->List.map(fun(_,({v=id},_))->id)l|RecordDecl(oid,l,obinder)->(matchoidwithSome{v=x}->[x]|_->[])@(matchobinderwithSome{v=x}->[x]|_->[])@CList.map_filter(function|AssumExpr({v=Names.Namen},_,_),_->Somen|_->None)l)linVtSideff(List.flattenids,VtLater)|VernacSchemel->letids=List.map(fun{v}->v)(CList.map_filter(fun(x,_)->x)l)inVtSideff(ids,VtLater)|VernacCombinedScheme({v=id},_)->VtSideff([id],VtLater)|VernacUniverse_|VernacConstraint_|VernacCanonical_|VernacCoercion_|VernacIdentityCoercion_|VernacCreateHintDb_|VernacRemoveHints_|VernacHints_|VernacArguments_|VernacReserve_|VernacGeneralizable_|VernacSetOpacity_|VernacSetStrategy_|VernacAddOption_|VernacRemoveOption_|VernacMemOption_|VernacPrintOption_|VernacDeclareReduction_|VernacExistingClass_|VernacExistingInstance_|VernacRegister_|VernacNameSectionHypSet_|VernacComments_|VernacAttributes_|VernacSchemeEquality_|VernacAddRewRule_|VernacDeclareInstance_->VtSideff([],VtLater)(* Who knows *)|VernacOpenCloseScope_|VernacDeclareScope_|VernacDelimiters_|VernacBindScope_|VernacEnableNotation_|VernacSyntacticDefinition_|VernacContext_(* TASSI: unsure *)->VtSideff([],VtNow)|VernacInstance((name,_),_,_,props,_)->letprogram,refine=Attributes.(parse_drop_extraNotations.(program++Classes.refine_att)atts)inifprogram||(props<>None&¬refine)thenVtSideff(idents_of_namename.CAst.v,VtLater)elseletpolymorphic=Attributes.(parse_drop_extrapolymorphicatts)inletguarantee=ifpolymorphicthenDoesn'tGuaranteeOpacityelseGuaranteesOpacityinVtStartProof(guarantee,idents_of_namename.CAst.v)(* Stm will install a new classifier to handle these *)|VernacBack_|VernacAbortAll|VernacUndoTo_|VernacUndo_|VernacResetName_|VernacResetInitial|VernacRestart->VtMetainletstatic_classifier~attse=matchewith|VernacSynPuree->static_pure_classifier~attse|VernacSynterpe->static_synterp_classifier~attseinletstatic_control_classifier({CAst.v;_}ascmd)=(* Fail Qed or Fail Lemma must not join/fork the DAG *)(* XXX why is Fail not always Query? *)ifVernacprop.has_query_controlcmdthen(matchstatic_classifier~atts:v.attrsv.exprwith|VtQuery|VtProofStep_|VtSideff_|VtMetaasx->x|VtQed_->VtProofStep{proof_block_detection=None}|VtStartProof_|VtProofMode_->VtQuery)elsestatic_classifier~atts:v.attrsv.exprinstatic_control_classifiere