This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
<!DOCTYPE html>
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>IBase__Utils (infer.IBase__Utils)</title><linkrel="stylesheet"href="../../odoc.css"/><metacharset="utf-8"/><metaname="generator"content="odoc 1.5.1"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><scriptsrc="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><divclass="content"><header><nav><ahref="../index.html">Up</a>–<ahref="../index.html">infer</a>» IBase__Utils</nav><h1>Module <code>IBase__Utils</code></h1></header><dl><dtclass="spec value"id="val-find_files"><ahref="#val-find_files"class="anchor"></a><code><spanclass="keyword">val</span> find_files : <span>path:string</span><span>-></span><span>extension:string</span><span>-></span><span>string list</span></code></dt><dd><p>recursively traverse a path for files ending with a given extension</p></dd></dl><dl><dtclass="spec value"id="val-fold_folders"><ahref="#val-fold_folders"class="anchor"></a><code><spanclass="keyword">val</span> fold_folders : <span>init:<spanclass="type-var">'acc</span></span><span>-></span><span>f:<span>(<spanclass="type-var">'acc</span><span>-></span> string <span>-></span><spanclass="type-var">'acc</span>)</span></span><span>-></span><span>path:string</span><span>-></span><spanclass="type-var">'acc</span></code></dt><dd><p>recursively traverse a path for folders, returning resuls by a given fold function</p></dd></dl><dl><dtclass="spec value"id="val-string_crc_hex32"><ahref="#val-string_crc_hex32"class="anchor"></a><code><spanclass="keyword">val</span> string_crc_hex32 : string <span>-></span> string</code></dt><dd><p>Compute a 32-character hexadecimal crc using the Digest module</p></dd></dl><dl><dtclass="spec value"id="val-read_file"><ahref="#val-read_file"class="anchor"></a><code><spanclass="keyword">val</span> read_file : string <span>-></span><span><span>(<span>string list</span>,string)</span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Result.t</span></code></dt><dd><p>read a source file and return a list of lines</p></dd></dl><dl><dtclass="spec value"id="val-normalize_path_from"><ahref="#val-normalize_path_from"class="anchor"></a><code><spanclass="keyword">val</span> normalize_path_from : <span>root:string</span><span>-></span> string <span>-></span> string * string</code></dt><dd><p><code>normalize_path_from ~root path</code> removes ".." and "." parts of <code>root/path</code> when possible and returns the new <code>root</code> and <code>path</code>, eg if <code>root = "r"</code> and <code>path = "a/../../../foo/./bar"</code> then the result is <code>("../foo/bar", ".")</code> (in particular "r/a/../../../foo/./bar" and "./../foo/bar" represent the same file)</p></dd></dl><dl><dtclass="spec value"id="val-normalize_path"><ahref="#val-normalize_path"class="anchor"></a><code><spanclass="keyword">val</span> normalize_path : string <span>-></span> string</code></dt><dd><p>Normalize a path without a root</p></dd></dl><dl><dtclass="spec value"id="val-filename_to_absolute"><ahref="#val-filename_to_absolute"class="anchor"></a><code><spanclass="keyword">val</span> filename_to_absolute : <span>root:string</span><span>-></span> string <span>-></span> string</code></dt><dd><p>Convert a filename to an absolute one if it is relative, and normalize "." and ".."</p></dd></dl><dl><dtclass="spec value"id="val-filename_to_relative"><ahref="#val-filename_to_relative"class="anchor"></a><code><spanclass="keyword">val</span> filename_to_relative : <span>?⁠force_full_backtrack:bool</span><span>-></span><span>?⁠backtrack:int</span><span>-></span><span>root:string</span><span>-></span> string <span>-></span><span>string option</span></code></dt><dd><p>Convert an absolute filename to one relative to a root directory. Returns <code>None</code> if filename is not under root. The backtrack level sets the maximum level of steps in the parent directories to search for a common prefix</p></dd></dl><dl><dtclass="spec type"id="type-outfile"><ahref="#type-outfile"class="anchor"></a><code><spanclass="keyword">type</span> outfile</code><code> = </code><code>{</code><tableclass="record"><trid="type-outfile.fname"class="anchored"><tdclass="def field"><ahref="#type-outfile.fname"class="anchor"></a><code>fname : string;</code></td><tdclass="doc"><p>name of the file</p></td></tr><trid="type-outfile.out_c"class="anchored"><tdclass="def field"><ahref="#type-outfile.out_c"class="anchor"></a><code>out_c : <ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Out_channel.t;</code></td><tdclass="doc"><p>output channel</p></td></tr><trid="type-outfile.fmt"class="anchored"><tdclass="def field"><ahref="#type-outfile.fmt"class="anchor"></a><code>fmt : Stdlib.Format.formatter;</code></td><tdclass="doc"><p>formatter for printing</p></td></tr></table><code>}</code></dt><dd><p>type for files used for printing</p></dd></dl><dl><dtclass="spec value"id="val-create_outfile"><ahref="#val-create_outfile"class="anchor"></a><code><spanclass="keyword">val</span> create_outfile : string <span>-></span><span><ahref="index.html#type-outfile">outfile</a> option</span></code></dt><dd><p>create an outfile for the command line, the boolean indicates whether to do demangling when closing the file</p></dd></dl><dl><dtclass="spec value"id="val-close_outf"><ahref="#val-close_outf"class="anchor"></a><code><spanclass="keyword">val</span> close_outf : <ahref="index.html#type-outfile">outfile</a><span>-></span> unit</code></dt><dd><p>close an outfile</p></dd></dl><dl><dtclass="spec value"id="val-directory_fold"><ahref="#val-directory_fold"class="anchor"></a><code><spanclass="keyword">val</span> directory_fold : <span>(<spanclass="type-var">'a</span><span>-></span> string <span>-></span><spanclass="type-var">'a</span>)</span><span>-></span><spanclass="type-var">'a</span><span>-></span> string <span>-></span><spanclass="type-var">'a</span></code></dt><dd><p>Functional fold function over all the files of a directory</p></dd></dl><dl><dtclass="spec value"id="val-directory_iter"><ahref="#val-directory_iter"class="anchor"></a><code><spanclass="keyword">val</span> directory_iter : <span>(string <span>-></span> unit)</span><span>-></span> string <span>-></span> unit</code></dt><dd><p>Functional iter function over all the files of a directory</p></dd></dl><dl><dtclass="spec value"id="val-directory_is_empty"><ahref="#val-directory_is_empty"class="anchor"></a><code><spanclass="keyword">val</span> directory_is_empty : string <span>-></span> bool</code></dt><dd><p>Returns true if a given directory is empty. The directory is assumed to exist.</p></dd></dl><dl><dtclass="spec value"id="val-read_json_file"><ahref="#val-read_json_file"class="anchor"></a><code><spanclass="keyword">val</span> read_json_file : string <span>-></span><span><span>(Yojson.Basic.t,string)</span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Result.t</span></code></dt><dtclass="spec value"id="val-read_safe_json_file"><ahref="#val-read_safe_json_file"class="anchor"></a><code><spanclass="keyword">val</span> read_safe_json_file : string <span>-></span><span><span>(Yojson.Safe.t,string)</span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Result.t</span></code></dt><dtclass="spec value"id="val-with_file_in"><ahref="#val-with_file_in"class="anchor"></a><code><spanclass="keyword">val</span> with_file_in : string <span>-></span><span>f:<span>(<ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.In_channel.t <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><spanclass="type-var">'a</span></code></dt><dtclass="spec value"id="val-with_file_out"><ahref="#val-with_file_out"class="anchor"></a><code><spanclass="keyword">val</span> with_file_out : string <span>-></span><span>f:<span>(<ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Out_channel.t <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><spanclass="type-var">'a</span></code></dt><dtclass="spec value"id="val-with_intermediate_temp_file_out"><ahref="#val-with_intermediate_temp_file_out"class="anchor"></a><code><spanclass="keyword">val</span> with_intermediate_temp_file_out : string <span>-></span><span>f:<span>(<ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Out_channel.t <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><spanclass="type-var">'a</span></code></dt><dd><p>like <code>with_file_out</code> but uses a fresh intermediate temporary file and rename to avoid write-write races</p></dd></dl><dl><dtclass="spec value"id="val-write_json_to_file"><ahref="#val-write_json_to_file"class="anchor"></a><code><spanclass="keyword">val</span> write_json_to_file : string <span>-></span> Yojson.Basic.t <span>-></span> unit</code></dt><dtclass="spec value"id="val-consume_in"><ahref="#val-consume_in"class="anchor"></a><code><spanclass="keyword">val</span> consume_in : <ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.In_channel.t <span>-></span> unit</code></dt><dd><p>consume and ignore all the lines from the channel until End_of_file is reached</p></dd></dl><dl><dtclass="spec value"id="val-echo_in"><ahref="#val-echo_in"class="anchor"></a><code><spanclass="keyword">val</span> echo_in : <ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.In_channel.t <span>-></span> unit</code></dt><dd><p>echo the lines we get to stdout until End_of_file is reached</p></dd></dl><dl><dtclass="spec value"id="val-with_channel_in"><ahref="#val-with_channel_in"class="anchor"></a><code><spanclass="keyword">val</span> with_channel_in : <span>f:<span>(string <span>-></span> unit)</span></span><span>-></span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.In_channel.t <span>-></span> unit</code></dt><dtclass="spec value"id="val-with_process_in"><ahref="#val-with_process_in"class="anchor"></a><code><spanclass="keyword">val</span> with_process_in : string <span>-></span><span>(<ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.In_channel.t <span>-></span><spanclass="type-var">'a</span>)</span><span>-></span><spanclass="type-var">'a</span> * <ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Unix.Exit_or_signal.t</code></dt><dtclass="spec value"id="val-create_dir"><ahref="#val-create_dir"class="anchor"></a><code><spanclass="keyword">val</span> create_dir : string <span>-></span> unit</code></dt><dd><p>recursively create a directory if it does not exist already</p></dd></dl><dl><dtclass="spec value"id="val-out_channel_create_with_dir"><ahref="#val-out_channel_create_with_dir"class="anchor"></a><code><spanclass="keyword">val</span> out_channel_create_with_dir : <ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Filename.t <span>-></span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Out_channel.t</code></dt><dd><p>create an out channel with creating missing directories</p></dd></dl><dl><dtclass="spec value"id="val-realpath"><ahref="#val-realpath"class="anchor"></a><code><spanclass="keyword">val</span> realpath : <span>?⁠warn_on_error:bool</span><span>-></span> string <span>-></span> string</code></dt><dd><p><code>realpath warn_on_error path</code> returns path with all symbolic links resolved. It caches results of previous calls to avoid expensive system calls. WARNING: If warn_on_error is false, no warning will be shown whenever an error occurs for the given path (e.g. if it does not exist).</p></dd></dl><dl><dtclass="spec value"id="val-suppress_stderr2"><ahref="#val-suppress_stderr2"class="anchor"></a><code><spanclass="keyword">val</span> suppress_stderr2 : <span>(<spanclass="type-var">'a</span><span>-></span><spanclass="type-var">'b</span><span>-></span><spanclass="type-var">'c</span>)</span><span>-></span><spanclass="type-var">'a</span><span>-></span><spanclass="type-var">'b</span><span>-></span><spanclass="type-var">'c</span></code></dt><dd><p>wraps a function expecting 2 arguments in another that temporarily redirects stderr to /dev/null for the duration of the function call</p></dd></dl><dl><dtclass="spec value"id="val-rmtree"><ahref="#val-rmtree"class="anchor"></a><code><spanclass="keyword">val</span> rmtree : string <span>-></span> unit</code></dt><dd><p><code>rmtree path</code> removes <code>path</code> and, if <code>path</code> is a directory, recursively removes its contents</p></dd></dl><dl><dtclass="spec value"id="val-try_finally_swallow_timeout"><ahref="#val-try_finally_swallow_timeout"class="anchor"></a><code><spanclass="keyword">val</span> try_finally_swallow_timeout : <span>f:<span>(unit <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><span>finally:<span>(unit <span>-></span> unit)</span></span><span>-></span><spanclass="type-var">'a</span></code></dt><dd><p>Calls <code>f</code> then <code>finally</code> even if <code>f</code> raised an exception. The original exception is reraised afterwards. Where possible use <code>SymOp.try_finally</code> to avoid swallowing timeouts.</p></dd></dl><dl><dtclass="spec value"id="val-better_hash"><ahref="#val-better_hash"class="anchor"></a><code><spanclass="keyword">val</span> better_hash : <spanclass="type-var">'a</span><span>-></span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.Caml.Digest.t</code></dt><dd><p>Hashtbl.hash only hashes the first 10 meaningful values, <code>better_hash</code> uses everything.</p></dd></dl><dl><dtclass="spec value"id="val-unlink_file_on_exit"><ahref="#val-unlink_file_on_exit"class="anchor"></a><code><spanclass="keyword">val</span> unlink_file_on_exit : string <span>-></span> unit</code></dt><dd><p>delete <code>temporary</code> file on exit</p></dd></dl><dl><dtclass="spec value"id="val-strip_balanced_once"><ahref="#val-strip_balanced_once"class="anchor"></a><code><spanclass="keyword">val</span> strip_balanced_once : <span>drop:<span>(char <span>-></span> bool)</span></span><span>-></span> string <span>-></span> string</code></dt><dd><p>drop at most one layer of well-balanced first and last characters satisfying <code>drop</code> from the string; for instance, <code>strip_balanced ~drop:(function | 'a' | 'x' -> true | _ -> false) "xaabax"</code> returns "aaba"</p></dd></dl><dl><dtclass="spec value"id="val-assoc_of_yojson"><ahref="#val-assoc_of_yojson"class="anchor"></a><code><spanclass="keyword">val</span> assoc_of_yojson : Yojson.Basic.t <span>-></span><span>src:string</span><span>-></span><span><span>(string,Yojson.Basic.t)</span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.List.Assoc.t</span></code></dt><dd><p>Verify we have a json object (or empty list) and return the corresponding assoc list. Otherwise die with a message including src.</p></dd></dl><dl><dtclass="spec value"id="val-string_of_yojson"><ahref="#val-string_of_yojson"class="anchor"></a><code><spanclass="keyword">val</span> string_of_yojson : Yojson.Basic.t <span>-></span><span>src:string</span><span>-></span> string</code></dt><dd><p>Verify we have a json string and return the corresponding ocaml string. Otherwise die with a message including src.</p></dd></dl><dl><dtclass="spec value"id="val-string_list_of_yojson"><ahref="#val-string_list_of_yojson"class="anchor"></a><code><spanclass="keyword">val</span> string_list_of_yojson : Yojson.Basic.t <span>-></span><span>src:string</span><span>-></span><span>string list</span></code></dt><dd><p>Verify we have a json list of strings and return the corresponding ocaml string list. Otherwise die with a message including src.</p></dd></dl><dl><dtclass="spec value"id="val-yojson_lookup"><ahref="#val-yojson_lookup"class="anchor"></a><code><spanclass="keyword">val</span> yojson_lookup : <span><span>(string,Yojson.Basic.t)</span><ahref="../IStdlib/index.html#module-IStd">IStdlib.IStd</a>.List.Assoc.t</span><span>-></span> string <span>-></span><span>src:string</span><span>-></span><span>f:<span>(Yojson.Basic.t <span>-></span><span>src:string</span><span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><span>default:<spanclass="type-var">'a</span></span><span>-></span><spanclass="type-var">'a</span></code></dt><dd><p>Lookup a json value on an assoc list. If not present, returns default. Otherwise returns (f json_value ~src) where src has element name appended. f is typically one of the above _of_yojson functions.</p></dd></dl><dl><dtclass="spec value"id="val-timeit"><ahref="#val-timeit"class="anchor"></a><code><spanclass="keyword">val</span> timeit : <span>f:<span>(unit <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><spanclass="type-var">'a</span> * int</code></dt><dd><p>Returns the execution time of <code>f</code> in milliseconds together with its result</p></dd></dl><dl><dtclass="spec value"id="val-do_in_dir"><ahref="#val-do_in_dir"class="anchor"></a><code><spanclass="keyword">val</span> do_in_dir : <span>dir:string</span><span>-></span><span>f:<span>(unit <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><spanclass="type-var">'a</span></code></dt><dd><p>executes <code>f</code> after cding into <code>dir</code> and then restores original cwd</p></dd></dl><dl><dtclass="spec value"id="val-get_available_memory_MB"><ahref="#val-get_available_memory_MB"class="anchor"></a><code><spanclass="keyword">val</span> get_available_memory_MB : unit <span>-></span><span>int option</span></code></dt><dd><p>On Linux systems, return <code>Some x</code> where <code>MemAvailable x</code> is in <code>/proc/meminfo</code>. Returns <code>None</code> in all other cases.</p></dd></dl><dl><dtclass="spec value"id="val-iter_infer_deps"><ahref="#val-iter_infer_deps"class="anchor"></a><code><spanclass="keyword">val</span> iter_infer_deps : <span>project_root:string</span><span>-></span><span>f:<span>(string <span>-></span> unit)</span></span><span>-></span> string <span>-></span> unit</code></dt><dd><p>Parse each line of the given infer_deps.txt file (split on tabs, assume 3 elements per line) and run <code>f</code> on the third element. <code>project_root</code> is an argument to avoid dependency cycles.</p></dd></dl><dl><dtclass="spec value"id="val-numcores"><ahref="#val-numcores"class="anchor"></a><code><spanclass="keyword">val</span> numcores : int</code></dt><dd><ul><li>On Linux return the number of physical cores (sockets * cores per socket).</li><li>On Darwin and Windows returns half of the number of CPUs since most processors have 2 hardware threads per core.</li></ul></dd></dl><dl><dtclass="spec value"id="val-set_best_cpu_for"><ahref="#val-set_best_cpu_for"class="anchor"></a><code><spanclass="keyword">val</span> set_best_cpu_for : int <span>-></span> unit</code></dt><dd><p>Pins processes to CPUs aiming to saturate physical cores evenly</p></dd></dl><dl><dtclass="spec value"id="val-zip_fold_filenames"><ahref="#val-zip_fold_filenames"class="anchor"></a><code><spanclass="keyword">val</span> zip_fold_filenames : <span>init:<spanclass="type-var">'a</span></span><span>-></span><span>f:<span>(<spanclass="type-var">'a</span><span>-></span> string <span>-></span><spanclass="type-var">'a</span>)</span></span><span>-></span><span>zip_filename:string</span><span>-></span><spanclass="type-var">'a</span></code></dt><dd><p>fold over each filename in the given <code>zip_filename</code>.</p></dd></dl></div></body></html>