aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/value.hh
AgeCommit message (Collapse)Author
2021-04-13libexpr: misc improvements for proper error positionMaximilian Bosch
When working on some more complex Nix code, there are sometimes rather unhelpful or misleading error messages, especially if coerce-errors are thrown. This patch is a first steps towards improving that. I'm happy to file more changes after that, but I'd like to gather some feedback first. To summarize, this patch does the following things: * Attrsets (a.k.a. `Bindings` in `libexpr`) now have a `Pos`. This is helpful e.g. to identify which attribute-set in `listToAttrs` is invalid. * The `Value`-struct has a new method named `determinePos` which tries to guess the position of a value and falls back to a default if that's not possible. This can be used to provide better messages if a coercion fails. * The new `determinePos`-API is used by `builtins.concatMap` now. With that change, Nix shows the exact position in the error where a wrong value was returned by the lambda. To make sure it's still obvious that `concatMap` is the problem, another stack-frame was added. * The changes described above can be added to every other `primop`, but first I'd like to get some feedback about the overall approach.
2020-12-18Replace Value type setters with mk* functionsSilvan Mosberger
Move clearValue inside Value mkInt instead of setInt mkBool instead of setBool mkString instead of setString mkPath instead of setPath mkNull instead of setNull mkAttrs instead of setAttrs mkList instead of setList* mkThunk instead of setThunk mkApp instead of setApp mkLambda instead of setLambda mkBlackhole instead of setBlackhole mkPrimOp instead of setPrimOp mkPrimOpApp instead of setPrimOpApp mkExternal instead of setExternal mkFloat instead of setFloat Add note that the static mk* function should be removed eventually
2020-12-17Rename Value::normalType() -> Value::type()Silvan Mosberger
2020-12-17Rename ValueType -> InternalType, NormalType -> ValueTypeSilvan Mosberger
And Value::type to Value::internalType, such that type() can be used in the next commit to get the new ValueType
2020-12-12Make Value::type privateSilvan Mosberger
This is an implementation detail and shouldn't be used. Use normalType() and the various is<Type> functions instead
2020-12-12Add ValueType checking functions for types that have the same NormalTypeSilvan Mosberger
2020-12-12Introduce Value type setters and make use of themSilvan Mosberger
2020-12-12Introduce NormalType for the normal type of a ValueSilvan Mosberger
This will be useful to abstract over the ValueType implementation details Make use of it already to replace the showType(ValueType) function
2020-06-29EvalCache: Store string contextsEelco Dolstra
2020-04-16Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-04-16ValueMap, VectorVector: Use traceable_allocatorEelco Dolstra
We want to *trace* the 'Value *' arrays, not garbage-collect them! Otherwise the vectors/maps can end up pointing to nowhere. Fixes #3377. Closes #3384.
2020-04-16Add function to allocate a Value in traceable memoryEelco Dolstra
2019-12-04Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2019-11-28Remove builtins.valueSizeEelco Dolstra
Fixes #3246.
2019-11-10De-duplicate struct PrimOp forward declarationPeter Kolloch
2019-09-09Require flake.nix to be an attrset (not a non-trivial thunk)Eelco Dolstra
2018-08-29libexpr: Use int64_t for NixIntaszlig
Using a 64bit integer on 32bit systems will come with a bit of a performance overhead, but given that Nix doesn't use a lot of integers compared to other types, I think the overhead is negligible also considering that 32bit systems are in decline. The biggest advantage however is that when we use a consistent integer size across all platforms it's less likely that we miss things that we break due to that. One example would be: https://github.com/NixOS/nixpkgs/pull/44233 On Hydra it will evaluate, because the evaluator runs on a 64bit machine, but when evaluating the same on a 32bit machine it will fail, so using 64bit integers should make that consistent. While the change of the type in value.hh is rather easy to do, we have a few more options available for doing the conversion in the lexer: * Via an #ifdef on the architecture and using strtol() or strtoll() accordingly depending on which architecture we are. For the #ifdef we would need another AX_COMPILE_CHECK_SIZEOF in configure.ac. * Using istringstream, which would involve copying the value. * As we're already using boost, lexical_cast might be a good idea. Spoiler: I went for the latter, first of all because lexical_cast does have an overload for const char* and second of all, because it doesn't involve copying around the input string. Also, because istringstream seems to come with a bigger overhead than boost::lexical_cast: https://www.boost.org/doc/libs/release/doc/html/boost_lexical_cast/performance.html The first method (still using strtol/strtoll) also wasn't something I pursued further, because it is also locale-aware which I doubt is what we want, given that the regex for int is [0-9]+. Signed-off-by: aszlig <aszlig@nix.build> Fixes: #2339
2018-07-03Store floating point numbers in double precisionEelco Dolstra
Even on 32-bit systems, Value has enough space to hold a double.
2018-05-02Fix some random -Wconversion warningsEelco Dolstra
2017-04-25Restructure installables handling in the "nix" commandEelco Dolstra
2017-03-24use std::tuple for ValueMap allocatorDaiderd Jordan
2017-02-08Include config.h implicitly with '-include config.h' in CFLAGSTuomas Tynkkynen
Because config.h can #define things like _FILE_OFFSET_BITS=64 and not every compilation unit includes config.h, we currently compile half of Nix with _FILE_OFFSET_BITS=64 and other half with _FILE_OFFSET_BITS unset. This causes major havoc with the Settings class on e.g. 32-bit ARM, where different compilation units disagree with the struct layout. E.g.: diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc @@ -166,6 +166,8 @@ void Settings::update() _get(useSubstitutes, "build-use-substitutes"); + fprintf(stderr, "at Settings::update(): &useSubstitutes = %p\n", &nix::settings.useSubstitutes); _get(buildUsersGroup, "build-users-group"); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -138,6 +138,8 @@ void RemoteStore::initConnection(Connection & conn) void RemoteStore::setOptions(Connection & conn) { + fprintf(stderr, "at RemoteStore::setOptions(): &useSubstitutes = %p\n", &nix::settings.useSubstitutes); conn.to << wopSetOptions Gave me: at Settings::update(): &useSubstitutes = 0xb6e5c5cb at RemoteStore::setOptions(): &useSubstitutes = 0xb6e5c5c7 That was not a fun one to debug!
2016-08-30Fix GC buildEelco Dolstra
2016-08-29Add builtin function "partition"Eelco Dolstra
The implementation of "partition" in Nixpkgs is O(n^2) (because of the use of ++), and for some reason was causing stack overflows in multi-threaded evaluation (not sure why). This reduces "nix-env -qa --drv-path" runtime by 0.197s and memory usage by 298 MiB (in non-Boehm mode).
2016-08-29nix path-info: Add --json flagEelco Dolstra
Also, factor out JSON generation from value-to-json.{cc,hh}, and support producing indented JSON.
2016-01-06@eelco's feedback: downgrade to regular float for size, remove unused function.Christian Theune
2016-01-05First hit at providing support for floats in the language.Christian Theune
2015-07-23Optimize small listsEelco Dolstra
The value pointers of lists with 1 or 2 elements are now stored in the list value itself. In particular, this makes the "concatMap (x: if cond then [(f x)] else [])" idiom cheaper.
2014-12-02Make all ExternalValueBase functions constShea Levy
2014-12-02Allow external code using libnixexpr to add typesShea Levy
Code that links to libnixexpr (e.g. plugins loaded with importNative, or nix-exec) may want to provide custom value types and operations on values of those types. For example, nix-exec is currently using sets where a custom IO value type would be more appropriate. This commit provides a generic hook for such types in the form of tExternal and the ExternalBase virtual class, which contains all functions necessary for libnixexpr's type-polymorphic functions (e.g. `showType`) to be implemented.
2014-10-09mkList: Scrub betterEelco Dolstra
Clearing v.app.right was not enough, because the length field of a list only takes 32 bits, so the most significant 32 bits of v.app.left (a.k.a. v.thunk.env) would remain. This could cause Boehm GC to interpret it as a valid pointer. This change reduces maximum RSS for evaluating the ‘tested’ job in nixos/release-small.nix from 1.33 GiB to 0.80 GiB, and runtime by about 8%.
2014-10-09TypoEelco Dolstra
2014-09-22Add a function ‘valueSize’Eelco Dolstra
It returns the size of value, including all other values and environments reachable from it. It is intended for debugging memory consumption issues.
2014-01-21Fix some clang warningsEelco Dolstra
2013-11-18Add a primop unsafeGetAttrPos to return the position of an attributeEelco Dolstra
2013-08-19Store Nix integers as longsEelco Dolstra
So on 64-bit systems, integers are now 64-bit. Fixes #158.
2013-08-06Remove obsolete reference to ATermsEelco Dolstra
2012-12-13fix use-after-free bug in mkString(Value&, Symbol&)Stuart Pernsteiner
2012-07-18Use "#pragma once" to prevent repeated header file inclusionEelco Dolstra
2012-01-07* Don't create thunks for simple constants (integers, strings, paths)Eelco Dolstra
and allocate them only once. * Move Value and related functions into value.hh.