From aae416132d5ca470ac96c68f56f3085a9b0bc65e Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Wed, 12 Jul 2023 15:18:35 +0200 Subject: [PATCH] refactor(odoc): remove redundant arguments The functions `setup_pkg_odocl_rules` and `setup_pkg_html_rules` are always called with `~lib` computed from `libs_of_pkg`. We move that inside the function. Signed-off-by: Etienne Millon --- src/dune_rules/odoc.ml | 63 ++++++++++++------------------------------ 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/src/dune_rules/odoc.ml b/src/dune_rules/odoc.ml index 9e468fb5816..4d856caa4f3 100644 --- a/src/dune_rules/odoc.ml +++ b/src/dune_rules/odoc.ml @@ -439,14 +439,6 @@ let libs_of_pkg ctx ~pkg = | None -> Some lib | Some _ -> None)) -let load_all_odoc_rules_pkg sctx ~pkg = - let* pkg_libs = libs_of_pkg sctx ~pkg in - let+ () = - Pkg pkg :: List.map pkg_libs ~f:(fun lib -> Lib lib) - |> Memo.parallel_iter ~f:(fun _ -> Memo.return ()) - in - pkg_libs - let entry_modules_by_lib sctx lib = let info = Lib.Local.info lib in let dir = Lib_info.src_dir info in @@ -572,32 +564,22 @@ let setup_pkg_rules_def memo_name f = let module Input = struct module Super_context = Super_context.As_memo_key - type t = Super_context.t * Package.Name.t * Lib.Local.t list + type t = Super_context.t * Package.Name.t - let equal (s1, p1, l1) (s2, p2, l2) = - Package.Name.equal p1 p2 - && List.equal Lib.Local.equal l1 l2 - && Super_context.equal s1 s2 + let equal (s1, p1) (s2, p2) = + Package.Name.equal p1 p2 && Super_context.equal s1 s2 - let hash (sctx, p, ls) = - Poly.hash - ( Super_context.hash sctx - , Package.Name.hash p - , List.hash Lib.Local.hash ls ) - - let to_dyn (_, package, libs) = - let open Dyn in - Tuple - [ Package.Name.to_dyn package - ; List (List.map ~f:Lib.Local.to_dyn libs) - ] + let hash = Tuple.T2.hash Super_context.hash Package.Name.hash + + let to_dyn (_, package) = Package.Name.to_dyn package end in Memo.With_implicit_output.create memo_name ~input:(module Input) ~implicit_output:Rules.implicit_output f let setup_pkg_odocl_rules_def = - let f (sctx, pkg, (libs : Lib.Local.t list)) = + let f (sctx, pkg) = + let* libs = libs_of_pkg (Super_context.context sctx) ~pkg in let* requires = let libs = (libs :> Lib.t list) in Lib.closure libs ~linking:false @@ -618,8 +600,8 @@ let setup_pkg_odocl_rules_def = in setup_pkg_rules_def "setup-package-odocls-rules" f -let setup_pkg_odocl_rules sctx ~pkg ~libs : unit Memo.t = - Memo.With_implicit_output.exec setup_pkg_odocl_rules_def (sctx, pkg, libs) +let setup_pkg_odocl_rules sctx ~pkg : unit Memo.t = + Memo.With_implicit_output.exec setup_pkg_odocl_rules_def (sctx, pkg) let setup_lib_html_rules_def = let module Input = struct @@ -653,8 +635,9 @@ let setup_lib_html_rules sctx lib = Memo.With_implicit_output.exec setup_lib_html_rules_def (sctx, lib) let setup_pkg_html_rules_def = - let f (sctx, pkg, (libs : Lib.Local.t list)) = + let f (sctx, pkg) = let ctx = Super_context.context sctx in + let* libs = libs_of_pkg ctx ~pkg in let* () = Memo.parallel_iter libs ~f:(setup_lib_html_rules sctx) and* pkg_odocs = let* pkg_odocs = odoc_artefacts sctx (Pkg pkg) in @@ -672,8 +655,8 @@ let setup_pkg_html_rules_def = in setup_pkg_rules_def "setup-package-html-rules" f -let setup_pkg_html_rules sctx ~pkg ~libs : unit Memo.t = - Memo.With_implicit_output.exec setup_pkg_html_rules_def (sctx, pkg, libs) +let setup_pkg_html_rules sctx ~pkg : unit Memo.t = + Memo.With_implicit_output.exec setup_pkg_html_rules_def (sctx, pkg) let setup_package_aliases sctx (pkg : Package.t) = let ctx = Super_context.context sctx in @@ -835,10 +818,6 @@ let gen_rules sctx ~dir rest = lib_unique_name_or_pkg is neither a valid pkg or lnu *) let ctx = Super_context.context sctx in let* lib, lib_db = Scope_key.of_string ctx lib_unique_name_or_pkg in - let setup_pkg_odocl_rules pkg = - let* pkg_libs = load_all_odoc_rules_pkg ctx ~pkg in - setup_pkg_odocl_rules sctx ~pkg ~libs:pkg_libs - in (* jeremiedimino: why isn't [None] some kind of error here? *) let* lib = let+ lib = Lib.DB.find lib_db lib in @@ -854,7 +833,7 @@ let gen_rules sctx ~dir rest = Lib.closure [ Lib.Local.to_lib lib ] ~linking:false in setup_lib_odocl_rules sctx lib ~requires - | Some pkg -> setup_pkg_odocl_rules pkg) + | Some pkg -> setup_pkg_odocl_rules sctx ~pkg) and+ () = let* packages = Only_packages.get () in match @@ -864,7 +843,7 @@ let gen_rules sctx ~dir rest = | None -> Memo.return () | Some pkg -> let name = Package.name pkg in - setup_pkg_odocl_rules name + setup_pkg_odocl_rules sctx ~pkg:name in ()) | [ "_html"; lib_unique_name_or_pkg ] -> @@ -873,12 +852,6 @@ let gen_rules sctx ~dir rest = lib_unique_name_or_pkg is neither a valid pkg or lnu *) let ctx = Super_context.context sctx in let* lib, lib_db = Scope_key.of_string ctx lib_unique_name_or_pkg in - let setup_pkg_html_rules pkg = - let* pkg_libs = - load_all_odoc_rules_pkg (Super_context.context sctx) ~pkg - in - setup_pkg_html_rules sctx ~pkg ~libs:pkg_libs - in (* jeremiedimino: why isn't [None] some kind of error here? *) let* lib = let+ lib = Lib.DB.find lib_db lib in @@ -890,7 +863,7 @@ let gen_rules sctx ~dir rest = | Some lib -> ( match Lib_info.package (Lib.Local.info lib) with | None -> setup_lib_html_rules sctx lib - | Some pkg -> setup_pkg_html_rules pkg) + | Some pkg -> setup_pkg_html_rules sctx ~pkg) and+ () = let* packages = Only_packages.get () in match @@ -900,7 +873,7 @@ let gen_rules sctx ~dir rest = | None -> Memo.return () | Some pkg -> let name = Package.name pkg in - setup_pkg_html_rules name + setup_pkg_html_rules sctx ~pkg:name in ()) | _ -> Memo.return (Build_config.Redirect_to_parent Build_config.Rules.empty)