aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/attr-path.cc
AgeCommit message (Collapse)Author
2024-03-09libexpr: Support structured error classeseldritch horrors
While preparing PRs like #9753, I've had to change error messages in dozens of code paths. It would be nice if instead of EvalError("expected 'boolean' but found '%1%'", showType(v)) we could write TypeError(v, "boolean") or similar. Then, changing the error message could be a mechanical refactor with the compiler pointing out places the constructor needs to be changed, rather than the error-prone process of grepping through the codebase. Structured errors would also help prevent the "same" error from having multiple slightly different messages, and could be a first step towards error codes / an error index. This PR reworks the exception infrastructure in `libexpr` to support exception types with different constructor signatures than `BaseError`. Actually refactoring the exceptions to use structured data will come in a future PR (this one is big enough already, as it has to touch every exception in `libexpr`). The core design is in `eval-error.hh`. Generally, errors like this: state.error("'%s' is not a string", getAttrPathStr()) .debugThrow<TypeError>() are transformed like this: state.error<TypeError>("'%s' is not a string", getAttrPathStr()) .debugThrow() The type annotation has moved from `ErrorBuilder::debugThrow` to `EvalState::error`. (cherry picked from commit c6a89c1a1659b31694c0fbcd21d78a6dd521c732) Change-Id: Iced91ba4e00ca9e801518071fb43798936cbd05a
2023-04-24Merge remote-tracking branch 'origin/master' into source-pathEelco Dolstra
2023-04-06Backport SourcePath from the lazy-trees branchEelco Dolstra
This introduces the SourcePath type from lazy-trees as an abstraction for accessing files from inputs that may not be materialized in the real filesystem (e.g. Git repositories). Currently, however, it's just a wrapper around CanonPath, so it shouldn't change any behaviour. (On lazy-trees, SourcePath is a <InputAccessor, CanonPath> tuple.)
2023-01-19Revert "Revert "Merge pull request #6204 from layus/coerce-string""Guillaume Maudoux
This reverts commit 9b33ef3879a764bed4cc2404a08344c3a697a646.
2023-01-18Revert "Merge pull request #6204 from layus/coerce-string"Robert Hensing
This reverts commit a75b7ba30f1e4f8b15e810fd18e63ee9552e0815, reversing changes made to 9af16c5f742300e831a2cc400e43df1e22f87f31.
2022-04-29Merge remote-tracking branch 'origin/master' into coerce-stringGuillaume Maudoux
2022-04-28fix errors case and wordingGuillaume Maudoux
2022-04-25rename SymbolIdx -> Symbol, Symbol -> SymbolStrpennae
after #6218 `Symbol` no longer confers a uniqueness invariant on the string it wraps, it is now possible to create multiple symbols that compare equal but whose string contents have different addresses. this guarantee is now only provided by `SymbolIdx`, leaving `Symbol` only as a string wrapper that knows about the intricacies of how symbols need to be formatted for output. this change renames `SymbolIdx` to `Symbol` to restore the previous semantics of `Symbol` to that name. we also keep the wrapper type and rename it to `SymbolStr` instead of returning plain strings from lookups into the symbol table because symbols are formatted for output in many places. theoretically we do not need `SymbolStr`, only a function that formats a string for output as a symbol, but having to wrap every symbol that appears in a message into eg `formatSymbol()` is error-prone and inconvient.
2022-04-21store Symbols in a table as well, like positionspennae
this slightly increases the amount of memory used for any given symbol, but this increase is more than made up for if the symbol is referenced more than once in the EvalState that holds it. on average every symbol should be referenced at least twice (once to introduce a binding, once to use it), so we expect no increase in memory on average. symbol tables are limited to 2³² entries like position tables, and similar arguments apply to why overflow is not likely: 2³² symbols would require as many string instances (at 24 bytes each) and map entries (at 24 bytes or more each, assuming that the map holds on average at most one item per bucket as the docs say). a full symbol table would require at least 192GB of memory just for symbols, which is well out of reach. (an ofborg eval of nixpks today creates less than a million symbols!)
2022-04-21replace most Pos objects/ptrs with indexes into a position tablepennae
Pos objects are somewhat wasteful as they duplicate the origin file name and input type for each object. on files that produce more than one Pos when parsed this a sizeable waste of memory (one pointer per Pos). the same goes for ptr<Pos> on 64 bit machines: parsing enough source to require 8 bytes to locate a position would need at least 8GB of input and 64GB of expression memory. it's not likely that we'll hit that any time soon, so we can use a uint32_t index to locate positions instead.
2022-04-21don't use full Pos for findPackageFilename/editorForpennae
only file and line of the returned position were ever used, it wasn't actually used a position. as such we may as well use a path+int pair for only those two values and remove a use of Pos that would not work well with a position table.
2022-03-18Merge remote-tracking branch 'origin/master' into coerce-stringGuillaume Maudoux
2022-03-18Revert extra colon at end os stringsGuillaume Maudoux
2022-03-07more fixesGuillaume Maudoux
2022-03-07Implement a suggestions mechanismregnat
Each `Error` class now includes a set of suggestions, and these are printed by the top-level handler.
2022-03-04Add error context for most basic coercionsGuillaume Maudoux
2022-02-25Remove std::string alias (for real this time)Eelco Dolstra
Also use std::string_view in a few more places.
2022-02-04Merge branch 'issue-3505' of https://github.com/kamadorueda/nixEelco Dolstra
2022-01-27return string_views from forceString*pennae
once a string has been forced we already have dynamic storage allocated for it, so we can easily reuse that storage instead of copying.
2022-01-21determinePos: remove from critical pathKevin Amado
2022-01-21forceValue: make pos mandatoryKevin Amado
- Make passing the position to `forceValue` mandatory, this way we remember people that the position is important for better error messages - Add pos to all `forceValue` calls
2021-07-19Rename findDerivationFilename -> findPackageFilenameRobert Hensing
It does not operate on a derivation and does not return a derivation path. Instead it works at the language level, where a distinct term "package" is more appropriate to distinguish the parent object of `meta.position`; an attribute which doesn't even make it into the derivation.
2021-07-01Prefer to throw specific errorsPamplemousse
Signed-off-by: Pamplemousse <xav.maso@gmail.com>
2021-01-08string2Int(): Return std::optionalEelco Dolstra
2020-12-17Rename Value::normalType() -> Value::type()Silvan Mosberger
2020-12-12Use Value::normalType on all forced values instead of Value::typeSilvan Mosberger
2020-06-18Merge branch 'master' into caveman-LOCsBen Burdette
2020-06-18Some backports from the flakes branchEelco Dolstra
2020-06-15Remove trailing whitespaceEelco Dolstra
2020-05-20print LOC for stdin, string argsBen Burdette
2020-04-21remove 'format' from Error constructor callsBen Burdette
2020-04-02libexpr: remove unused attrErrorAndreas Rammhold
The attrError variable is no longer used but still allocated on every call to the findAlongAttrPath function.
2020-03-24nix edit: Support non-derivation attributesEelco Dolstra
E.g. $ nix edit .#nixosConfigurations.bla now works. (cherry picked from commit d2032edb2f86e955a8a7724a27c0c3225f386500)
2020-03-24findAlongAttrPath(): Return positionEelco Dolstra
(cherry picked from commit 0b013a54dc570395bed887369f8dd622b8ce337b)
2020-03-24findAlongAttrPath(): Throw AttrPathNotFoundEelco Dolstra
(cherry picked from commit 6b0ca8e803710342af70e257935724c5ad84ca04)
2019-10-28findDerivationFilename: add FIXMEzimbatm
2019-10-28libexpr: findDerivationFilename return Pos instead of tuplezimbatm
2019-10-23libexpr: add findDerivationFilenamezimbatm
extract the derivation to filename:lineno heuristic
2017-07-30Replace Unicode quotes in user-facing strings by ASCIIJörg Thalheim
Relevant RFC: NixOS/rfcs#4 $ ag -l | xargs sed -i -e "/\"/s/’/'/g;/\"/s/‘/'/g"
2016-11-26Revert "Get rid of unicode quotes (#1140)"Eelco Dolstra
This reverts commit f78126bfd6b6c8477fcdbc09b2f98772dbe9a1e7. There really is no need for such a massive change...
2016-11-25Get rid of unicode quotes (#1140)Guillaume Maudoux
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.
2015-07-17OCD: foreach -> C++11 ranged forEelco Dolstra
2014-08-20Use proper quotes everywhereEelco Dolstra
2013-11-18Support quoted attribute names in -AEelco Dolstra
This is requires if you have attribute names with dots in them. So you can now say: $ nix-instantiate '<nixos>' -A 'config.systemd.units."postgresql.service".text' --eval-only Fixes #151.
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-09-03Work on Values instead of ExprsEelco Dolstra
This prevents some duplicate evaluation in nix-env and nix-instantiate. Also, when traversing ~/.nix-defexpr, only read regular files with the extension .nix. Previously it was reading files like .../channels/binary-caches/<name>. The only reason this didn't cause problems is pure luck (namely, <name> shadows an actual Nix expression, the binary-caches files happen to be syntactically valid Nix expressions, and we iterate over the directory contents in just the right order).
2013-09-02Get rid of a signedness warningEelco Dolstra
2013-09-02Fix whitespaceEelco Dolstra
2012-09-19Templatise tokenizeString()Eelco Dolstra