moonpool/dev/ocaml/Local_store/index.html

2 lines
5.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Local_store (ocaml.Local_store)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../index.html">ocaml</a> &#x00BB; Local_store</nav><header class="odoc-preamble"><h1>Module <code><span>Local_store</span></code></h1><p>This module provides some facilities for creating references (and hash tables) which can easily be snapshoted and restored to an arbitrary version.</p><p>It is used throughout the frontend (read: typechecker), to register all (well, hopefully) the global state. Thus making it easy for tools like Merlin to go back and forth typechecking different files.</p></header><nav class="odoc-toc"><ul><li><a href="#creators">Creators</a></li><li><a href="#state-management">State management</a></li></ul></nav><div class="odoc-content"><h2 id="creators"><a href="#creators" class="anchor"></a>Creators</h2><div class="odoc-spec"><div class="spec value anchored" id="val-s_ref"><a href="#val-s_ref" class="anchor"></a><code><span><span class="keyword">val</span> s_ref : <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="../Stdlib/index.html#type-ref">Stdlib.ref</a></span></span></code></div><div class="spec-doc"><p>Similar to <a href="../Stdlib/index.html#val-ref"><code>Stdlib.ref</code></a>, except the allocated reference is registered into the store.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-s_table"><a href="#val-s_table" class="anchor"></a><code><span><span class="keyword">val</span> s_table : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'b</span> <a href="../Stdlib/index.html#type-ref">Stdlib.ref</a></span></span></code></div><div class="spec-doc"><p>Used to register hash tables. Those also need to be placed into refs to be easily swapped out, but one can't just &quot;snapshot&quot; the initial value to create fresh instances, so instead an initializer is required.</p><p>Use it like this:</p><pre class="language-ocaml"><code>let my_table = s_table Hashtbl.create 42</code></pre></div></div><h2 id="state-management"><a href="#state-management" class="anchor"></a>State management</h2><p>Note: all the following functions are currently unused inside the compiler codebase. Merlin is their only user at the moment.</p><div class="odoc-spec"><div class="spec type anchored" id="type-store"><a href="#type-store" class="anchor"></a><code><span><span class="keyword">type</span> store</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fresh"><a href="#val-fresh" class="anchor"></a><code><span><span class="keyword">val</span> fresh : <span>unit <span class="arrow">&#45;&gt;</span></span> <a href="#type-store">store</a></span></code></div><div class="spec-doc"><p>Returns a fresh instance of the store.</p><p>The first time this function is called, it snapshots the value of all the registered references, later calls to <code>fresh</code> will return instances initialized to those values.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-with_store"><a href="#val-with_store" class="anchor"></a><code><span><span class="keyword">val</span> with_store : <span><a href="#type-store">store</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(<span>unit <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>with_store s f</code> resets all the registered references to the value they have in <code>s</code> for the run of <code>f</code>. If <code>f</code> updates any of the registered refs, <code>s</code> is updated to remember those changes.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-reset"><a href="#val-reset" class="anchor"></a><code><span><span class="keyword">val</span> reset : <span>unit <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Resets all the references to the initial snapshot (i.e. to the same values that new instances start with).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_bound"><a href="#val-is_bound" class="anchor"></a><code><span><span class="keyword">val</span> is_bound : <span>unit <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>Returns <code>true</code> when a store is active (i.e. when called from the callback passed to <a href="#val-with_store"><code>with_store</code></a>), <code>false</code> otherwise.</p></div></div></div></body></html>