2010-04-07 16:59:45 +03:00
|
|
|
#include "value-to-xml.hh"
|
2006-08-24 17:16:55 +03:00
|
|
|
#include "xml-writer.hh"
|
2012-03-05 23:04:40 +02:00
|
|
|
#include "eval-inline.hh"
|
2023-10-25 07:43:36 +03:00
|
|
|
#include "signals.hh"
|
2006-08-24 17:16:55 +03:00
|
|
|
|
2008-05-21 14:17:31 +03:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2006-08-24 17:16:55 +03:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
namespace nix {
|
|
|
|
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2024-06-06 17:33:41 +03:00
|
|
|
static XMLAttrs singletonAttrs(const std::string & name, std::string_view value)
|
2006-08-24 17:16:55 +03:00
|
|
|
{
|
|
|
|
XMLAttrs attrs;
|
|
|
|
attrs[name] = value;
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 17:46:47 +03:00
|
|
|
static void printValueAsXML(EvalState & state, bool strict, bool location,
|
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-01-29 03:31:10 +02:00
|
|
|
Value & v, XMLWriter & doc, NixStringContext & context, PathSet & drvsSeen,
|
2022-03-04 20:31:59 +02:00
|
|
|
const PosIdx pos);
|
2007-01-13 17:11:10 +02:00
|
|
|
|
|
|
|
|
2022-03-05 15:40:24 +02:00
|
|
|
static void posToXML(EvalState & state, XMLAttrs & xmlAttrs, const Pos & pos)
|
2010-05-07 17:46:47 +03:00
|
|
|
{
|
2023-04-06 16:25:06 +03:00
|
|
|
if (auto path = std::get_if<SourcePath>(&pos.origin))
|
|
|
|
xmlAttrs["path"] = path->path.abs();
|
2023-03-02 16:44:19 +02:00
|
|
|
xmlAttrs["line"] = fmt("%1%", pos.line);
|
|
|
|
xmlAttrs["column"] = fmt("%1%", pos.column);
|
2010-05-07 17:46:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void showAttrs(EvalState & state, bool strict, bool location,
|
2024-03-25 19:20:18 +02:00
|
|
|
const Bindings & attrs, XMLWriter & doc, NixStringContext & context, PathSet & drvsSeen)
|
2007-01-13 17:11:10 +02:00
|
|
|
{
|
|
|
|
StringSet names;
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2024-03-25 19:20:18 +02:00
|
|
|
for (auto & a : attrs.lexicographicOrder(state.symbols)) {
|
2010-05-07 17:46:47 +03:00
|
|
|
XMLAttrs xmlAttrs;
|
2024-03-25 19:20:18 +02:00
|
|
|
xmlAttrs["name"] = state.symbols[a->name];
|
|
|
|
if (location && a->pos) posToXML(state, xmlAttrs, state.positions[a->pos]);
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2010-05-07 17:46:47 +03:00
|
|
|
XMLOpenElement _(doc, "attr", xmlAttrs);
|
|
|
|
printValueAsXML(state, strict, location,
|
2024-03-25 19:20:18 +02:00
|
|
|
*a->value, doc, context, drvsSeen, a->pos);
|
2008-08-14 15:53:29 +03:00
|
|
|
}
|
2008-08-14 13:04:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 17:46:47 +03:00
|
|
|
static void printValueAsXML(EvalState & state, bool strict, bool location,
|
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-01-29 03:31:10 +02:00
|
|
|
Value & v, XMLWriter & doc, NixStringContext & context, PathSet & drvsSeen,
|
2022-03-04 20:31:59 +02:00
|
|
|
const PosIdx pos)
|
2006-08-24 17:16:55 +03:00
|
|
|
{
|
2007-01-13 16:48:41 +02:00
|
|
|
checkInterrupt();
|
|
|
|
|
2021-11-14 03:29:31 +02:00
|
|
|
if (strict) state.forceValue(v, pos);
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2020-12-17 15:45:45 +02:00
|
|
|
switch (v.type()) {
|
2006-08-24 17:16:55 +03:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nInt:
|
2024-03-25 19:20:18 +02:00
|
|
|
doc.writeEmptyElement("int", singletonAttrs("value", fmt("%1%", v.integer())));
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2006-08-24 17:16:55 +03:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nBool:
|
2024-03-25 19:20:18 +02:00
|
|
|
doc.writeEmptyElement("bool", singletonAttrs("value", v.boolean() ? "true" : "false"));
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2006-08-24 17:16:55 +03:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nString:
|
2010-04-07 16:55:46 +03:00
|
|
|
/* !!! show the context? */
|
2010-06-10 13:29:50 +03:00
|
|
|
copyContext(v, context);
|
2023-09-26 04:30:41 +03:00
|
|
|
doc.writeEmptyElement("string", singletonAttrs("value", v.c_str()));
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2006-08-24 17:16:55 +03:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nPath:
|
2023-04-06 14:15:50 +03:00
|
|
|
doc.writeEmptyElement("path", singletonAttrs("value", v.path().to_string()));
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2007-01-13 17:11:10 +02:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nNull:
|
2010-04-07 16:55:46 +03:00
|
|
|
doc.writeEmptyElement("null");
|
|
|
|
break;
|
2007-01-13 17:11:10 +02:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nAttrs:
|
2010-04-07 16:55:46 +03:00
|
|
|
if (state.isDerivation(v)) {
|
|
|
|
XMLAttrs xmlAttrs;
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2010-04-07 16:55:46 +03:00
|
|
|
Path drvPath;
|
2024-03-25 19:20:18 +02:00
|
|
|
if (auto a = v.attrs()->get(state.sDrvPath)) {
|
2022-03-04 20:31:59 +02:00
|
|
|
if (strict) state.forceValue(*a->value, a->pos);
|
2020-12-17 15:45:45 +02:00
|
|
|
if (a->value->type() == nString)
|
2023-09-26 04:30:41 +03:00
|
|
|
xmlAttrs["drvPath"] = drvPath = a->value->c_str();
|
2010-05-07 17:46:47 +03:00
|
|
|
}
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2024-03-25 19:20:18 +02:00
|
|
|
if (auto a = v.attrs()->get(state.sOutPath)) {
|
2022-03-04 20:31:59 +02:00
|
|
|
if (strict) state.forceValue(*a->value, a->pos);
|
2020-12-17 15:45:45 +02:00
|
|
|
if (a->value->type() == nString)
|
2023-09-26 04:30:41 +03:00
|
|
|
xmlAttrs["outPath"] = a->value->c_str();
|
2010-05-07 17:46:47 +03:00
|
|
|
}
|
2010-04-07 16:55:46 +03:00
|
|
|
|
|
|
|
XMLOpenElement _(doc, "derivation", xmlAttrs);
|
|
|
|
|
2019-10-09 16:51:52 +03:00
|
|
|
if (drvPath != "" && drvsSeen.insert(drvPath).second)
|
2024-03-25 19:20:18 +02:00
|
|
|
showAttrs(state, strict, location, *v.attrs(), doc, context, drvsSeen);
|
2019-10-09 16:51:52 +03:00
|
|
|
else
|
2010-04-07 16:55:46 +03:00
|
|
|
doc.writeEmptyElement("repeated");
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
XMLOpenElement _(doc, "attrs");
|
2024-03-25 19:20:18 +02:00
|
|
|
showAttrs(state, strict, location, *v.attrs(), doc, context, drvsSeen);
|
2010-04-07 16:55:46 +03:00
|
|
|
}
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2007-01-13 17:11:10 +02:00
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nList: {
|
2010-04-07 16:55:46 +03:00
|
|
|
XMLOpenElement _(doc, "list");
|
2021-11-24 21:21:34 +02:00
|
|
|
for (auto v2 : v.listItems())
|
|
|
|
printValueAsXML(state, strict, location, *v2, doc, context, drvsSeen, pos);
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2007-01-13 17:11:10 +02:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nFunction: {
|
|
|
|
if (!v.isLambda()) {
|
|
|
|
// FIXME: Serialize primops and primopapps
|
|
|
|
doc.writeEmptyElement("unevaluated");
|
|
|
|
break;
|
|
|
|
}
|
2010-05-07 17:46:47 +03:00
|
|
|
XMLAttrs xmlAttrs;
|
2024-03-25 19:20:18 +02:00
|
|
|
if (location) posToXML(state, xmlAttrs, state.positions[v.payload.lambda.fun->pos]);
|
2010-05-07 17:46:47 +03:00
|
|
|
XMLOpenElement _(doc, "function", xmlAttrs);
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2024-03-25 19:20:18 +02:00
|
|
|
if (v.payload.lambda.fun->hasFormals()) {
|
2010-04-12 21:30:11 +03:00
|
|
|
XMLAttrs attrs;
|
2024-03-25 19:20:18 +02:00
|
|
|
if (v.payload.lambda.fun->arg) attrs["name"] = state.symbols[v.payload.lambda.fun->arg];
|
|
|
|
if (v.payload.lambda.fun->formals->ellipsis) attrs["ellipsis"] = "1";
|
2010-04-12 21:30:11 +03:00
|
|
|
XMLOpenElement _(doc, "attrspat", attrs);
|
2024-03-25 19:20:18 +02:00
|
|
|
for (auto & i : v.payload.lambda.fun->formals->lexicographicOrder(state.symbols))
|
2022-03-05 15:40:24 +02:00
|
|
|
doc.writeEmptyElement("attr", singletonAttrs("name", state.symbols[i.name]));
|
2010-04-12 21:30:11 +03:00
|
|
|
} else
|
2024-03-25 19:20:18 +02:00
|
|
|
doc.writeEmptyElement("varpat", singletonAttrs("name", state.symbols[v.payload.lambda.fun->arg]));
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2010-04-07 16:55:46 +03:00
|
|
|
break;
|
2006-08-24 17:16:55 +03:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nExternal:
|
2024-03-25 19:20:18 +02:00
|
|
|
v.external()->printValueAsXML(state, strict, location, doc, context, drvsSeen, pos);
|
2014-11-30 20:16:19 +02:00
|
|
|
break;
|
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nFloat:
|
2024-03-25 19:20:18 +02:00
|
|
|
doc.writeEmptyElement("float", singletonAttrs("value", fmt("%1%", v.fpoint())));
|
2016-01-05 01:40:40 +02:00
|
|
|
break;
|
|
|
|
|
2020-12-12 03:09:10 +02:00
|
|
|
case nThunk:
|
2010-04-07 16:55:46 +03:00
|
|
|
doc.writeEmptyElement("unevaluated");
|
2006-08-24 17:16:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-30 20:16:19 +02:00
|
|
|
void ExternalValueBase::printValueAsXML(EvalState & state, bool strict,
|
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-01-29 03:31:10 +02:00
|
|
|
bool location, XMLWriter & doc, NixStringContext & context, PathSet & drvsSeen,
|
2022-03-04 20:31:59 +02:00
|
|
|
const PosIdx pos) const
|
2014-11-30 20:16:19 +02:00
|
|
|
{
|
|
|
|
doc.writeEmptyElement("unevaluated");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 17:46:47 +03:00
|
|
|
void printValueAsXML(EvalState & state, bool strict, bool location,
|
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-01-29 03:31:10 +02:00
|
|
|
Value & v, std::ostream & out, NixStringContext & context, const PosIdx pos)
|
2006-08-24 17:16:55 +03:00
|
|
|
{
|
|
|
|
XMLWriter doc(true, out);
|
|
|
|
XMLOpenElement root(doc, "expr");
|
2015-07-17 20:24:28 +03:00
|
|
|
PathSet drvsSeen;
|
2021-11-14 03:29:31 +02:00
|
|
|
printValueAsXML(state, strict, location, v, doc, context, drvsSeen, pos);
|
2006-08-24 17:16:55 +03:00
|
|
|
}
|
2006-09-05 00:06:23 +03:00
|
|
|
|
2015-07-17 20:24:28 +03:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|