From e71a49e290db2190ff0eeb88b8688a2a2717885c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Thu, 22 Feb 2024 17:52:04 +0100 Subject: [PATCH] index: cache files (and move to another library) --- src/analysis/dune | 4 +++- src/analysis/occurrences.ml | 2 +- src/index-format/dune | 10 ++++++++++ src/index-format/index_cache.ml | 5 +++++ src/{analysis => index-format}/index_format.ml | 2 +- src/kernel/dune | 2 +- src/kernel/mocaml.ml | 3 ++- 7 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/index-format/dune create mode 100644 src/index-format/index_cache.ml rename src/{analysis => index-format}/index_format.ml (98%) diff --git a/src/analysis/dune b/src/analysis/dune index 09227105d8..905df41c6d 100644 --- a/src/analysis/dune +++ b/src/analysis/dune @@ -10,13 +10,15 @@ -open Merlin_utils -open Merlin_specific -open Merlin_extend - -open Merlin_kernel) + -open Merlin_kernel + -open Merlin_index_format) (libraries merlin_config merlin_specific merlin_extend merlin_kernel merlin_utils + merlin_index_format ocaml_parsing ocaml_preprocess query_protocol diff --git a/src/analysis/occurrences.ml b/src/analysis/occurrences.ml index 1800ccd24b..e324e8a260 100644 --- a/src/analysis/occurrences.ml +++ b/src/analysis/occurrences.ml @@ -243,7 +243,7 @@ let locs_of ~config ~env ~typer_result ~pos ~scope path = let exception File_changed in try let locs = List.filter_map config.merlin.index_files ~f:(fun file -> - let external_index = Index_format.read_exn ~file in + let external_index = Index_cache.read file in Hashtbl.find_opt external_index.defs def_uid |> Option.map ~f:(fun locs -> LidSet.filter (fun {loc; _} -> (* We ignore external results that concern the current buffer *) diff --git a/src/index-format/dune b/src/index-format/dune new file mode 100644 index 0000000000..7cdf97ffd4 --- /dev/null +++ b/src/index-format/dune @@ -0,0 +1,10 @@ +(library + (name merlin_index_format) + (public_name merlin-lib.index_format) + (flags + :standard + -open Ocaml_parsing + -open Ocaml_typing + -open Ocaml_utils + -open Merlin_utils) + (libraries ocaml_parsing ocaml_typing ocaml_utils merlin_utils)) diff --git a/src/index-format/index_cache.ml b/src/index-format/index_cache.ml new file mode 100644 index 0000000000..6ff979bfd4 --- /dev/null +++ b/src/index-format/index_cache.ml @@ -0,0 +1,5 @@ +include File_cache.Make (struct + type t = Index_format.index + let read file = Index_format.read_exn ~file + let cache_name = "Index_cache" +end) diff --git a/src/analysis/index_format.ml b/src/index-format/index_format.ml similarity index 98% rename from src/analysis/index_format.ml rename to src/index-format/index_format.ml index e31baf369a..98da574135 100644 --- a/src/analysis/index_format.ml +++ b/src/index-format/index_format.ml @@ -79,7 +79,7 @@ let ext = "ocaml-index" let magic_number = "Merl2023I001" let write ~file index = - Merlin_utils.Misc.output_to_file_via_temporary ~mode:[ Open_binary ] file + Misc.output_to_file_via_temporary ~mode:[ Open_binary ] file (fun _temp_file_name oc -> output_string oc magic_number; output_value oc (index : index)) diff --git a/src/kernel/dune b/src/kernel/dune index 7d12d85e73..bd98153bd1 100644 --- a/src/kernel/dune +++ b/src/kernel/dune @@ -15,7 +15,7 @@ -open Merlin_extend) (libraries merlin_config os_ipc ocaml_parsing ocaml_preprocess ocaml_typing ocaml_utils merlin_extend merlin_specific merlin_utils - merlin_dot_protocol unix str)) + merlin_dot_protocol merlin_index_format unix str)) (rule (targets standard_library.ml) diff --git a/src/kernel/mocaml.ml b/src/kernel/mocaml.ml index 833db64fe8..650d8d7925 100644 --- a/src/kernel/mocaml.ml +++ b/src/kernel/mocaml.ml @@ -112,5 +112,6 @@ let clear_caches () = ( (* Flush cache *) let flush_caches ?older_than () = ( Cmi_cache.flush ?older_than (); - Cmt_cache.flush ?older_than () + Cmt_cache.flush ?older_than (); + Merlin_index_format.Index_cache.flush ?older_than () )