123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268(************************************************************************)(* * 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) *)(************************************************************************)moduleParser=structtypet=Pcoq.frozen_tletinit()=Pcoq.freeze~marshallable:falseletcur_state()=Pcoq.freeze~marshallable:falseletparsepsentrypa=Pcoq.unfreezeps;Flags.with_optionFlags.we_are_parsing(fun()->Pcoq.Entry.parseentrypa)()endmoduleSystem:sigtypetvalprotect:('a->'b)->'a->'bvalfreeze:marshallable:bool->tvalunfreeze:t->unitmoduleStm:sigvalmake_shallow:t->tvallib:t->Lib.frozenvalsummary:t->Summary.frozenvalreplace_summary:t->Summary.frozen->tendend=structtypet=Lib.frozen*Summary.frozenletfreeze~marshallable=(Lib.freeze(),Summary.freeze_summaries~marshallable)letunfreeze(fl,fs)=Lib.unfreezefl;Summary.unfreeze_summariesfsletprotectfx=letst=freeze~marshallable:falseintryleta=fxinunfreezest;awithreraise->letreraise=Exninfo.capturereraisein(unfreezest;Exninfo.iraisereraise)(* STM-specific state manipulations *)moduleStm=structletmake_shallow(lib,summary)=Lib.drop_objectslib,summaryletlib=fstletsummary=sndletreplace_summary(lib,_)summary=(lib,summary)endendmoduleLemmaStack=structtypet=Declare.Proof.tNeList.tletmap~fx=NeList.mapfxletmap_top~fx=NeList.map_headfxletpopx=NeList.headx,NeList.tailxletget_top=NeList.headletwith_topx~f=f(get_topx)letpushontopa=NeList.pushaontopletget_all_proof_names(pf:t)=letprjx=Declare.Proof.getxinList.mapProof.(functionpf->(data(prjpf)).name)(NeList.to_listpf)letcopy_infosrctgt=Declare.Proof.map~f:(fun_->Declare.Proof.gettgt)srcletcopy_info~(src:t)~(tgt:t)=NeList.map2copy_infosrctgtendtypet={parsing:Parser.t;system:System.t;(* summary + libstack *)lemmas:LemmaStack.toption;(* proofs of lemmas currently opened *)program:Declare.OblState.tNeList.t;(* obligations table *)opaques:Opaques.Summary.t;(* opaque proof terms *)shallow:bool(* is the state trimmed down (libstack) *)}lets_cache=refNonelets_lemmas=refNonelets_program=ref(NeList.singletonDeclare.OblState.empty)letinvalidate_cache()=s_cache:=Noneletupdate_cacherfv=rf:=Somev;vletdo_if_not_cachedrffv=match!rfwith|None->rf:=Somev;fv|Somevcwhenvc!=v->rf:=Somev;fv|Some_->()letfreeze_interp_state~marshallable={system=update_caches_cache(System.freeze~marshallable);lemmas=!s_lemmas;program=!s_program;opaques=Opaques.Summary.freeze~marshallable;shallow=false;parsing=Parser.cur_state();}letunfreeze_interp_state{system;lemmas;program;parsing;opaques}=do_if_not_cacheds_cacheSystem.unfreezesystem;s_lemmas:=lemmas;s_program:=program;Opaques.Summary.unfreezeopaques;Pcoq.unfreezeparsing(* Compatibility module *)moduleDeclare_=structletget_program()=!s_programletset(pstate,pm)=s_lemmas:=pstate;s_program:=pmletget_pstate()=Option.map(LemmaStack.with_top~f:(funx->x))!s_lemmasletunfreezex=s_lemmas:=SomexexceptionNoCurrentProoflet()=CErrors.register_handlerbeginfunction|NoCurrentProof->Some(Pp.(str"No focused proof (No proof-editing in progress)."))|_->Noneendletccf=match!s_lemmaswith|None->raiseNoCurrentProof|Somex->LemmaStack.with_top~fxletcc_stackf=match!s_lemmaswith|None->raiseNoCurrentProof|Somex->fxletddf=match!s_lemmaswith|None->raiseNoCurrentProof|Somex->s_lemmas:=Some(LemmaStack.map_top~fx)letthere_are_pending_proofs()=!s_lemmas<>Noneletget_open_goals()=ccDeclare.Proof.get_open_goalsletgive_me_the_proof_opt()=Option.map(LemmaStack.with_top~f:Declare.Proof.get)!s_lemmasletgive_me_the_proof()=ccDeclare.Proof.getletget_current_proof_name()=ccDeclare.Proof.get_nameletmap_prooff=dd(Declare.Proof.map~f)letwith_current_prooff=match!s_lemmaswith|None->raiseNoCurrentProof|Somestack->letpf,res=LemmaStack.with_topstack~f:(Declare.Proof.map_fold_endline~f)inletstack=LemmaStack.map_topstack~f:(fun_->pf)ins_lemmas:=Somestack;resletreturn_proof()=ccDeclare.Proof.return_proofletreturn_partial_proof()=ccDeclare.Proof.return_partial_proofletclose_future_proof~feedback_idpf=cc(funpt->Declare.Proof.close_future_proof~feedback_idptpf)letclose_proof~opaque~keep_body_ucst_separate=cc(funpt->Declare.Proof.close_proof~opaque~keep_body_ucst_separatept)letdiscard_all()=s_lemmas:=Noneletupdate_sigma_univsugraph=dd(Declare.Proof.update_sigma_univsugraph)letget_current_context()=ccDeclare.Proof.get_current_contextletget_all_proof_names()=trycc_stackLemmaStack.get_all_proof_nameswithNoCurrentProof->[]letcopy_terminators~src~tgt=matchsrc,tgtwith|None,None->None|Some_,None->None|None,Somex->Somex|Somesrc,Sometgt->Some(LemmaStack.copy_info~src~tgt)end(* STM-specific state-handling *)moduleStm=struct(* Proof-related state, for workers; ideally the two counters would
be contained in the lemmas state themselves, as there is no need
for evar / metas to be global among proofs *)typenonrecpstate=LemmaStack.toption*int*(* Evarutil.meta_counter_summary_tag *)int(* Evd.evar_counter_summary_tag *)(* Parts of the system state that are morally part of the proof state *)letpstate{lemmas;system}=letst=System.Stm.summarysysteminlemmas,Summary.project_from_summarystEvarutil.meta_counter_summary_tag,Summary.project_from_summarystEvd.evar_counter_summary_tagletset_pstate({lemmas;system}ass)(pstate,c1,c2)={swithlemmas=Declare_.copy_terminators~src:s.lemmas~tgt:pstate;system=System.Stm.replace_summarys.systembeginletst=System.Stm.summarys.systeminletst=Summary.modify_summarystEvarutil.meta_counter_summary_tagc1inletst=Summary.modify_summarystEvd.evar_counter_summary_tagc2instend}typenon_pstate=Summary.frozen*Lib.frozenletnon_pstate{system}=letst=System.Stm.summarysysteminletst=Summary.remove_from_summarystEvarutil.meta_counter_summary_taginletst=Summary.remove_from_summarystEvd.evar_counter_summary_taginst,System.Stm.libsystemletsame_env{system=s1}{system=s2}=lets1=System.Stm.summarys1inlete1=Summary.project_from_summarys1Global.global_env_summary_taginlets2=System.Stm.summarys2inlete2=Summary.project_from_summarys2Global.global_env_summary_tagine1==e2letmake_shallowst={stwithsystem=System.Stm.make_shallowst.system;shallow=true}endmoduleDeclare=Declare_