123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198(************************************************************************)(* * 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) *)(************************************************************************)(** GC tweaking *)(** Work around a broken Gc.set function in released OCaml versions between
4.08.0 and 4.11.1 inclusive. *)letgc_set:Gc.control->unit=letopenGcinletfixed_setcontrol=let{custom_major_ratio;custom_minor_ratio;custom_minor_max_size;_}=controlinletcontrol={controlwithcustom_major_ratio=custom_major_ratiolsr1;custom_minor_ratio=custom_minor_ratiolsr1;custom_minor_max_size=custom_minor_max_sizelsr1;}inGc.setcontrolin(* the fix has been backported to all of these branches, so any
version after these will be fixed. *)matchCoq_config.caml_version_numswith|[4;11;1]|[4;11;0]|[4;10;2]|[4;10;1]|[4;10;0]|[4;09;1]|[4;09;0]|[4;08;1]|[4;08;0]->fixed_set|_->Gc.set(** Coq is a heavy user of persistent data structures and symbolic ASTs, so the
minor heap is heavily solicited. Unfortunately, the default size is far too
small, so we enlarge it a lot (128 times larger).
To better handle huge memory consumers, we also augment the default major
heap increment and the GC pressure coefficient.
*)letset_gc_policy()=gc_set{(Gc.get())withGc.minor_heap_size=32*1024*1024(* 32Mwords x 8 bytes/word = 256Mb *);Gc.space_overhead=120}letset_gc_best_fit()=gc_set{(Gc.get())withGc.allocation_policy=2(* best-fit *);Gc.space_overhead=200}letinit_gc()=try(* OCAMLRUNPARAM environment variable is set.
* In that case, we let ocamlrun to use the values provided by the user.
*)ignore(Sys.getenv"OCAMLRUNPARAM")withNot_found->(* OCAMLRUNPARAM environment variable is not set.
* In this case, we put in place our preferred configuration.
*)set_gc_policy();ifCoq_config.caml_version_nums>=[4;10;0]thenset_gc_best_fit()else()letinit_ocaml()=CProfile.init_profile();init_gc();Sys.catch_breakfalse(* Ctrl-C is fatal during the initialisation *)letinit_coqlibopts=matchopts.Coqargs.config.Coqargs.coqlibwith|None->()|Somes->Boot.Env.set_coqlibsletprint_queryopts=letopenCoqargsinfunction|PrintVersion->Boot.Usage.version()|PrintMachineReadableVersion->Boot.Usage.machine_readable_version()|PrintWhere->letenv=Boot.Env.init()inletcoqlib=Boot.Env.coqlibenv|>Boot.Path.to_stringinprint_endlinecoqlib|PrintHelph->Boot.Usage.print_usagestderrh|PrintConfig->let()=init_coqliboptsinEnvars.print_configstdoutletparse_arguments~parse_extra~usage?(initial_args=Coqargs.default)()=letopts,extras=Coqargs.parse_args~usage~init:initial_args(List.tl(Array.to_listSys.argv))inletcustomopts,extras=parse_extraextrasinifnot(CList.is_emptyextras)thenbeginprerr_endline("Don't know what to do with "^String.concat" "extras);prerr_endline"See -help for the list of supported options";exit1end;matchopts.Coqargs.mainwith|Coqargs.Queriesq->List.iter(print_queryopts)q;exit0|Coqargs.Run->opts,customoptsletprint_memory_stat()=letopenPpin(* -m|--memory from the command-line *)Feedback.msg_notice(str"total heap size = "++int(CObj.heap_size_kb())++str" kbytes"++fnl());(* operf-macro interface:
https://github.com/OCamlPro/operf-macro *)tryletfn=Sys.getenv"OCAML_GC_STATS"inletoc=open_outfninGc.print_statoc;close_outocwith_->()letinit_load_pathsopts=letopenCoqargsinletboot_ml_path,boot_vo_path=ifopts.pre.bootthen[],[]elseletcoqenv=Boot.Env.init()inCoqloadpath.init_load_path~coqenvinletml_path=opts.pre.ml_includes@boot_ml_pathinList.iterMltop.add_ml_dir(List.revml_path);List.iterLoadpath.add_vo_pathboot_vo_path;List.iterLoadpath.add_vo_pathopts.pre.vo_includes;letenv_ocamlpath=try[Sys.getenv"OCAMLPATH"]withNot_found->[]inletenv_ocamlpath=ml_path@env_ocamlpathinletocamlpathsep=ifSys.unixthen":"else";"inletenv_ocamlpath=String.concatocamlpathsepenv_ocamlpathinFindlib.init~env_ocamlpath()letinit_runtimeopts=letopenCoqargsinLib.init();init_coqlibopts;ifopts.post.memory_statthenat_exitprint_memory_stat;(* Configuration *)Global.set_impredicative_setopts.config.logic.impredicative_set;Global.set_indices_matteropts.config.logic.indices_matter;Global.set_check_universes(notopts.config.logic.type_in_type);Global.set_VMopts.config.enable_VM;Flags.set_native_compiler(matchopts.config.native_compilerwithNativeOff->false|NativeOn_->true);Global.set_native_compiler(matchopts.config.native_compilerwithNativeOff->false|NativeOn_->true);(* Native output dir *)Nativelib.output_dir:=opts.config.native_output_dir;Nativelib.include_dirs:=opts.config.native_include_dirs;(* Paths for loading stuff *)init_load_pathsopts;injection_commandsoptsletrequire_file(dir,from,exp)=letmp=Libnames.qualid_of_stringdirinletmfrom=Option.mapLibnames.qualid_of_stringfrominletexp=Option.map(fune->e,None)expinFlags.silently(Vernacentries.vernac_requiremfromexp)[mp,Vernacexpr.ImportAll]letwarn_no_native_compiler=CWarnings.create~name:"native-compiler-disabled"~category:"native-compiler"Pp.(funs->strbrk"Native compiler is disabled,"++strbrk" -native-compiler "++strbrks++strbrk" option ignored.")letwarn_deprecated_native_compiler=CWarnings.create~name:"deprecated-native-compiler-option"~category:"deprecated"(fun()->Pp.strbrk"The native-compiler option is deprecated. To compile native \
files ahead of time, use the coqnative binary instead.")lethandle_injection=letopenCoqargsinfunction|RequireInjectionr->require_filer|OptionInjectiono->set_optiono|WarnNoNatives->warn_no_native_compilers|WarnNativeDeprecated->warn_deprecated_native_compiler()letstart_library~topinjections=Flags.verboselyDeclaremods.start_librarytop;List.iterhandle_injectioninjections