From e2531ee09170268590ac1b8a859ba9f9afe43bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Wed, 15 May 2024 17:12:40 +0200 Subject: [PATCH] Factor duplicated logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ulysse GĂ©rard --- src/dune_rules/merlin/merlin.ml | 46 +++++++++++++-------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/dune_rules/merlin/merlin.ml b/src/dune_rules/merlin/merlin.ml index e0d074029958..80b5ce7ae4ea 100644 --- a/src/dune_rules/merlin/merlin.ml +++ b/src/dune_rules/merlin/merlin.ml @@ -596,6 +596,21 @@ module Unprocessed = struct ~f:(pp_flags ctx ~expander t.config.libname) ;; + let add_lib_dirs sctx mode ~init libs = + Action_builder.of_memo + (let open Memo.O in + Memo.parallel_map (Lib.Set.to_list libs) ~f:(fun lib -> + let+ dirs = src_dirs sctx lib in + lib, dirs) + >>| List.fold_left ~init ~f:(fun (src_dirs, obj_dirs) (lib, more_src_dirs) -> + ( Path.Set.union src_dirs more_src_dirs + , let public_cmi_dir = + let info = Lib.info lib in + obj_dir_of_lib `Public mode (Lib_info.obj_dir info) + in + Path.Set.add obj_dirs public_cmi_dir ))) + ;; + let process ({ modules ; ident = _ @@ -658,35 +673,10 @@ module Unprocessed = struct in let+ flags = flags and+ src_dirs, obj_dirs = - Action_builder.of_memo - (let open Memo.O in - Memo.parallel_map (Lib.Set.to_list requires) ~f:(fun lib -> - let+ dirs = src_dirs sctx lib in - lib, dirs) - >>| List.fold_left - ~init:(Path.set_of_source_paths source_dirs, objs_dirs) - ~f:(fun (src_dirs, obj_dirs) (lib, more_src_dirs) -> - ( Path.Set.union src_dirs more_src_dirs - , let public_cmi_dir = - let info = Lib.info lib in - obj_dir_of_lib `Public mode (Lib_info.obj_dir info) - in - Path.Set.add obj_dirs public_cmi_dir ))) + let init = Path.set_of_source_paths source_dirs, objs_dirs in + add_lib_dirs sctx mode ~init requires and+ hidden_src_dirs, hidden_obj_dirs = - Action_builder.of_memo - (let open Memo.O in - Memo.parallel_map (Lib.Set.to_list requires_hidden) ~f:(fun lib -> - let+ dirs = src_dirs sctx lib in - lib, dirs) - >>| List.fold_left - ~init:(Path.Set.empty, Path.Set.empty) - ~f:(fun (src_dirs, obj_dirs) (lib, more_src_dirs) -> - ( Path.Set.union src_dirs more_src_dirs - , let public_cmi_dir = - let info = Lib.info lib in - obj_dir_of_lib `Public mode (Lib_info.obj_dir info) - in - Path.Set.add obj_dirs public_cmi_dir ))) + add_lib_dirs sctx mode ~init:(Path.Set.empty, Path.Set.empty) requires_hidden in let src_dirs = Path.Set.union src_dirs (Path.Set.of_list_map ~f:Path.source more_src_dirs)