lib: Use Nix's static scope checking, fix error message, optimize

Nix can perform static scope checking, but whenever code is inside
a `with` expression, the analysis breaks down, because it can't
know statically what's in the attribute set whose attributes were
brought into scope. In those cases, Nix has to assume that
everything works out.

Except it doesnt. Removing `with` from lib/ revealed an undefined
variable in an error message.

If that doesn't convince you that we're better off without `with`,
I can tell you that this PR results in a 3% evaluation performance
improvement because Nix can look up local variables by index.
This adds up with applications like the module system.

Furthermore, removing `with` makes the binding site of each
variable obvious, which helps with comprehension.
This commit is contained in:
Robert Hensing 2020-10-20 13:47:24 +02:00
parent 5aa2a98dfa
commit afa6c51f27
9 changed files with 238 additions and 82 deletions

View file

@ -41,10 +41,15 @@ Usage:
[1] maybe this behaviour should be removed to keep things simple (?)
*/
with lib.lists;
with lib.attrsets;
with lib.strings;
let
inherit (lib)
concatStringsSep
head
isAttrs
listToAttrs
tail
;
in
rec {
/* !!! The interface of this function is kind of messed up, since