lib.modules: Refactor option scanning slightly

This scans the options with fewer function calls, improving performance.

It also removes a let Env from the happy flow of the new logic.

Changed files
+8 -10
lib
+8 -10
lib/modules.nix
···
catAttrs
concatLists
concatMap
-
count
elem
filter
findFirst
···
loc = prefix ++ [name];
defns = defnsByName.${name} or [];
defns' = defnsByName'.${name} or [];
-
nrOptions = count (m: isOption m.options) decls;
in
-
if nrOptions == length decls then
let opt = fixupOptionType loc (mergeOptionDecls loc decls);
in {
matchedOptions = evalOptionValue loc opt defns';
unmatchedDefns = [];
}
-
else if nrOptions != 0 then
-
let
-
firstOption = findFirst (m: isOption m.options) "" decls;
-
firstNonOption = findFirst (m: !isOption m.options) "" decls;
-
in
-
if firstOption.options.type.name == "submodule"
then
let opt = fixupOptionType loc (mergeOptionDecls loc (map optionTreeToOption decls));
in {
···
unmatchedDefns = [];
}
else
-
throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
else
mergeModules' loc decls defns) declsByName;
···
catAttrs
concatLists
concatMap
elem
filter
findFirst
···
loc = prefix ++ [name];
defns = defnsByName.${name} or [];
defns' = defnsByName'.${name} or [];
+
optionDecls = filter (m: isOption m.options) decls;
in
+
if length optionDecls == length decls then
let opt = fixupOptionType loc (mergeOptionDecls loc decls);
in {
matchedOptions = evalOptionValue loc opt defns';
unmatchedDefns = [];
}
+
else if optionDecls != [] then
+
if (lib.head optionDecls).options.type.name == "submodule"
then
let opt = fixupOptionType loc (mergeOptionDecls loc (map optionTreeToOption decls));
in {
···
unmatchedDefns = [];
}
else
+
let
+
firstNonOption = findFirst (m: !isOption m.options) "" decls;
+
in
+
throw "The option `${showOption loc}' in `${(lib.head optionDecls)._file}' is a prefix of options in `${firstNonOption._file}'."
else
mergeModules' loc decls defns) declsByName;