aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
AgeCommit message (Collapse)Author
2014-09-19Store Attrs inside BindingsEelco Dolstra
This prevents a double allocation per attribute set.
2014-09-17Add some instrumentation for debugging GC leaksEelco Dolstra
2014-09-02Fix boost::too_many_args errorEelco Dolstra
Fixes #333.
2014-08-20Use proper quotes everywhereEelco Dolstra
2014-08-13Fix warning about non-existant -I directoriesEelco Dolstra
2014-06-10== operator: Ignore string contextEelco Dolstra
There really is no case I can think of where taking the context into account is useful. Mostly it's just very inconvenient.
2014-05-26Remove ExprBuiltinEelco Dolstra
It's slower than ExprVar since it doesn't compute a static displacement. Since we're not using the throw primop in the implementation of <...> anymore, it's also not really needed.
2014-05-26Ensure that -I flags get included in nixPathEelco Dolstra
Also fixes #261.
2014-05-15Provide a more useful error message when a dynamic attr lookup failsShea Levy
2014-04-04Show position info in attribute selection errorsEelco Dolstra
2014-04-04Show position info in Boolean operationsEelco Dolstra
2014-04-04Show position info in string concatenation / addition errorsEelco Dolstra
2014-04-04forceString: Show position infoEelco Dolstra
2014-04-04forceAttrs: Show position infoEelco Dolstra
2014-04-04forceList: Show position infoEelco Dolstra
2014-04-04forceInt: Show position infoEelco Dolstra
2014-04-04Pass position information to primop callsEelco Dolstra
For example: error: `tail' called on an empty list, at /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/ex-2/default.nix:13:7
2014-04-04Include position info in function applicationEelco Dolstra
This allows error messages like: error: the anonymous function at `/etc/nixos/configuration.nix:1:1' called without required argument `foo', at `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:77:59'
2014-03-30boost::shared_ptr -> std::shared_ptrEelco Dolstra
2014-03-10The expr of AttrNames/DynamicAttrDefs is always an ExprConcatStringsShea Levy
2014-03-10If a dynamic attribute name evaluates to null, remove it from the setShea Levy
2014-03-05Revert "Make ifs and asserts tail-recursive"Eelco Dolstra
This reverts commit 273322c7732093a354e86df82cf75d6604b8bce8.
2014-02-27Correctly detect infinite recursion in function applicationEelco Dolstra
If we're evaluating some application ‘v = f x’, we can't store ‘f’ temporarily in ‘v’, because if ‘f x’ refers to ‘v’, it will get ‘f’ rather than an infinite recursion error. Unfortunately, this breaks the tail call optimisation introduced in c897bac54954373f63511702731fe2cb23c0c98e. Fixes #217.
2014-01-21Merge branch 'master' into makeEelco Dolstra
Conflicts: src/libexpr/eval.cc
2013-12-31Don't use any syntactic sugar for dynamic attrsShea Levy
This doesn't change any functionality but moves some behavior out of the parser and into the evaluator in order to simplify the code. Signed-off-by: Shea Levy <shea@shealevy.com>
2013-12-31Dynamic attrsShea Levy
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-31Add the ExprBuiltin Expr type to the ASTShea Levy
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-23Drop the dependency on libgc in libmainEelco Dolstra
Instead, libexpr now depends on libgc. This means commands like nix-store that don't do any evaluation no longer require libgc.
2013-11-23Initialise Boehm GC only onceEelco Dolstra
2013-11-19Add a toJSON primopEelco Dolstra
2013-11-18Add a primop unsafeGetAttrPos to return the position of an attributeEelco Dolstra
2013-11-18Add a symbol __curPos that expands to the current source locationEelco Dolstra
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
2013-11-12Make function calls show up in stack traces againEelco Dolstra
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-12Make function calls tail-recursiveEelco Dolstra
2013-11-12Make ifs and asserts tail-recursiveEelco Dolstra
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-12Get rid of an intermediary on the stackEelco Dolstra
2013-10-28Slightly optimize listToAttrsEelco Dolstra
2013-10-24Rename "attribute sets" to "sets"Eelco Dolstra
We don't have any other kind of sets so calling them attribute sets is unnecessarily verbose.
2013-10-24Remove unnecessary call to forceStringNoCtxEelco Dolstra
2013-10-24Don't require NIX_SHOW_STATS for NIX_COUNT_CALLSEelco Dolstra
2013-10-23Memoize evalFile() lookups under both the original and resolved nameEelco Dolstra
Previously we only used the resolved name, causing repeated resolution (e.g. /dir to /dir/default.nix).
2013-10-17Don't show <nix/derivation.nix> in stack tracesEelco Dolstra
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-17Revert the behaviour of antiquoted paths to pre-Nix 1.6Eelco Dolstra
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-08printStats(): Print the size of the symbol table in bytesEelco Dolstra
2013-10-08Deduplicate filenames in PosEelco Dolstra
This saves ~4 MiB of RAM for NixOS system instantiation, and ~18 MiB for "nix-env -qa".
2013-10-08Treat undefined variable errors consistentlyEelco Dolstra
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-08Show the exact position of undefined variablesEelco Dolstra
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-08Remove some unused functionsEelco Dolstra
2013-10-08Merge VarRef into ExprVarEelco Dolstra
2013-10-07Don't show calls to primops in stack tracesEelco Dolstra
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': ...