Local_store(3)

πŸŽ€ Local_store πŸŽ€

okay so bestie, welcome to Local_store, fresh from the OCaml library manual. This module is literally your little save-point system for refs and hash tables: it gives you facilities for creating references (and hash tables) that can easily be snapshotted and restored to an arbitrary version. Obsessed. πŸ’…


✨ NAME ✨

Local_store β€” the module that provides some facilities for creating references (and hash tables) which can easily be snapshotted and restored to an arbitrary version. No cap, that's the whole assignment.

🧚 MODULE 🧚

Module name: Local_store. That's it, that's the module. 🫢

πŸ’– DOCUMENTATION πŸ’–

Module Local_store : sig end

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. Iconic behavior, honestly. ✨

πŸŽ€ Creators πŸŽ€

  • val s_ref : 'a -> 'a ref β€” Similar to ref, except the allocated reference is registered into the store.
  • val 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.
  • type store
  • val 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.

  • val 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.
  • val reset : unit -> unit β€” Resets all the references to the initial snapshot (i.e. to the same values that new instances start with).
  • val is_bound : unit -> bool β€” Returns true when a store is active (i.e. when called from the callback passed to Local_store.with_store), false otherwise.

that's the whole vibe, bestie β€” page cooked by OCamldoc, dated 2026-06-22, for Local_store(3). πŸ’…βœ¨

πŸ“¦ where this page comes from