From 447d6a816c52654f637cad29961bf2cdc7c85173 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 11 Jan 2021 11:39:29 -0800 Subject: [PATCH] Add Build.with_targets_set Allows for more deforestation Signed-off-by: Rudi Grinberg --- src/dune_engine/build.ml | 2 ++ src/dune_engine/build.mli | 3 +++ src/dune_rules/action_unexpanded.ml | 3 +-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dune_engine/build.ml b/src/dune_engine/build.ml index 5e7b249a16c..39b97c3fdee 100644 --- a/src/dune_engine/build.ml +++ b/src/dune_engine/build.ml @@ -234,6 +234,8 @@ end let with_targets build ~targets : _ With_targets.t = { build; targets = Path.Build.Set.of_list targets } +let with_targets_set build ~targets : _ With_targets.t = { build; targets } + let with_no_targets build : _ With_targets.t = { build; targets = Path.Build.Set.empty } diff --git a/src/dune_engine/build.mli b/src/dune_engine/build.mli index 732c475ea44..650286c0b14 100644 --- a/src/dune_engine/build.mli +++ b/src/dune_engine/build.mli @@ -58,6 +58,9 @@ val set_file_system_accessors : file_exists:(Path.t -> bool) -> unit into [Build.With_targets.t]. *) val with_targets : 'a t -> targets:Path.Build.t list -> 'a With_targets.t +(** [with_targets_set] is like [with_targets] but [targets] is a set *) +val with_targets_set : 'a t -> targets:Path.Build.Set.t -> 'a With_targets.t + (** Create a value of [With_targets.t] with the empty set of targets. *) val with_no_targets : 'a t -> 'a With_targets.t diff --git a/src/dune_rules/action_unexpanded.ml b/src/dune_rules/action_unexpanded.ml index 0f351216bf5..012c5e27ded 100644 --- a/src/dune_rules/action_unexpanded.ml +++ b/src/dune_rules/action_unexpanded.ml @@ -702,7 +702,6 @@ let expand t ~loc ~dep_kind ~targets_dir ~targets:targets_written_by_user ; Pp.enumerate (Path.Build.Set.to_list targets) ~f:(fun target -> Pp.text (Dpath.describe_path (Path.build target))) ]); - let targets = Path.Build.Set.to_list targets in Build.path_set deps >>> add_deps_if_exist deps_if_exist >>> Build.dyn_path_set @@ -731,7 +730,7 @@ let expand t ~loc ~dep_kind ~targets_dir ~targets:targets_written_by_user ((Action.Chdir (dir, action), deps), deps_if_exist)) in (action, Path.Set.union deps deps_if_exist_which_exist)) - |> Build.with_targets ~targets + |> Build.with_targets_set ~targets (* We re-export [Action_dune_lang] in the end to avoid polluting the inferred types in this module with all the various t's *)