a provider for decl-service
[hiphop-php.git] / hphp / hack / src / providers / provider_config.ml
blobf58001077573f81bc5febdfd12da4bb7b742ac64
1 (*
2 * Copyright (c) 2019, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
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.
18 type decl_cache_key =
19 | Fun_decl of string
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
27 type backend =
28 | Lru_shared_memory
29 | Shared_memory
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 =
40 backend_ref :=
41 Local_memory
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