Minor module system evaluation speedups
This gives about a 5% speedup. Issue #8152.
This commit is contained in:
parent
0ca10a445a
commit
67b1a20f12
1 changed files with 25 additions and 22 deletions
|
@ -264,43 +264,46 @@ rec {
|
||||||
defs' = (optional (opt ? default)
|
defs' = (optional (opt ? default)
|
||||||
{ file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs;
|
{ file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs;
|
||||||
|
|
||||||
# Handle properties, check types, and merge everything together
|
# Handle properties, check types, and merge everything together.
|
||||||
inherit (mergeDefinitions loc opt.type defs') isDefined defsFinal mergedValue;
|
res = mergeDefinitions loc opt.type defs';
|
||||||
files = map (def: def.file) defsFinal;
|
|
||||||
merged =
|
# Check whether the option is defined, and apply the ‘apply’
|
||||||
if isDefined then mergedValue
|
# function to the merged value. This allows options to yield a
|
||||||
else throw "The option `${showOption loc}' is used but not defined.";
|
# value computed from the definitions.
|
||||||
|
value =
|
||||||
|
if !res.isDefined then
|
||||||
|
throw "The option `${showOption loc}' is used but not defined."
|
||||||
|
else if opt ? apply then
|
||||||
|
opt.apply res.mergedValue
|
||||||
|
else
|
||||||
|
res.mergedValue;
|
||||||
|
|
||||||
# Finally, apply the ‘apply’ function to the merged
|
|
||||||
# value. This allows options to yield a value computed
|
|
||||||
# from the definitions.
|
|
||||||
value = (opt.apply or id) merged;
|
|
||||||
in opt //
|
in opt //
|
||||||
{ value = addErrorContext "while evaluating the option `${showOption loc}':" value;
|
{ value = addErrorContext "while evaluating the option `${showOption loc}':" value;
|
||||||
definitions = map (def: def.value) defsFinal;
|
definitions = map (def: def.value) defsFinal;
|
||||||
inherit isDefined files;
|
files = map (def: def.file) res.defsFinal;
|
||||||
|
inherit (res) isDefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Merge definitions of a value of a given type.
|
# Merge definitions of a value of a given type.
|
||||||
mergeDefinitions = loc: type: defs: rec {
|
mergeDefinitions = loc: type: defs: rec {
|
||||||
defsFinal =
|
defsFinal =
|
||||||
let
|
let
|
||||||
# Process mkMerge and mkIf properties
|
# Process mkMerge and mkIf properties.
|
||||||
processIfAndMerge = defs: concatMap (m:
|
defs' = concatMap (m:
|
||||||
map (value: { inherit (m) file; inherit value; }) (dischargeProperties m.value)
|
map (value: { inherit (m) file; inherit value; }) (dischargeProperties m.value)
|
||||||
) defs;
|
) defs;
|
||||||
|
|
||||||
# Process mkOverride properties
|
# Process mkOverride properties.
|
||||||
processOverride = defs: filterOverrides defs;
|
defs'' = filterOverrides defs';
|
||||||
|
|
||||||
# Sort mkOrder properties
|
# Sort mkOrder properties.
|
||||||
processOrder = defs:
|
defs''' =
|
||||||
# Avoid sorting if we don't have to.
|
# Avoid sorting if we don't have to.
|
||||||
if any (def: def.value._type or "" == "order") defs
|
if any (def: def.value._type or "" == "order") defs''
|
||||||
then sortProperties defs
|
then sortProperties defs''
|
||||||
else defs;
|
else defs'';
|
||||||
in
|
in defs''';
|
||||||
processOrder (processOverride (processIfAndMerge defs));
|
|
||||||
|
|
||||||
# Type-check the remaining definitions, and merge them.
|
# Type-check the remaining definitions, and merge them.
|
||||||
mergedValue = foldl' (res: def:
|
mergedValue = foldl' (res: def:
|
||||||
|
|
Loading…
Reference in a new issue