Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file parTactic.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166(**************************************************************************)(* *)(* VSCoq *)(* *)(* Copyright INRIA and contributors *)(* (see version control and README file for authors & dates) *)(* *)(**************************************************************************)(* *)(* This file is distributed under the terms of the MIT License. *)(* See LICENSE file. *)(* *)(**************************************************************************)openTypesletLoglog=Log.mk_log"parTactic"typesentence_id=Stateid.tmoduleTacticJob=structtypesolution=|SolvedofConstr.t*UState.t|NoProgress|ErrorofPp.ttypeupdate_request=|UpdateSolutionofEvar.t*solution|AppendFeedbackofFeedback.route_id*sentence_id*(Feedback.level*Loc.toption*Quickfix.tlist*Pp.t)letappendFeedback(rid,id)fb=AppendFeedback(rid,id,fb)typet={state:Vernacstate.t;ast:ComTactic.interpretable;goalno:int;goal:Evar.t;name:string}letname="tactic"letbinary_name="vscoqtop_tactic_worker.opt"letinitial_pool_size=2endmoduleTacticWorker=DelegationManager.MakeWorker(TacticJob)letassign_tac~abstractres:unitProofview.tactic=Proofview.(Goal.enterbeginfung->letgid=Goal.goalgintryletpt,uc=List.assocgidresinletopenNotationsinletpush_statectx=Proofview.tclEVARMAP>>=funsigma->Proofview.Unsafe.tclEVARS(Evd.merge_universe_contextsigmactx)in(ifabstractthenAbstract.tclABSTRACTNoneelse(funx->x))(push_stateuc<*>Tactics.exact_no_check(EConstr.of_constrpt))withNot_found->log@@"nothing for "^Pp.string_of_ppcmds@@Evar.printgid;tclUNIT()end)[%%ifcoq="8.18"||coq="8.19"]letcommand_focus=Proof.new_focus_kind()[%%else]letcommand_focus=Proof.new_focus_kind"vscoq_command_focus"[%%endif][%%ifcoq="8.18"||coq="8.19"||coq="8.20"]letget_ustatesigma=Evd.evar_universe_contextsigma[%%else]letget_ustatesigma=Evd.ustatesigma[%%endif]letworker_solve_one_goal{TacticJob.state;ast;goalno;goal}~send_back=letfocus_cond=Proof.no_condcommand_focusinletpr_goalg=string_of_int(Evar.reprg)inVernacstate.unfreeze_full_statestate;tryVernacstate.LemmaStack.with_top(Option.getstate.Vernacstate.interp.lemmas)~f:(funpstate->letpstate=Declare.Proof.mappstate~f:(Proof.focusfocus_cond()goalno)inletpstate=ComTactic.solve~pstateGoal_select.SelectAll~info:Noneast~with_end_tac:falseinlet{Proof.sigma}=Declare.Proof.foldpstate~f:Proof.datainletEvarInfoevi=Evd.findsigmagoalinmatchEvd.(evar_bodyevi)with|Evd.Evar_empty->log@@"no progress on goal "^pr_goalgoal;send_back(TacticJob.UpdateSolution(goal,TacticJob.NoProgress))|Evd.Evar_definedt->lett=Evarutil.nf_evarsigmatinletevars=Evarutil.undefined_evars_of_termsigmatinifEvar.Set.is_emptyevarsthenlett=EConstr.Unsafe.to_constrtinlog@@"closed goal "^pr_goalgoal;send_back(TacticJob.UpdateSolution(goal,TacticJob.Solved(t,get_ustatesigma)))elseCErrors.user_errPp.(str"The par: selector requires a tactic that makes no progress or fully"++str" solves the goal and leaves no unresolved existential variables. The following"++str" existentials remain unsolved: "++prlist(Termops.pr_existential_key(Global.env())sigma)(Evar.Set.elementsevars)))withewhenCErrors.noncriticale->send_back(TacticJob.UpdateSolution(goal,TacticJob.ErrorPp.(CErrors.printe++spc()++str"(for subgoal "++intgoalno++str")")))letfeedback_id=ref(0,Stateid.dummy)letset_id_for_feedbackridsid=feedback_id:=(rid,sid)letinterp_par~pstate~infoast~abstract~with_end_tac:Declare.Proof.t=letstate=Vernacstate.freeze_full_state()inletstate=Vernacstate.Stm.make_shallowstateinletqueue=Queue.create()inletevents,job_ids=List.split@@Declare.Proof.foldpstate~f:(funp->(Proof.datap).Proof.goals|>CList.map_i(fungoalnogoal->letjob={TacticJob.state;ast;goalno=goalno+1;goal;name=string_of_int(Evar.reprgoal)}inletjob_id=DelegationManager.mk_job_handle!feedback_idinlete=TacticWorker.worker_available~feedback_cleanup:(fun_->())(* not really correct, since there is a cleanup to be done, but it concern a sel loop which is dead (we don't come back to it), so we can ignore the problem *)~jobs:queue~fork_action:worker_solve_one_goalinQueue.push(job_id,Sel.Event.get_cancellation_handlee,job)queue;e,job_id)0)inletrecwaitaccevs=log@@"waiting for events: "^string_of_int@@Sel.Todo.sizeevs;letmore_ready,evs=Sel.pop_optevsinmatchmore_readywith|None->ifSel.Todo.is_emptyevsthen(log@@"done waiting for tactic workers";acc)elsewaitaccevs(* should be assert false *)|Someev->letresult,more_events=TacticWorker.handle_eventevinletevs=Sel.Todo.addevsmore_eventsinmatchresultwith|None->waitaccevs|Some(TacticJob.UpdateSolution(ev,TacticJob.Solved(c,u)))->log@@"got solution for evar "^Pp.string_of_ppcmds@@Evar.printev;waitaccevs|Some(TacticJob.AppendFeedback_)->log@@"got feedback";waitaccevs|Some(TacticJob.UpdateSolution(ev,TacticJob.NoProgress))->log@@"got no progress for "^Pp.string_of_ppcmds@@Evar.printev;waitaccevs|Some(TacticJob.UpdateSolution(ev,TacticJob.Errorerr))->log@@"got error for "^Pp.string_of_ppcmds@@Evar.printev;List.iterDelegationManager.cancel_jobjob_ids;CErrors.user_errerrinletresults=wait[]Sel.Todo.(addemptyevents)inDeclare.Proof.mappstate~f:(funp->letp,_,()=Proof.run_tactic(Global.env())(assign_tac~abstractresults)pinp)[@@warning"-27"](* FIXME: why are info and with_end_tac unused? *)let()=ComTactic.set_par_implementationinterp_parmoduleTacticWorkerProcess=structtypeoptions=TacticWorker.optionsletparse_options=TacticWorker.parse_optionsletmain~st:initial_vernac_stateoptions=letsend_back,job=TacticWorker.setup_plumbingoptionsinworker_solve_one_goaljob~send_back;exit0[@@warning"-27"](* FIXME: why is st unused? *)letlog=TacticWorker.logend