Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,12 @@ EvalCache::EvalCache(

Value * EvalCache::getRootValue()
{
if (!value) {
auto value(this->value.lock());
if (!*value) {
debug("getting root value");
value = RootValue(rootLoader());
*value = RootValue(rootLoader());
}
return *value;
return **value;
}

ref<AttrCursor> EvalCache::getRoot()
Expand All @@ -378,7 +379,7 @@ AttrCursor::AttrCursor(
, cachedValue(std::move(cachedValue))
{
if (value)
_value = RootValue(value);
*_value.lock() = RootValue(value);
}

AttrKey AttrCursor::getKey()
Expand All @@ -394,18 +395,23 @@ AttrKey AttrCursor::getKey()

Value & AttrCursor::getValue()
{
if (!_value) {
/* Note: this lock is held while the value is being evaluated,
so concurrent calls block until the value is available. Lock
ordering is strictly child -> parent, so this cannot
deadlock. */
auto value(_value.lock());
if (!*value) {
if (parent) {
auto & vParent = parent->first->getValue();
root->state.forceAttrs(vParent, noPos, "while searching for an attribute");
auto attr = vParent.attrs()->get(parent->second);
if (!attr)
throw Error("attribute '%s' is unexpectedly missing", getAttrPathStr());
_value = RootValue(attr->value);
*value = RootValue(attr->value);
} else
_value = RootValue(root->getRootValue());
*value = RootValue(root->getRootValue());
}
return **_value;
return ***value;
}

void AttrCursor::fetchCachedValue()
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/include/nix/expr/eval-cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public:
private:
typedef fun<Value *()> RootLoader;
RootLoader rootLoader;
RootValue value;
Sync<RootValue> value;

Value * getRootValue();

Expand Down Expand Up @@ -112,7 +112,7 @@ public:
private:
using Parent = std::optional<std::pair<ref<AttrCursor>, Symbol>>;
const Parent parent;
RootValue _value;
Sync<RootValue> _value;
std::optional<std::pair<AttrId, AttrValue>> cachedValue;

AttrKey getKey();
Expand Down
Loading