1Local_store(3) OCaml library Local_store(3)
2
3
4
6 Local_store - This module provides some facilities for creating refer‐
7 ences (and hash tables) which can easily be snapshoted and restored to
8 an arbitrary version.
9
11 Module Local_store
12
14 Module Local_store
15 : sig end
16
17
18 This module provides some facilities for creating references (and hash
19 tables) which can easily be snapshoted and restored to an arbitrary
20 version.
21
22 It is used throughout the frontend (read: typechecker), to register all
23 (well, hopefully) the global state. Thus making it easy for tools like
24 Merlin to go back and forth typechecking different files.
25
26
27
28
29
30
31
32 Creators
33 val s_ref : 'a -> 'a ref
34
35 Similar to ref , except the allocated reference is registered into the
36 store.
37
38
39
40 val s_table : ('a -> 'b) -> 'a -> 'b ref
41
42 Used to register hash tables. Those also need to be placed into refs to
43 be easily swapped out, but one can't just "snapshot" the initial value
44 to create fresh instances, so instead an initializer is required.
45
46 Use it like this:
47 let my_table = s_table Hashtbl.create 42
48
49
50
51
52
53 State management
54 Note: all the following functions are currently unused inside the com‐
55 piler codebase. Merlin is their only user at the moment.
56
57 type store
58
59
60
61
62
63 val fresh : unit -> store
64
65 Returns a fresh instance of the store.
66
67 The first time this function is called, it snapshots the value of all
68 the registered references, later calls to fresh will return instances
69 initialized to those values.
70
71
72
73 val with_store : store -> (unit -> 'a) -> 'a
74
75
76 with_store s f resets all the registered references to the value they
77 have in s for the run of f . If f updates any of the registered refs,
78 s is updated to remember those changes.
79
80
81
82 val reset : unit -> unit
83
84 Resets all the references to the initial snapshot (i.e. to the same
85 values that new instances start with).
86
87
88
89 val is_bound : unit -> bool
90
91 Returns true when a store is active (i.e. when called from the callback
92 passed to Local_store.with_store ), false otherwise.
93
94
95
96
97
98OCamldoc 2022-07-22 Local_store(3)