Skip to content

Commit 5a66f44

Browse files
authored
perf(merlin): compute module configuration fields once (#16567)
Extracted from #16522. Signed-off-by: Antonio Nuno Monteiro <[email protected]>
1 parent 12802a6 commit 5a66f44

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

‎src/dune_rules/merlin/merlin.ml‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -903,22 +903,27 @@ module Unprocessed = struct
903903
modules
904904
|> Modules.With_vlib.drop_vlib
905905
|> Modules.fold ~init:[] ~f:(fun m init ->
906-
Module.sources_without_pp m
907-
|> Path.Build.Set.of_list_map ~f:(fun src -> Path.as_in_build_dir_exn src)
908-
|> Path.Build.Set.fold ~init ~f:(fun src acc ->
909-
let config =
910-
{ Processed.module_ = Module.set_pp m None
911-
; opens = Modules.With_vlib.local_open modules m
912-
; reader =
913-
String.Map.find
914-
readers
915-
(Filename.Extension.Or_empty.to_string (Path.Build.extension src))
916-
}
917-
in
918-
(* we add the config with and without the extension, the latter is
919-
needed for a fallback in this file's [get] function. *)
920-
let src_without_extension = remove_extension src in
921-
(src, config) :: (src_without_extension, config) :: acc))
906+
match Module.sources_without_pp m with
907+
| [] -> init
908+
| sources ->
909+
let module_ = Module.set_pp m None in
910+
let opens = Modules.With_vlib.local_open modules m in
911+
sources
912+
|> Path.Build.Set.of_list_map ~f:(fun src -> Path.as_in_build_dir_exn src)
913+
|> Path.Build.Set.fold ~init ~f:(fun src acc ->
914+
let config =
915+
{ Processed.module_
916+
; opens
917+
; reader =
918+
String.Map.find
919+
readers
920+
(Filename.Extension.Or_empty.to_string (Path.Build.extension src))
921+
}
922+
in
923+
(* we add the config with and without the extension, the latter is
924+
needed for a fallback in this file's [get] function. *)
925+
let src_without_extension = remove_extension src in
926+
(src, config) :: (src_without_extension, config) :: acc))
922927
|> Path.Build.Map.of_list_reduce ~f:(fun existing _ -> existing)
923928
in
924929
{ Processed.pp_config; config; per_file_config }

0 commit comments

Comments
 (0)