1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 16:51: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

@ -65,24 +65,26 @@ public:
typedef Attr * iterator;
typedef const Attr * const_iterator;
void push_back(const Attr & attr)
{
assert(size_ < capacity_);
attrs[size_++] = attr;
}
iterator find(Symbol name)
const_iterator find(Symbol name) const
{
Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key);
const_iterator i = std::lower_bound(begin(), end(), key);
if (i != end() && i->name == name) return i;
return end();
}
Attr * get(Symbol name)
const Attr * get(Symbol name) const
{
Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key);
const_iterator i = std::lower_bound(begin(), end(), key);
if (i != end() && i->name == name) return &*i;
return nullptr;
}
@ -90,14 +92,22 @@ public:
iterator begin() { return &attrs[0]; }
iterator end() { return &attrs[size_]; }
const_iterator begin() const { return &attrs[0]; }
const_iterator end() const { return &attrs[size_]; }
Attr & operator[](size_t pos)
{
return attrs[pos];
}
const Attr & operator[](size_t pos) const
{
return attrs[pos];
}
void sort();
size_t capacity() { return capacity_; }
size_t capacity() const { return capacity_; }
/**
* Returns the attributes in lexicographically sorted order.
@ -166,6 +176,20 @@ public:
{
return bindings;
}
size_t capacity()
{
return bindings->capacity();
}
void grow(Bindings * newBindings)
{
for (auto & i : *bindings)
newBindings->push_back(i);
bindings = newBindings;
}
friend class ExprAttrs;
};
}