lix/src/nix
John Ericson 85f0cdc370 Use std::set<StringContextElem> not PathSet for string contexts
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-21 01:05:49 -04:00
..
realisation fix spelling mistakes reported by Debian's lintian tool 2022-01-30 10:51:39 +02:00
add-file.md Split 'nix store add-to-store' into 'add-path' and 'add-file' 2020-12-04 00:59:24 +01:00
add-path.md Split 'nix store add-to-store' into 'add-path' and 'add-file' 2020-12-04 00:59:24 +01:00
add-to-store.cc No inheritance for TextInfo and FixedOutputInfo 2023-02-28 12:14:11 -05:00
app.cc Move value-only methods to InstallableValue 2023-03-16 20:06:46 -04:00
build.cc Stratify ExtraPathInfo along Installable hierarchy 2023-03-24 12:22:40 -04:00
build.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
bundle.cc Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
bundle.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
cat.cc nix store cat: Use writeFull() 2023-03-02 14:51:14 +01:00
copy.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
copy.md Add 'nix copy' manpage 2020-12-21 13:32:27 +01:00
daemon.cc Experimentally allow forcing nix-daemon trust; use this to test 2023-04-17 13:06:21 -04:00
daemon.md manual: build action -> build task 2022-11-06 13:28:18 +01:00
derivation-add.cc Create nix derivation add command 2023-04-07 08:34:58 -04:00
derivation-add.md Create nix derivation add command 2023-04-07 08:34:58 -04:00
derivation-show.cc Rename files to reflect new nix derivation show name 2023-04-07 08:34:58 -04:00
derivation-show.md Create nix derivation add command 2023-04-07 08:34:58 -04:00
derivation.cc nix show-derivation -> nix derivation show 2023-04-07 08:34:58 -04:00
develop.cc Merge pull request #7763 from obsidiansystems/installable-wide-info 2023-03-27 17:04:08 +02:00
develop.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
diff-closures.cc Get rid of some unchecked calls to std::cout 2023-03-02 15:02:24 +01:00
diff-closures.md Add 'nix store diff-closures' manpage 2020-12-21 13:32:29 +01:00
doctor.cc Add Store::isTrustedClient() 2023-04-06 19:59:57 -04:00
dump-path.cc Add 'nix store' NAR-related manpages 2020-12-21 13:32:28 +01:00
edit.cc Move value-only methods to InstallableValue 2023-03-16 20:06:46 -04:00
edit.md nix edit: support kakoune 2022-03-22 23:18:02 +09:00
eval.cc Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
eval.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
flake-archive.md Add 'nix flake' manpages 2020-12-23 18:26:40 +01:00
flake-check.md nix flake check: Fix markdown 2021-11-24 13:53:09 +01:00
flake-clone.md Add 'nix flake' manpages 2020-12-23 18:26:40 +01:00
flake-init.md Update docs 2022-02-22 14:32:56 +01:00
flake-lock.md nix flake update: Recreate the lock file 2021-02-26 14:55:54 +01:00
flake-metadata.md Merge 'nix flake {info,list-inputs}' into 'nix flake metadata' 2021-03-16 17:19:04 +01:00
flake-new.md Add 'nix flake' manpages 2020-12-23 18:26:40 +01:00
flake-prefetch.md nix store prefetch-tarball -> nix flake prefetch 2021-01-11 12:36:39 +01:00
flake-show.md Update docs 2022-02-22 14:32:56 +01:00
flake-update.md Trivial changes from the lazy-trees branch 2022-12-07 14:06:34 +01:00
flake.cc Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
flake.md src/nix/flake.md: Itemize safe nixConfigs 2023-04-18 16:06:58 +02:00
fmt.cc Move value-only methods to InstallableValue 2023-03-16 20:06:46 -04:00
fmt.md nix-fmt: add command 2022-03-11 10:00:19 -05:00
get-env.sh nix develop: Ignore some more bash special variables 2022-08-23 14:57:08 +02:00
hash.cc Merge pull request #7750 from obsidiansystems/no-args-prepare 2023-03-15 17:23:40 -04:00
help-stores.md Tweaks 2023-03-23 15:32:59 +01:00
help.md Add 'nix help' manpage 2020-12-21 13:32:29 +01:00
key-convert-secret-to-public.md Add commands for generating secret/public keys 2021-01-06 17:49:31 +01:00
key-generate-secret.md Fix missing ` in key manual 2022-06-08 11:46:50 +02:00
local.mk build: use pkg-config for lowdown 2022-11-12 23:04:58 +01:00
log.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
log.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
ls.cc Get rid of some unchecked calls to std::cout 2023-03-02 15:02:24 +01:00
main.cc Merge pull request #7798 from peeley/list-experimental-features 2023-04-11 11:55:35 +02:00
make-content-addressed.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
make-content-addressed.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
nar-cat.md Add 'nix nar' manpages 2020-12-21 13:32:28 +01:00
nar-dump-path.md Add 'nix nar' manpages 2020-12-21 13:32:28 +01:00
nar-ls.md Add 'nix nar' manpages 2020-12-21 13:32:28 +01:00
nar.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
nar.md Add 'nix nar' manpages 2020-12-21 13:32:28 +01:00
nix.md Start cross-referencing experimental features 2023-04-14 07:45:08 -04:00
optimise-store.cc Add 'nix store optimise' manpage 2020-12-21 13:32:28 +01:00
optimise-store.md Add 'nix store optimise' manpage 2020-12-21 13:32:28 +01:00
path-from-hash-part.cc Add command 'nix store path-from-hash-part' 2022-10-18 16:51:12 +02:00
path-from-hash-part.md Add command 'nix store path-from-hash-part' 2022-10-18 16:51:12 +02:00
path-info.cc Replace src/libutil/json.cc with nlohmann json generation 2022-11-16 16:50:50 +01:00
path-info.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
ping-store.cc Add Store::isTrustedClient() 2023-04-06 19:59:57 -04:00
ping-store.md Tweak 2021-01-17 19:49:28 +01:00
prefetch.cc Use "raw pattern" for content address types 2023-03-30 17:12:49 -04:00
print-dev-env.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
profile-diff-closures.md Add 'nix profile' manpage 2020-12-21 13:32:29 +01:00
profile-history.md nix profile history: Show profile date 2021-09-14 20:47:33 +02:00
profile-install.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
profile-list.md Trivial changes from the lazy-trees branch 2022-12-07 14:06:34 +01:00
profile-remove.md man: fix formatting of nix3-profile-remove 2021-06-28 16:27:03 +02:00
profile-rollback.md Generations -> profile versions 2021-09-14 19:57:45 +02:00
profile-upgrade.md Trivial changes from the lazy-trees branch 2022-12-07 14:06:34 +01:00
profile-wipe-history.md Add 'nix profile wipe-history' command 2021-09-14 20:35:41 +02:00
profile.cc Explain various .self = false, 2023-04-17 09:15:11 -04:00
profile.md Fix nix profile --help 2023-03-20 14:22:23 -04:00
realisation.cc Move enabled experimental feature to libutil struct 2023-03-20 11:05:22 -04:00
registry-add.md nix registry: add --registry flag 2021-06-30 22:13:32 +03:00
registry-list.md Add 'nix registry' manpages 2020-12-21 13:32:27 +01:00
registry-pin.md Style tweaks 2021-07-07 10:02:55 +02:00
registry-remove.md nix registry: add --registry flag 2021-06-30 22:13:32 +03:00
registry.cc Move enabled experimental feature to libutil struct 2023-03-20 11:05:22 -04:00
registry.md doc: Fix typo 2022-06-28 22:43:37 -04:00
repl.cc Stuctured command stability 2023-04-03 11:48:21 -04:00
repl.md Fix typo -- dashes not underscores 2022-10-17 14:15:32 -06:00
run.cc Move value-only methods to InstallableValue 2023-03-16 20:06:46 -04:00
run.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
run.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
search.cc Move value-only methods to InstallableValue 2023-03-16 20:06:46 -04:00
search.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
shell.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
show-config.cc nix/show-config: allow getting the value of a specific setting 2023-01-12 13:56:35 -08:00
sigs.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
store-cat.md Add 'nix store' NAR-related manpages 2020-12-21 13:32:28 +01:00
store-copy-log.cc Fix misrendering of 'nix store --help' 2023-03-21 12:02:19 +01:00
store-copy-log.md link "store derivation" to glossary definition 2022-12-21 11:42:50 +01:00
store-delete.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
store-delete.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
store-dump-path.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
store-gc.cc Deduplicate the Store downcasting with a template 2022-03-11 13:32:33 +00:00
store-gc.md Add 'nix store gc' command 2021-01-10 23:29:14 +01:00
store-ls.md Add 'nix store' NAR-related manpages 2020-12-21 13:32:28 +01:00
store-prefetch-file.md Fix some typos 2021-03-26 16:14:38 +01:00
store-repair.cc Make command infra less stateful and more regular 2023-03-15 16:29:07 -04:00
store-repair.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
store.cc Move store docs to 'nix help-stores' 2023-03-21 14:37:09 +01:00
upgrade-nix.cc Stuctured command stability 2023-04-03 11:48:21 -04:00
upgrade-nix.md Fix more profile dirs in docs 2023-03-27 12:10:32 -04:00
verify.cc Avoid some StorePath <-> Path round trips 2023-01-30 09:37:57 -05:00
verify.md clarify definition of "installable" 2023-03-05 01:46:17 +01:00
why-depends.cc Scope down --derivation to just the commands that use it 2023-02-04 18:30:02 -05:00
why-depends.md Add 'nix why-depends' manpage 2020-12-21 13:32:28 +01:00