mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 16:59:35 +01:00
Extract a Value method to get the eval cache
This commit is contained in:
parent
6ec852e7f0
commit
45a28ed36f
3 changed files with 30 additions and 16 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
|
#include "value-cache.hh"
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
|
|
@ -1190,23 +1191,22 @@ bool EvalState::getAttrField(Value & attrs, const std::vector<Symbol> & selector
|
||||||
Pos * pos2 = 0;
|
Pos * pos2 = 0;
|
||||||
|
|
||||||
forceValue(attrs, pos);
|
forceValue(attrs, pos);
|
||||||
if (attrs.type() == nAttrs) {
|
auto eval_cache = attrs.getEvalCache();
|
||||||
auto eval_cache = attrs.attrs->eval_cache;
|
auto [ cacheResult, resultingCursor ] = eval_cache.getValue(*this, selector, dest);
|
||||||
auto [ cacheResult, resultingCursor ] = eval_cache.getValue(*this, selector, dest);
|
updateCacheStats(cacheResult);
|
||||||
updateCacheStats(cacheResult);
|
switch (cacheResult.returnCode) {
|
||||||
switch (cacheResult.returnCode) {
|
case ValueCache::CacheHit:
|
||||||
case ValueCache::CacheHit:
|
if (cacheResult.lastQueriedSymbolIfMissing)
|
||||||
if (cacheResult.lastQueriedSymbolIfMissing)
|
return false;
|
||||||
return false;
|
return true;
|
||||||
return true;
|
case ValueCache::CacheMiss: // FIXME: Handle properly
|
||||||
case ValueCache::CacheMiss: // FIXME: Handle properly
|
case ValueCache::Forward: // FIXME: Handle properly
|
||||||
case ValueCache::Forward: // FIXME: Handle properly
|
case ValueCache::NoCacheKey:
|
||||||
case ValueCache::NoCacheKey:
|
case ValueCache::UnCacheable:
|
||||||
case ValueCache::UnCacheable:
|
;
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Value * vAttrs = &attrs;
|
Value * vAttrs = &attrs;
|
||||||
try {
|
try {
|
||||||
for (auto & name : selector) {
|
for (auto & name : selector) {
|
||||||
|
|
@ -1802,6 +1802,16 @@ std::vector<std::pair<Path, std::string>> Value::getContext()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValueCache & Value::getEvalCache()
|
||||||
|
{
|
||||||
|
if (internalType == tAttrs) {
|
||||||
|
return attrs->eval_cache;
|
||||||
|
} else {
|
||||||
|
return ValueCache::empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueCache ValueCache::empty = ValueCache(nullptr);
|
||||||
|
|
||||||
string EvalState::forceString(Value & v, PathSet & context, const Pos & pos)
|
string EvalState::forceString(Value & v, PathSet & context, const Pos & pos)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ public:
|
||||||
|
|
||||||
ValueCache(tree_cache::Cursor::Ref rawCache) : rawCache(rawCache) {}
|
ValueCache(tree_cache::Cursor::Ref rawCache) : rawCache(rawCache) {}
|
||||||
|
|
||||||
const static ValueCache empty;
|
static ValueCache empty;
|
||||||
|
|
||||||
bool isEmpty () { return rawCache == nullptr; }
|
bool isEmpty () { return rawCache == nullptr; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ class EvalState;
|
||||||
class XMLWriter;
|
class XMLWriter;
|
||||||
class JSONPlaceholder;
|
class JSONPlaceholder;
|
||||||
|
|
||||||
|
class ValueCache;
|
||||||
|
|
||||||
|
|
||||||
typedef int64_t NixInt;
|
typedef int64_t NixInt;
|
||||||
typedef double NixFloat;
|
typedef double NixFloat;
|
||||||
|
|
@ -349,6 +351,8 @@ public:
|
||||||
bool isTrivial() const;
|
bool isTrivial() const;
|
||||||
|
|
||||||
std::vector<std::pair<Path, std::string>> getContext();
|
std::vector<std::pair<Path, std::string>> getContext();
|
||||||
|
|
||||||
|
ValueCache & getEvalCache();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue