summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-28 14:41:36 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-28 15:04:18 +0200
commit67b1a20f126fb61c43c3a37c2d908ef0302c6c58 (patch)
tree27b7298145f8516ba42e62594f9ce9473585ae6c /lib/modules.nix
parent0ca10a445a76e9e88818a986a0691b30b20aaada (diff)
downloadnixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.tar
nixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.tar.gz
nixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.tar.bz2
nixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.tar.lz
nixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.tar.xz
nixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.tar.zst
nixpkgs-67b1a20f126fb61c43c3a37c2d908ef0302c6c58.zip
Minor module system evaluation speedups
This gives about a 5% speedup.

Issue #8152.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix49
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 959abf5e51e..f64adaf1b19 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -264,43 +264,46 @@ rec {
       defs' = (optional (opt ? default)
         { file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs;
 
-      # Handle properties, check types, and merge everything together
-      inherit (mergeDefinitions loc opt.type defs') isDefined defsFinal mergedValue;
-      files = map (def: def.file) defsFinal;
-      merged =
-        if isDefined then mergedValue
-        else throw "The option `${showOption loc}' is used but not defined.";
-
-      # 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;
+      # Handle properties, check types, and merge everything together.
+      res = mergeDefinitions loc opt.type defs';
+
+      # Check whether the option is defined, and apply the ‘apply’
+      # function to the merged value.  This allows options to yield a
+      # 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;
+
     in opt //
       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
         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.
   mergeDefinitions = loc: type: defs: rec {
     defsFinal =
       let
-        # Process mkMerge and mkIf properties
-        processIfAndMerge = defs: concatMap (m:
+        # Process mkMerge and mkIf properties.
+        defs' = concatMap (m:
           map (value: { inherit (m) file; inherit value; }) (dischargeProperties m.value)
         ) defs;
 
-        # Process mkOverride properties
-        processOverride = defs: filterOverrides defs;
+        # Process mkOverride properties.
+        defs'' = filterOverrides defs';
 
-        # Sort mkOrder properties
-        processOrder = defs:
+        # Sort mkOrder properties.
+        defs''' =
           # Avoid sorting if we don't have to.
-          if any (def: def.value._type or "" == "order") defs
-          then sortProperties defs
-          else defs;
-      in
-        processOrder (processOverride (processIfAndMerge defs));
+          if any (def: def.value._type or "" == "order") defs''
+          then sortProperties defs''
+          else defs'';
+      in defs''';
 
     # Type-check the remaining definitions, and merge them.
     mergedValue = foldl' (res: def: