123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149(************************************************************************)(* * 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 *)(** 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|Nonewhenopts.Coqargs.pre.Coqargs.boot->()|None->Envars.set_coqlib~fail:(funmsg->CErrors.user_errPp.(strmsg));|Somes->Envars.set_user_coqlibsletprint_queryopts=letopenCoqargsinfunction|PrintVersion->Usage.version()|PrintMachineReadableVersion->Usage.machine_readable_version()|PrintWhere->let()=init_coqliboptsinprint_endline(Envars.coqlib())|PrintHelph->Usage.print_usagestderrh|PrintConfig->let()=init_coqliboptsinEnvars.print_configstdoutCoq_config.all_src_dirsletparse_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_runtimeopts=letopenCoqargsinLib.init();init_coqlibopts;ifopts.post.memory_statthenat_exitprint_memory_stat;Mltop.init_known_plugins();(* Configuration *)Global.set_engagementopts.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 *)letml_load_path,vo_load_path=Coqargs.build_load_pathoptsinList.iterMltop.add_ml_dirml_load_path;List.iterLoadpath.add_vo_pathvo_load_path;injection_commandsoptsletrequire_file(dir,from,exp)=letmp=Libnames.qualid_of_stringdirinletmfrom=Option.mapLibnames.qualid_of_stringfrominFlags.silently(Vernacentries.vernac_requiremfromexp)[mp]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