123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310(************************************************************************)(* * 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) *)(************************************************************************)moduleSynterp=structtypet=Lib.Synterp.frozen*Summary.Synterp.frozenletfreeze()=(Lib.Synterp.freeze(),Summary.Synterp.freeze_summaries())letunfreeze(fl,fs)=Lib.Synterp.unfreezefl;Summary.Synterp.unfreeze_summariesfsletparsing(_fl,fs)=Summary.Synterp.project_from_summaryfsPcoq.parser_summary_tagletinit()=freeze()moduleStm=structletmake_shallow(lib,summary)=Lib.Synterp.drop_objectslib,Summary.Synterp.make_marshallablesummaryletlib=fstletsummary=sndendendmoduleInterp_system: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_summariesfsmoduleStm=structletmake_shallow(lib,summary)=Lib.Interp.drop_objectslib,Summary.Interp.make_marshallablesummaryletlib=fstletsummary=sndletreplace_summary(lib,_)summary=(lib,summary)endendmoduleSystem=structletprotectfx=letsynterp_st=Synterp.freeze()inletinterp_st=Interp_system.freeze()intryleta=fxinSynterp.unfreezesynterp_st;Interp_system.unfreezeinterp_st;awithreraise->letreraise=Exninfo.capturereraiseinbeginSynterp.unfreezesynterp_st;Interp_system.unfreezeinterp_st;Exninfo.iraisereraiseendendmoduleLemmaStack=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=structmoduleSystem=Interp_systemtypet={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 *)}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.freeze());lemmas=!s_lemmas;program=!s_program;opaques=Opaques.Summary.freeze();}letmake_shallows={swithsystem=System.Stm.make_shallows.system}letunfreeze_interp_state{system;lemmas;program;opaques}=do_if_not_cacheds_cacheSystem.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=NewProfile.profile"unfreeze_full_state"(fun()->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_proofletclose_future_proof~feedback_idpf=NewProfile.profile"close_future_proof"(fun()->cc(funpt->Declare.Proof.close_future_proof~feedback_idptpf))()letclose_proof~opaque~keep_body_ucst_separate=NewProfile.profile"close_proof"(fun()->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=Interp.System.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=Interp.System.Stm.replace_summarys.interp.systembeginletst=Interp.System.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=Interp.System.Stm.summarysysteminletst=Summary.Interp.remove_from_summarystEvarutil.meta_counter_summary_taginletst=Summary.Interp.remove_from_summarystEvd.evar_counter_summary_taginSynterp.Stm.summarysynterp,Synterp.Stm.libsynterp,st,Interp.System.Stm.libsystemletsame_env{interp={system=s1}}{interp={system=s2}}=lets1=Interp.System.Stm.summarys1inlete1=Summary.Interp.project_from_summarys1Global.global_env_summary_taginlets2=Interp.System.Stm.summarys2inlete2=Summary.Interp.project_from_summarys2Global.global_env_summary_tagine1==e2letmake_shallowst={interp=Interp.make_shallowst.interp;synterp=Synterp.Stm.make_shallowst.synterp}endmoduleDeclare=Declare_