1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 02:11:15 +02:00

Never update values after setting the type

Thunks are now overwritten by a helper function
`Value::finishValue(newType, payload)` (where `payload` is the
original anonymous union inside `Value`). This helps to ensure we
never update a value elsewhere, since that would be incompatible with
parallel evaluation (i.e. after a value has transitioned from being a
thunk to being a non-thunk, it should be immutable).

There were two places where this happened: `Value::mkString()` and
`ExprAttrs::eval()`.

This PR also adds a bunch of accessor functions for value contents,
like `Value::integer()` to access the integer field in the union.
This commit is contained in:
Eelco Dolstra 2024-03-25 18:20:18 +01:00
parent 6d90287f5a
commit 8c0590fa32
35 changed files with 530 additions and 556 deletions

View file

@ -21,10 +21,10 @@ void printAmbiguous(
}
switch (v.type()) {
case nInt:
str << v.integer;
str << v.integer();
break;
case nBool:
printLiteralBool(str, v.boolean);
printLiteralBool(str, v.boolean());
break;
case nString:
printLiteralString(str, v.string_view());
@ -36,11 +36,11 @@ void printAmbiguous(
str << "null";
break;
case nAttrs: {
if (seen && !v.attrs->empty() && !seen->insert(v.attrs).second)
if (seen && !v.attrs()->empty() && !seen->insert(v.attrs()).second)
str << "«repeated»";
else {
str << "{ ";
for (auto & i : v.attrs->lexicographicOrder(symbols)) {
for (auto & i : v.attrs()->lexicographicOrder(symbols)) {
str << symbols[i->name] << " = ";
printAmbiguous(*i->value, symbols, str, seen, depth - 1);
str << "; ";
@ -87,10 +87,10 @@ void printAmbiguous(
}
break;
case nExternal:
str << *v.external;
str << *v.external();
break;
case nFloat:
str << v.fpoint;
str << v.fpoint();
break;
default:
printError("Nix evaluator internal error: printAmbiguous: invalid value type");