about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
AgeCommit message (Collapse)AuthorFilesLines
2013-12-31 Dynamic attrsShea Levy1-1/+23
This adds new syntax for attribute names: * attrs."${name}" => getAttr name attrs * attrs ? "${name}" => isAttrs attrs && hasAttr attrs name * attrs."${name}" or def => if attrs ? "${name}" then attrs."${name}" else def * { "${name}" = value; } => listToAttrs [{ inherit name value; }] Of course, it's a bit more complicated than that. The attribute chains can be arbitrarily long and contain combinations of static and dynamic parts (e.g. attrs."${foo}".bar."${baz}" or qux), which is relatively straightforward for the getAttrs/hasAttrs cases but is more complex for the listToAttrs case due to rules about duplicate attribute definitions. For attribute sets with dynamic attribute names, duplicate static attributes are detected at parse time while duplicate dynamic attributes are detected when the attribute set is forced. So, for example, { a = null; a.b = null; "${"c"}" = true; } will be a parse-time error, while { a = {}; "${"a"}".b = null; c = true; } will be an eval-time error (technically that case could theoretically be detected at parse time, but the general case would require full evaluation). Moreover, duplicate dynamic attributes are not allowed even in cases where they would be with static attributes ({ a.b.d = true; a.b.c = false; } is legal, but { a."${"b"}".d = true; a."${"b"}".c = false; } is not). This restriction might be relaxed in the future in cases where the static variant would not be an error, but it is not obvious that that is desirable. Finally, recursive attribute sets with dynamic attributes have the static attributes in scope but not the dynamic ones. So rec { a = true; "${"b"}" = a; } is equivalent to { a = true; b = true; } but rec { "${"a"}" = true; b = a; } would be an error or use a from the surrounding scope if it exists. Note that the getAttr, getAttr or default, and hasAttr are all implemented purely in the parser as syntactic sugar, while attribute sets with dynamic attribute names required changes to the AST to be implemented cleanly. This is an alternative solution to and closes #167 Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31 Add the ExprBuiltin Expr type to the ASTShea Levy1-0/+11
Certain desugaring schemes may require the parser to use some builtin function to do some of the work (e.g. currently `throw` is used to lazily cause an error if a `<>`-style path is not in the search path) Unfortunately, these names are not reserved keywords, so an expression that uses such a syntactic sugar will not see the expected behavior (see tests/lang/eval-okay-redefine-builtin.nix for an example). This adds the ExprBuiltin AST type, which when evaluated uses the value from the rootmost variable scope (which of course is initialized internally and can't shadow any of the builtins). Signed-off-by: Shea Levy <shea@shealevy.com>
2013-11-19 Add a toJSON primopEelco Dolstra1-20/+23
2013-11-18 Add a primop unsafeGetAttrPos to return the position of an attributeEelco Dolstra1-5/+14
2013-11-18 Add a symbol __curPos that expands to the current source locationEelco Dolstra1-0/+13
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
2013-11-12 Make function calls show up in stack traces againEelco Dolstra1-20/+28
Note that adding --show-trace prevents functions calls from being tail-recursive, so an expression that evaluates without --show-trace may fail with a stack overflow if --show-trace is given.
2013-11-12 Make function calls tail-recursiveEelco Dolstra1-38/+60
2013-11-12 Make ifs and asserts tail-recursiveEelco Dolstra1-4/+10
The local Value object prevented g++ from making a tail call. Not clear why. In any case, not using a temporary makes g++ do the tail call.
2013-11-12 Get rid of an intermediary on the stackEelco Dolstra1-9/+13
2013-10-28 Slightly optimize listToAttrsEelco Dolstra1-0/+1
2013-10-24 Rename "attribute sets" to "sets"Eelco Dolstra1-13/+10
We don't have any other kind of sets so calling them attribute sets is unnecessarily verbose.
2013-10-24 Remove unnecessary call to forceStringNoCtxEelco Dolstra1-1/+1
2013-10-24 Don't require NIX_SHOW_STATS for NIX_COUNT_CALLSEelco Dolstra1-0/+1
2013-10-23 Memoize evalFile() lookups under both the original and resolved nameEelco Dolstra1-4/+9
Previously we only used the resolved name, causing repeated resolution (e.g. /dir to /dir/default.nix).
2013-10-17 Don't show <nix/derivation.nix> in stack tracesEelco Dolstra1-1/+1
Messages like while evaluating the attribute `outPath' at `/nix/store/212ngf4ph63mp6p1np2bapkfikpakfv7-nix-1.6/share/nix/corepkgs/derivation.nix:18:9': are redundant, because Nix already shows that it's evaluating a derivation: while instantiating the derivation named `firefox-24.0' at `/home/eelco/Dev/nixpkgs/pkgs/applications/networking/browsers/firefox/default.nix:131:5': while evaluating the derivation attribute `nativeBuildInputs' at `/home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/default.nix:76:17':
2013-10-17 Revert the behaviour of antiquoted paths to pre-Nix 1.6Eelco Dolstra1-4/+4
Commit 159e621d1a9c4391b53f3d822109c36931934698 accidentally changed the behaviour of antiquoted paths, e.g. "${/foo}/bar" used to evaluate to "/nix/store/<hash>-foo/bar" (where /foo gets copied to the store), but in Nix 1.6 it evaluates to "/foo/bar". This is inconsistent, since " ${/foo}/bar" evaluates to " /nix/store/<hash>-foo/bar". So revert to the old behaviour.
2013-10-08 printStats(): Print the size of the symbol table in bytesEelco Dolstra1-0/+1
2013-10-08 Deduplicate filenames in PosEelco Dolstra1-1/+0
This saves ~4 MiB of RAM for NixOS system instantiation, and ~18 MiB for "nix-env -qa".
2013-10-08 Treat undefined variable errors consistentlyEelco Dolstra1-1/+6
Previously, a undefined variable inside a "with" caused an EvalError (which can be caught), while outside, it caused a ParseError (which cannot be caught). Now both cause an UndefinedVarError (which cannot be caught).
2013-10-08 Show the exact position of undefined variablesEelco Dolstra1-1/+1
In particular, undefined variable errors in a "with" previously didn't show *any* position information, so this should help a lot in those cases.
2013-10-08 Remove some unused functionsEelco Dolstra1-15/+0
2013-10-08 Merge VarRef into ExprVarEelco Dolstra1-3/+3
2013-10-07 Don't show calls to primops in stack tracesEelco Dolstra1-6/+1
Since they don't have location information, they just give you crap like: while evaluating the builtin function `getAttr': while evaluating the builtin function `derivationStrict': ...
2013-10-02 Fix segfault in nix-repl / hydra-eval-jobsEelco Dolstra1-3/+3
If a "with" attribute set fails to evaluate, we have to make sure its Env record remains unchanged. Otherwise, repeated evaluation gives a segfault: nix-repl> :a with 0; { a = x; b = x; } Added 2 variables. nix-repl> a error: value is an integer while an attribute set was expected nix-repl> b Segmentation fault
2013-09-03 nix-env: Load files in ~/.nix-defexpr on demandEelco Dolstra1-0/+6
So if you do "nix-env -qa -A nixos", then other channels won't be parsed/evaluated at all.
2013-09-03 Get rid of the parse tree cacheEelco Dolstra1-13/+17
Since we already cache files in normal form (fileEvalCache), caching parse trees is redundant. Note that getting rid of this cache doesn't actually save much memory at the moment, because parse trees are currently not freed / GC'ed.
2013-09-02 Add some support code for nix-replEelco Dolstra1-1/+8
2013-09-02 Fix whitespaceEelco Dolstra1-22/+22
2013-08-26 Simplify inherited attribute handlingShea Levy1-26/+14
This reduces the difference between inherited and non-inherited attribute handling to the choice of which env to use (in recs and lets) by setting the AttrDef::e to a new ExprVar in the parser rather than carrying a separate AttrDef::v VarRef member. As an added bonus, this allows inherited attributes that inherit from a with to delay forcing evaluation of the with's attributes. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-08-26 Fix typos, especially those that end up in the Nix manualIvan Kozik1-1/+1
2013-08-19 Store Nix integers as longsEelco Dolstra1-2/+2
So on 64-bit systems, integers are now 64-bit. Fixes #158.
2013-08-02 In the profiler output, show function names (if available)Eelco Dolstra1-7/+7
2013-08-02 Overload the ‘+’ operator to support integer additionEelco Dolstra1-11/+19
2013-07-31 Make Env smallerEelco Dolstra1-19/+21
Commit 20866a7031ca823055a221653b77986faa167329 added a ‘withAttrs’ field to Env, which is annoying because it makes every Env structure bigger and we allocate millions of them. E.g. NixOS evaluation took 18 MiB more. So this commit squeezes ‘withAttrs’ into values[0]. Probably should use a union...
2013-07-31 Don't use NULLEelco Dolstra1-4/+2
2013-07-31 Avoid thunks when a fromWith var can be looked up without evaluationShea Levy1-7/+7
Signed-off-by: Shea Levy <shea@shealevy.com>
2013-07-31 Delay evaulation of `with` attrs until a variable lookup needs themShea Levy1-7/+12
Evaluation of attribute sets is strict in the attribute names, which means immediate evaluation of `with` attribute sets rules out some potentially interesting use cases (e.g. where the attribute names of one set depend in some way on another but we want to bring those names into scope for some values in the second set). The major example of this is overridable self-referential package sets (e.g. all-packages.nix). With immediate `with` evaluation, the only options for such sets are to either make them non-recursive and explicitly use the name of the overridden set in non-overridden one every time you want to reference another package, or make the set recursive and use the `__overrides` hack. As shown in the test case that comes with this commit, though, delayed `with` evaluation allows a nicer third alternative. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-05-16 Show function names in error messagesEelco Dolstra1-4/+9
Functions in Nix are anonymous, but if they're assigned to a variable/attribute, we can use the variable/attribute name in error messages, e.g. while evaluating `concatMapStrings' at `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/pkgs/lib/strings.nix:18:25': ...
2013-05-16 Show which function argument was unexpectedEelco Dolstra1-5/+9
Fixes #116.
2013-05-16 Shut up a compiler warningEelco Dolstra1-1/+1
2013-03-08 Revert "Prevent config.h from being clobbered"Eelco Dolstra1-1/+1
This reverts commit 28bba8c44f484eae38e8a15dcec73cfa999156f6.
2013-03-07 Prevent config.h from being clobberedEelco Dolstra1-1/+1
2013-02-08 Make "${./path} ..." evaluate to a string, not a pathEelco Dolstra1-1/+1
Wacky string coercion semantics caused expressions like exec = "${./my-script} params..."; to evaluate to a path (‘/path/my-script params’), because anti-quotations are desuged to string concatenation: exec = ./my-script + " params..."; By constrast, adding a space at the start would yield a string as expected: exec = " ${./my-script} params..."; Now the first example also evaluates to a string.
2012-11-28 nix-env -q --out-path: Support multiple outputsEelco Dolstra1-0/+1
We now print all output paths of a package, e.g. openssl-1.0.0i bin=/nix/store/gq2mvh0wb9l90djvsagln3aqywqmr6vl-openssl-1.0.0i-bin;man=/nix/store/7zwf5r5hsdarl3n86dasvb4chm2xzw9n-openssl-1.0.0i-man;/nix/store/cj7xvk7fjp9q887359j75pw3pzjfmqf1-openssl-1.0.0i or (in XML mode) <item attrPath="openssl" name="openssl-1.0.0i" system="x86_64-linux"> <output name="bin" path="/nix/store/gq2mvh0wb9l90djvsagln3aqywqmr6vl-openssl-1.0.0i-bin" /> <output name="man" path="/nix/store/7zwf5r5hsdarl3n86dasvb4chm2xzw9n-openssl-1.0.0i-man" /> <output name="out" path="/nix/store/cj7xvk7fjp9q887359j75pw3pzjfmqf1-openssl-1.0.0i" /> </item>
2012-11-27 Optionally ignore null-valued derivation attributesEelco Dolstra1-0/+1
This allows adding attributes like attr = if stdenv.system == "bla" then something else null; without changing the resulting derivation on non-<bla> platforms. We once considered adding a special "ignore" value for this purpose, but using null seems more elegant.
2012-11-26 nix-instantiate: Fix read-only evaluationEelco Dolstra1-0/+1
2012-11-09 Fix a segfault when auto-calling a "a@{...}" functionEelco Dolstra1-5/+5
Since the called function can return its argument attribute set (e.g. "a"), the latter should not be allocated on the stack. Reported by Shea.
2012-10-03 Add a ‘--repair’ flag to nix-instantiateEelco Dolstra1-1/+2
This allows repairing corrupted derivations and other source files.
2012-09-19 Templatise tokenizeString()Eelco Dolstra1-1/+1
2012-08-27 Merge branch 'master' into no-manifestsEelco Dolstra1-11/+75