aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
AgeCommit message (Collapse)Author
2024-03-09slim down parser.yeldritch horrors
most EvalState and Expr members defined here could be elsewhere, where they'd be easier to maintain (not being embedded in a file with arcane syntax) and *somewhat* more faithfully placed according to the path of the file they're defined in. (cherry picked from commit e1aa585964c3d864ebff0030584f3349a539d615) Change-Id: Ibc704567462bb40f37cda05d8fadd465519db5f5
2024-03-09Merge pull request #9754 from 9999years/print-value-when-coercion-failseldritch horrors
Print the value in `error: cannot coerce` messages (cherry picked from commit 5b7bfd2d6b89d7dd5f54c1ca6c8072358d31a84e) === test taken from 6e8d5983143ae576e3f4b1d2954a5267f2943a49; it was added previously (and not backported because its pr was a mostly-revert), but it's useful to have around. Change-Id: Icbd14b55e3610ce7b774667bf14b82e6dc717982
2024-03-09Merge pull request #9818 from Ma27/print-value-on-function-call-type-erroreldritch horrors
libexpr: print value of what is attempted to be called as function (cherry picked from commit 50e5d7b883042852538371237e32a66bb22f0485) Change-Id: I7cb6290bd8f244e83bfce3b2eed2a4c8b4f16a83
2024-03-09Merge pull request #9753 from 9999years/print-value-on-type-erroreldritch horrors
Print the value in `value is X while a Y is expected` error (cherry picked from commit 5f72a97092da6af28a7d2b2a50d74e9d34fae7e1) Change-Id: Idb4bc903ae59a0f5b6fb3b1da4d47970fe0a6efe
2024-03-09Unify and refactor value printingeldritch horrors
Previously, there were two mostly-identical value printers -- one in `libexpr/eval.cc` (which didn't force values) and one in `libcmd/repl.cc` (which did force values and also printed ANSI color codes). This PR unifies both of these printers into `print.cc` and provides a `PrintOptions` struct for controlling the output, which allows for toggling whether values are forced, whether repeated values are tracked, and whether ANSI color codes are displayed. Additionally, `PrintOptions` allows tuning the maximum number of attributes, list items, and bytes in a string that will be displayed; this makes it ideal for contexts where printing too much output (e.g. all of Nixpkgs) is distracting. (As requested by @roberth in https://github.com/NixOS/nix/pull/9554#issuecomment-1845095735) Please read the tests for example output. Future work: - It would be nice to provide this function as a builtin, perhaps `builtins.toStringDebug` -- a printing function that never fails would be useful when debugging Nix code. - It would be nice to support customizing `PrintOptions` members on the command line, e.g. `--option to-string-max-attrs 1000`. (cherry picked from commit 0fa08b451682fb3311fe58112ff05c4fe5bee3a4, ) === Restore ambiguous value printer for `nix-instantiate` The Nix team has requested that this output format remain unchanged. I've added a warning to the man page explaining that `nix-instantiate --eval` output will not parse correctly in many situations. (cherry picked from commit df84dd4d8dd3fd6381ac2ca3064432ab31a16b79) Change-Id: I7cca6b4b53cd0642f2d49af657d5676a8554c9f8
2024-03-05Merge pull request #9634 from 9999years/combine-abstract-pos-and-poseldritch horrors
Combine `AbstractPos`, `PosAdapter`, and `Pos` (cherry picked from commit 113499d16fc87d53b73fb62fe6242154909756ed) === this is a bit cursed because originally it was based on InputAccessor code that we don't have and moved/patched features we likewise don't have (fetchToStore caching, all the individual accessors, ContentAddressMethod). the commit is adjusted accordingly to match (remove caching, ignore accessors, use FileIngestionMethod). note that `state.rootPath . CanonPath == abs` and computeStorePathForPath works relative to cwd, so the slight rewrite in the moved fetchToStore is legal. Change-Id: I05fd340c273f0bcc8ffabfebdc4a88b98083bce5
2024-03-04Merge pull request #9915 from 9999years/evaluating-attribute-positioneldritch horrors
Add position information to `while evaluating the attribute` errors in the debugger (cherry picked from commit ffe67c86a8ef3695e5c8b9c9800c192ac633dded) Change-Id: I177ea5ec60898abe09fb9d80d9602b2a32ff8f44
2024-03-04Merge pull request #9933 from pennae/debugger-fixeldritch horrors
fix debugger crashing while printing envs (cherry picked from commit 9b8b4860913afdb7f9cb1e1e81f9a9dd192cd1c1) Change-Id: Ica6a17e4b3e3b8b8093719f442c28be7f13be09d
2024-03-04Merge pull request #9919 from 9999years/reduce-debugger-cluttereldritch horrors
Reduce visual clutter in the debugger (cherry picked from commit f388a6148dae0fc999f1a67d0b96d76788f9b97f) Change-Id: I21bfe3e9f75816484b0f46dbe09e0ff40b22c6d9
2024-03-04Merge pull request #9681 from edolstra/eval-optimisationseldritch horrors
Optimize empty list constants (cherry picked from commit 315aade89d00c692715e5953c36a1b7d6528b703) Change-Id: I0f28ef8a27ccedc45acf44243eec9dc35b733300
2024-03-04Merge pull request #9658 from pennae/env-dieteldritch horrors
reduce the size of Env by one pointer (cherry picked from commit 83f5622545a2fc31eb7e7d5105f64ed6dd3058b3) Change-Id: I5636290526d0165cfc61aee1e7a5b94db4a26cef
2024-03-04Merge pull request #9617 from 9999years/stack-overflow-segfaulteldritch horrors
Fix segfault on infinite recursion in some cases (cherry picked from commit bf1b294bd81ca76c5ec9fe3ecd52196bf52a8300) Change-Id: Id137541426ec8536567835953fccf986a3aebf16
2024-03-04Merge pull request #9582 from pennae/misc-optseldritch horrors
a packet of small optimizations (cherry picked from commit ee439734e924eb337a869ff2e48aff8b989198bc) Change-Id: I125d870710750a32a0dece48f39a3e9132b0d023
2024-03-04Merge pull request #9555 from 9999years/positions-in-errorseldritch horrors
Pass positions when evaluating (cherry picked from commit c8458bd731eb1c74159bebe459ea00165e056b65) Change-Id: I1b4a5d58973be6264ffdb23b4492da200fdb71be
2024-03-04Merge pull request #9430 from hercules-ci/remove-vlaseldritch horrors
Fix stack overflow in `filter` (cherry picked from commit cb7f25869daa2491eeac5fee49ad8f31b2218c15) Change-Id: Ib90f97a9805bbb4d0e2741551d490f054fc0a675
2024-03-04Merge pull request #9399 from edolstra/revert-vlaseldritch horrors
Revert use of boost::container::small_vector in the evaluator (cherry picked from commit 6832d18ac734f4b855f97c07b158491dd01cefcd) Change-Id: I7f10af0c8b8a8beb4b1e36424120995f4ed82738
2024-03-04Merge pull request #9374 from hercules-ci/fix-nogceldritch horrors
Fix buildNoGc (cherry picked from commit 7762335a9c4d56f7501825345728c3f94e88bc31) Change-Id: I3ad53c9c1dd9180a2abc3528e9437c28ac95b303
2024-03-04Merge pull request #7348 from thufschmitt/dont-use-vlaseldritch horrors
Remove the usage of VLAs in the code (cherry picked from commit ac4431e9d016e62fb5dc9ae36833bd0c6cdadeec) Change-Id: Ifbf5fbfc2e27122362a2aaea4b62c7cf3ca46b1a
2024-03-04Merge pull request #9172 from tfc/bad-moveseldritch horrors
Fix/remove some bad std::moves (cherry picked from commit 8c049a9f044569ebda70231709f6f15d3073894a) Change-Id: I720273378d2506a13883acee28abd096d099b0d4
2024-03-04Merge pull request #8895 from hercules-ci/gc-before-statseldritch horrors
eval: Run a full GC before printing stats (cherry picked from commit aeea49609be014b1928c95b7ec28dbedeb4f032a) Change-Id: I47a23d3a7a47ea61d9a2b5727b638f879f3aaf1e
2023-08-18Delete `EvalState::addToSearchPath`John Ericson
This function is now trivial enough that it doesn't need to exist. `EvalState` can still be initialized with a custom search path, but we don't have a need to mutate the search path after it has been constructed, and I don't see why we would need to in the future. Fixes #8229
2023-08-18Fixing #7479John Ericson
Types converted: - `NixStringContextElem` - `OutputsSpec` - `ExtendedOutputsSpec` - `DerivationOutput` - `DerivationType` Existing ones mostly conforming the pattern cleaned up: - `ContentAddressMethod` - `ContentAddressWithReferences` The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think #8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`. See that issue (#7479) for details on the general goal. `git grep 'Raw::Raw'` indicates the two types I didn't yet convert `DerivedPath` and `BuiltPath` (and their `Single` variants) . This is because @roberth and I (can't find issue right now...) plan on reworking them somewhat, so I didn't want to churn them more just yet. Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2023-08-14Rework evaluator `SingleDerivedPath` infraJohn Ericson
`EvalState::mkSingleDerivedPathString` previously contained its own inverse (printing, rather than parsing) in order to validate what was parsed. Now that is pulled out into its own separate function: `EvalState::coerceToSingleDerivedPath`. In additional that pulled out logic is deduplicated with `EvalState::mkOutputString` via `EvalState::mkOutputStringRaw`, which is itself deduplicated (and generalized) with `DownstreamPlaceholder::mkOutputStringRaw`. All these changes make the unit tests simpler. (We would ideally write more unit tests for `mkSingleDerivedPathString` `coerceToSingleDerivedPath` directly, but we cannot yet do that because the IO in reading the store path won't work when the dummy store cannot hold anything. Someday we'll have a proper in-memory store which will work for this.) Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-08-14Rename `optOutputPath` to `optStaticOutputPath`John Ericson
This choice of variable name makes it more clear what is going on. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-08-10Make the Derived Path family of types inductive for dynamic derivationsJohn Ericson
We want to be able to write down `foo.drv^bar.drv^baz`: `foo.drv^bar.drv` is the dynamic derivation (since it is itself a derivation output, `bar.drv` from `foo.drv`). To that end, we create `Single{Derivation,BuiltPath}` types, that are very similar except instead of having multiple outputs (in a set or map), they have a single one. This is for everything to the left of the rightmost `^`. `NixStringContextElem` has an analogous change, and now can reuse `SingleDerivedPath` at the top level. In fact, if we ever get rid of `DrvDeep`, `NixStringContextElem` could be replaced with `SingleDerivedPath` entirely! Important note: some JSON formats have changed. We already can *produce* dynamic derivations, but we can't refer to them directly. Today, we can merely express building or example at the top imperatively over time by building `foo.drv^bar.drv`, and then with a second nix invocation doing `<result-from-first>^baz`, but this is not declarative. The ethos of Nix of being able to write down the full plan everything you want to do, and then execute than plan with a single command, and for that we need the new inductive form of these types. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-08-07Merge pull request #8692 from obsidiansystems/add-another-xp-checkThéophane Hufschmitt
Feature gate `DownstreamPlaceholder::unknownCaOutput`
2023-07-31Move evaluator settings (type and global) to separate file/headerJohn Ericson
2023-07-13Feature gate `DownstreamPlaceholder::unknownCaOutput`John Ericson
This is a part of CA derivations that we forgot to put behind the experimental feature. This was caught by @fricklerhandwerk in https://github.com/NixOS/nix/pull/8369#discussion_r1258133719
2023-07-09Clean up `SearchPath`John Ericson
- Better types - Own header / C++ file pair - Test factored out methods - Pass parsed thing around more than strings Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-07-09Clean up `resolveSearchPathElem`John Ericson
We should use `std::optional<std::string>` not `std::pair<bool, std::string>` for an optional string.
2023-07-01Merge pull request #8566 from inclyc/nixd/value-print-depthRobert Hensing
libexpr: extend `Value::print` to allow limited depth
2023-06-27Automatically document builtin constantsJohn Ericson
This is done in roughly the same way builtin functions are documented. Also auto-link experimental features for primops, subsuming PR #8371. Co-authored-by: Eelco Dolstra <edolstra@gmail.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-06-27Generialize `showType`John Ericson
2023-06-22libexpr: extend `Value::print` to allow limited depthYingchi Long
2023-05-26create pathAccessible, use it to infer default dirsYorick van Pelt
2023-05-26getDefaultNixPath: ignore EPERMYorick van Pelt
2023-05-17Upgrade `downstreamPlaceholder` to a type with methodsJohn Ericson
This gets us ready for dynamic derivation dependencies (part of RFC 92).
2023-05-15Create `EvalState::coerceToDerivedPath`John Ericson
This gives us some round trips to test. `EvalState::coerceToDerivedPathUnchecked` is a factored out helper just for unit testing.
2023-05-15Expose `mkOutputString` as method of `EvalState`John Ericson
2023-05-09prevent double quotationAlex Ameen
2023-05-09libexpr: quote reserved keys when printingAlex Ameen
This fixes a bug in commands like `nix eval' which would emit invalid attribute sets if they contained reserved keywords such as "assert", "let", etc. These keywords will not be quoted when printed, making them valid expressions. All keywords recognized by the lexer are quoted except "or", which does not require quotation.
2023-04-24Merge remote-tracking branch 'origin/master' into source-pathEelco Dolstra
2023-04-21Use `std::set<StringContextElem>` not `PathSet` for string contextsJohn Ericson
Motivation `PathSet` is not correct because string contexts have other forms (`Built` and `DrvDeep`) that are not rendered as plain store paths. Instead of wrongly using `PathSet`, or "stringly typed" using `StringSet`, use `std::std<StringContextElem>`. ----- In support of this change, `NixStringContext` is now defined as `std::std<StringContextElem>` not `std:vector<StringContextElem>`. The old definition was just used by a `getContext` method which was only used by the eval cache. It can be deleted altogether since the types are now unified and the preexisting `copyContext` function already suffices. Summarizing the previous paragraph: Old: - `value/context.hh`: `NixStringContext = std::vector<StringContextElem>` - `value.hh`: `NixStringContext Value::getContext(...)` - `value.hh`: `copyContext(...)` New: - `value/context.hh`: `NixStringContext = std::set<StringContextElem>` - `value.hh`: `copyContext(...)` ---- The string representation of string context elements no longer contains the store dir. The diff of `src/libexpr/tests/value/context.cc` should make clear what the new representation is, so we recommend reviewing that file first. This was done for two reasons: Less API churn: `Value::mkString` and friends did not take a `Store` before. But if `NixStringContextElem::{parse, to_string}` *do* take a store (as they did before), then we cannot have the `Value` functions use them (in order to work with the fully-structured `NixStringContext`) without adding that argument. That would have been a lot of churn of threading the store, and this diff is already large enough, so the easier and less invasive thing to do was simply make the element `parse` and `to_string` functions not take the `Store` reference, and the easiest way to do that was to simply drop the store dir. Space usage: Dropping the `/nix/store/` (or similar) from the internal representation will safe space in the heap of the Nix programming being interpreted. If the heap contains many strings with non-trivial contexts, the saving could add up to something significant. ---- The eval cache version is bumped. The eval cache serialization uses `NixStringContextElem::{parse, to_string}`, and since those functions are changed per the above, that means the on-disk representation is also changed. This is simply done by changing the name of the used for the eval cache from `eval-cache-v4` to eval-cache-v5`. ---- To avoid some duplication `EvalCache::mkPathString` is added to abstract over the simple case of turning a store path to a string with just that string in the context. Context This PR picks up where #7543 left off. That one introduced the fully structured `NixStringContextElem` data type, but kept `PathSet context` as an awkward middle ground between internal `char[][]` interpreter heap string contexts and `NixStringContext` fully parsed string contexts. The infelicity of `PathSet context` was specifically called out during Nix team group review, but it was agreeing that fixing it could be left as future work. This is that future work. A possible follow-up step would be to get rid of the `char[][]` evaluator heap representation, too, but it is not yet clear how to do that. To use `NixStringContextElem` there we would need to get the STL containers to GC pointers in the GC build, and I am not sure how to do that. ---- PR #7543 effectively is writing the inverse of a `mkPathString`, `mkOutputString`, and one more such function for the `DrvDeep` case. I would like that PR to have property tests ensuring it is actually the inverse as expected. This PR sets things up nicely so that reworking that PR to be in that more elegant and better tested way is possible. Co-authored-by: Théophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com>
2023-04-17Merge remote-tracking branch 'upstream/master' into source-pathRobert Hensing
2023-04-16libexpr/value/print.* -> libexpr/print.*Robert Hensing
Generalizes the file to sensibly allow printing any part of the language syntax.
2023-04-16printLiteral: Do not overloadRobert Hensing
2023-04-09Deduplicate string literal rendering, fix 4909Robert Hensing
2023-04-07Add talkative msg for coro gc debugYorick van Pelt
2023-04-07Always disable GC in a coroutine unless the patch is appliedYorick van Pelt
2023-04-07DisableGC: replace by CoroutineContext, std::shared_ptr<void>Yorick van Pelt