package merlin-lib

  1. Overview
  2. Docs
Merlin's libraries

Install

dune-project
 Dependency

Authors

Maintainers

Sources

merlin-5.9.tbz
sha256=de395dd37d246e3ec303e1af35ff8421665fa4f0f0005d95732124b22e3417ac
sha512=74756b28767cdfe10288720540582e818a9d946dd2406606724ebc7b68d1cf6623142e56a1e457f7862839732e7add365aec056930c7ac89be7036c22e5f29ae

doc/merlin-lib.ocaml_utils/Ocaml_utils/Local_store/index.html

Module Ocaml_utils.Local_storeSource

This module provides some facilities for creating references (and hash tables) which can easily be snapshotted and restored to an arbitrary version.

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.

Creators

Sourceval s_ref : 'a -> 'a ref

Similar to Stdlib.ref, except the allocated reference is registered into the store.

Sourceval s_table : ('a -> 'b) -> 'a -> 'b ref

Used to register hash tables. Those also need to be placed into refs to be easily swapped out, but one can't just "snapshot" the initial value to create fresh instances, so instead an initializer is required.

Use it like this:

  let my_table = s_table Hashtbl.create 42

State management

Note: all the following functions are currently unused inside the compiler codebase. Merlin is their only user at the moment.

Sourcetype store
Sourceval fresh : unit -> store

Returns a fresh instance of the store.

The first time this function is called, it snapshots the value of all the registered references, later calls to fresh will return instances initialized to those values.

Sourceval with_store : store -> (unit -> 'a) -> 'a

with_store s f resets all the registered references to the value they have in s for the run of f. If f updates any of the registered refs, s is updated to remember those changes.

Sourceval reset : unit -> unit

Resets all the references to the initial snapshot (i.e. to the same values that new instances start with).

Sourceval is_bound : unit -> bool

Returns true when a store is active (i.e. when called from the callback passed to with_store), false otherwise.