Skip to content

Improve shellFor selectComponents performance #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions builder/shell-for.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ let
(builtins.map (x: lib.nameValuePair (x.name) x)
(haskellLib.flatLibDepends {depends = directlySelectedComponents;}));

isSelectedComponent =
comp: selectedComponentsBitmap."${((haskellLib.dependToLib comp).name or null)}" or false;
selectedComponentsBitmap =
lib.mapAttrs
(_: x: (builtins.any
(dep: selectedComponentsBitmap."${(haskellLib.dependToLib dep).name}") x.config.depends))
(_: x: (builtins.any isSelectedComponent x.config.depends))
transitiveDependenciesComponents
// builtins.listToAttrs (map (x: lib.nameValuePair x.name true) directlySelectedComponents); # base case

selectedComponents =
lib.filter (x: selectedComponentsBitmap."${x.name}") (lib.attrValues transitiveDependenciesComponents);
lib.filter isSelectedComponent (lib.attrValues transitiveDependenciesComponents);

# Given a list of `depends`, removes those which are selected components
removeSelectedInputs =
lib.filter (input: !(selectedComponentsBitmap."${((haskellLib.dependToLib input).name or null)}" or false));
lib.filter (input: !(isSelectedComponent input));

# The configs of all the selected components
selectedConfigs = map (c: c.config) selectedComponents
Expand Down
9 changes: 1 addition & 8 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,7 @@ in {
## flatLibDepends :: Component -> [Package]
flatLibDepends = component:
let
# this is a minor improvement over the "cannot coerce set to string"
# error. It will now say:
#
# > The option `packages.Win32.package.identifier.name' is used but not defined.
#
# which indicates that the package.Win32 is missing and not defined.
getKey = x: if x ? "outPath" then "${x}" else (throw x.identifier.name);
makePairs = map (p: rec { key=getKey val; val=(p.components.library or p); });
makePairs = map (p: rec { key=val.name; val=(p.components.library or p); });
closure = builtins.genericClosure {
startSet = makePairs component.depends;
operator = {val,...}: makePairs val.config.depends;
Expand Down