123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338(************************************************************************)(* * 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()letcur_state()=Pcoq.freeze()letparsepsentrypa=Pcoq.unfreezeps;Pcoq.Entry.parseentrypaendmoduleSystem=structmoduleSynterp=structtypet=Lib.Synterp.frozen*Summary.Synterp.frozenletfreeze()=(Lib.Synterp.freeze(),Summary.Synterp.freeze_summaries())letunfreeze(fl,fs)=Lib.Synterp.unfreezefl;Summary.Synterp.unfreeze_summariesfsmoduleStm=structletmake_shallow(lib,summary)=Lib.Synterp.drop_objectslib,Summary.Synterp.make_marshallablesummaryletlib=fstletsummary=sndendendmoduleInterp:sigtypetvalfreeze:unit->tvalunfreeze:t->unitmoduleStm:sigvalmake_shallow:t->tvallib:t->Lib.Interp.frozenvalsummary:t->Summary.Interp.frozenvalreplace_summary:t->Summary.Interp.frozen->tendend=structtypet=Lib.Interp.frozen*Summary.Interp.frozenletfreeze()=(Lib.Interp.freeze(),Summary.Interp.freeze_summaries())letunfreeze(fl,fs)=Lib.Interp.unfreezefl;Summary.Interp.unfreeze_summariesfs(* STM-specific state manipulations *)moduleStm=structletmake_shallow(lib,summary)=Lib.Interp.drop_objectslib,Summary.Interp.make_marshallablesummaryletlib=fstletsummary=sndletreplace_summary(lib,_)summary=(lib,summary)endendletprotectfx=letsynterp_st=Synterp.freeze()inletinterp_st=Interp.freeze()intryleta=fxinSynterp.unfreezesynterp_st;Interp.unfreezeinterp_st;awithreraise->letreraise=Exninfo.capturereraiseinbeginSynterp.unfreezesynterp_st;Interp.unfreezeinterp_st;Exninfo.iraisereraiseendendmoduleSynterp=structtypet={parsing:Parser.t;system:System.Synterp.t}letfreeze()={parsing=Parser.cur_state();system=System.Synterp.freeze();}letmake_shallows={swithsystem=System.Synterp.Stm.make_shallows.system}letinit()=freeze()letunfreezest=System.Synterp.unfreezest.system;Pcoq.unfreezest.parsingendmoduleLemmaStack=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_infosrctgtendlets_cache=refNonelets_lemmas=refNonelets_program=ref(NeList.singletonDeclare.OblState.empty)moduleInterp=structtypet={system:System.Interp.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 *)}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()={system=update_caches_cache(System.Interp.freeze());lemmas=!s_lemmas;program=!s_program;opaques=Opaques.Summary.freeze();}letmake_shallows={swithsystem=System.Interp.Stm.make_shallows.system}letunfreeze_interp_state{system;lemmas;program;opaques}=do_if_not_cacheds_cacheSystem.Interp.unfreezesystem;s_lemmas:=lemmas;s_program:=program;Opaques.Summary.unfreezeopaquesendtypet={synterp:Synterp.t;interp:Interp.t}letfreeze_full_state()={synterp=Synterp.freeze();interp=Interp.freeze_interp_state();}letunfreeze_full_statest=Synterp.unfreezest.synterp;Interp.unfreeze_interp_statest.interp(* 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{interp={lemmas;system}}=letst=System.Interp.Stm.summarysysteminlemmas,Summary.Interp.project_from_summarystEvarutil.meta_counter_summary_tag,Summary.Interp.project_from_summarystEvd.evar_counter_summary_tagletset_pstate({interp={lemmas;system}}ass)(pstate,c1,c2)={swithinterp={s.interpwithlemmas=Declare_.copy_terminators~src:s.interp.lemmas~tgt:pstate;system=System.Interp.Stm.replace_summarys.interp.systembeginletst=System.Interp.Stm.summarys.interp.systeminletst=Summary.Interp.modify_summarystEvarutil.meta_counter_summary_tagc1inletst=Summary.Interp.modify_summarystEvd.evar_counter_summary_tagc2instend}}typenon_pstate=Summary.Synterp.frozen*Lib.Synterp.frozen*Summary.Interp.frozen*Lib.Interp.frozenletnon_pstate{synterp;interp}=letsystem=interp.systeminletst=System.Interp.Stm.summarysysteminletst=Summary.Interp.remove_from_summarystEvarutil.meta_counter_summary_taginletst=Summary.Interp.remove_from_summarystEvd.evar_counter_summary_taginSystem.Synterp.Stm.summarysynterp.system,System.Synterp.Stm.libsynterp.system,st,System.Interp.Stm.libsystemletsame_env{interp={system=s1}}{interp={system=s2}}=lets1=System.Interp.Stm.summarys1inlete1=Summary.Interp.project_from_summarys1Global.global_env_summary_taginlets2=System.Interp.Stm.summarys2inlete2=Summary.Interp.project_from_summarys2Global.global_env_summary_tagine1==e2letmake_shallowst={interp=Interp.make_shallowst.interp;synterp=Synterp.make_shallowst.synterp}endmoduleDeclare=Declare_