2 * Copyright (c) 2019, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
10 (* NOTE: we can't simply use a string as a key. In the case of a name conflict,
11 we may put e.g. a function named 'foo' into the cache whose value is one type,
12 and then later try to withdraw a class named 'foo' whose value is another type.
14 The problem can be solved with a GADT, but making a GADT with references to
15 types like `Typing_defs.ty` causes dependency cycles, since `typing` ends up
16 depending on `Provider_config` transitively.
20 | Class_decl
of string
21 | Record_decl
of string
22 | Typedef_decl
of string
23 | Gconst_decl
of string
25 type decl_cache
= (decl_cache_key
, Obj.t
) Memory_bounded_lru_cache.t
30 | Local_memory
of { decl_cache
: decl_cache
}
31 | Decl_service
of unit
33 let backend_ref = ref Shared_memory
35 let set_lru_shared_memory_backend () : unit = backend_ref := Lru_shared_memory
37 let set_shared_memory_backend () : unit = backend_ref := Shared_memory
39 let set_local_memory_backend ~
(max_size_in_words
: int) : unit =
42 { decl_cache
= Memory_bounded_lru_cache.make ~max_size_in_words
}
44 let set_decl_service_backend () : unit = backend_ref := Decl_service
()
46 let get_backend () : backend
= !backend_ref