123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \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) *)(************************************************************************)(************************************************************************)(* Coq serialization API/Plugin *)(* Copyright 2016-2019 MINES ParisTech *)(************************************************************************)(* Status: Very Experimental *)(************************************************************************)(* Init options for coq *)typeasync_flags={enable_async:stringoption;deep_edits:bool;async_workers:int;error_recovery:bool}typecoq_opts={fb_handler:Format.formatter->Feedback.feedback->unit(* callback to handle async feedback *);ml_load:(string->unit)option(* callback to load cma/cmo files *);debug:bool(* Enable Coq Debug mode *);allow_sprop:bool(* Allow SProp *);indices_matter:bool;ml_path:stringlist;vo_path:Loadpath.vo_pathlist(** From -R and -Q options usually *)}(**************************************************************************)(* Low-level, internal Coq initialization *)(**************************************************************************)(* Reference to feedback_handler *)letfb=ref0(* mirroring what's done in Coqinit.init_runtime () *)letinit_runtimeopts=(* Core Coq initialization *)Lib.init();(* This is only needed when statically linking *)Mltop.init_known_plugins();(* This should be configurable somehow. *)Global.set_engagementDeclarations.PredicativeSet;Global.set_indices_matteropts.indices_matter;(* --allow-sprop in agreement with coq v8.11 *)Global.set_allow_spropopts.allow_sprop;(* XXX fixme *)Flags.set_native_compilerfalse;(* Loadpath is early in the state now *)(* This is for defaults, in case we go back to the protocol setting it *)(* let dft_ml, dft_vo =
* Serapi.Serapi_paths.(coq_loadpath_default ~implicit:true ~coq_path:Coq_config.coqlib)
* in
* let ml_load_path = Option.default dft_ml opts.ml_path in
* let vo_load_path = Option.default dft_vo opts.vo_path in *)List.iterMltop.add_ml_diropts.ml_path;List.iterLoadpath.add_vo_pathopts.vo_path;()letcoq_initoptsout_fmt=ifopts.debugthenbeginPrintexc.record_backtracetrue;(* XXX Use CDebug *)(* Flags.debug := true; *)end;letload_obj=Sertop_loader.plugin_handleropts.ml_loadin(* XXX: We may not have to set path once the issue in Coq upstream is fixed. *)letadd_dir=Sertop_loader.add_ml_pathin(* Custom toplevel is used for bytecode-to-js dynlink *)letser_mltop:Mltop.toplevel=letopenMltopin{load_obj(* We ignore all the other operations for now. *);add_dir;ml_loop=(fun_->())}inMltop.set_topser_mltop;init_runtimeopts;(**************************************************************************)(* Feedback setup *)(**************************************************************************)(* Initialize logging. *)fb:=Feedback.add_feeder(opts.fb_handlerout_fmt);(**************************************************************************)(* Start the STM!! *)(**************************************************************************)Stm.init_core();(* End of initialization *)()letupdate_fb_handler~pp_feedout_fmt=Feedback.del_feeder!fb;fb:=Feedback.add_feeder(pp_feedout_fmt)(******************************************************************************)(* Async setup *)(******************************************************************************)(* Set async flags; IMPORTANT, this has to happen before STM.init () ! *)letprocess_stm_flagsopts=letstm_opts=Stm.AsyncOpts.default_optsin(* Process error resilience *)letasync_proofs_tac_error_resilience,async_proofs_cmd_error_resilience=ifopts.error_recoverythen`All,trueelse`None,falseinletstm_opts={stm_optswithasync_proofs_tac_error_resilience;async_proofs_cmd_error_resilience}in(* Enable async mode if requested *)Option.cata(funcoqtop->letopenStm.AsyncOptsinletopts={stm_optswithasync_proofs_mode=APon(* Imitate CoqIDE *);async_proofs_never_reopen_branch=notopts.deep_edits;async_proofs_n_workers=opts.async_workers;async_proofs_n_tacworkers=opts.async_workers}in(* async_proofs_worker_priority); *)(* Whether to forward Glob output to the IDE. *)(* let _dump_opt = "-no-glob" in
* AsyncTaskQueue.async_proofs_flags_for_workers := []; *)(* The -no-glob for workers seems broken recently *)AsyncTaskQueue.async_proofs_flags_for_workers:=[];CoqworkmgrApi.(initHigh);(* Uh! XXXX *)fori=0toArray.lengthSys.argv-1doArray.setSys.argvi"-m"done;Array.setSys.argv0coqtop;opts)stm_optsopts.enable_async