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

Get rid of the old eval cache

This commit is contained in:
Eelco Dolstra 2020-04-20 13:13:52 +02:00
parent 0725ab2fd7
commit 539a9c1c5f
7 changed files with 609 additions and 651 deletions

View file

@ -1,40 +1,103 @@
#pragma once
#include "sync.hh"
#include "flake.hh"
#include "path.hh"
#include "hash.hh"
#include "eval.hh"
namespace nix { struct SQLite; struct SQLiteStmt; }
#include <variant>
namespace nix::flake {
namespace nix::eval_cache {
class EvalCache
class AttrDb;
class AttrCursor;
class EvalCache : public std::enable_shared_from_this<EvalCache>
{
struct State;
friend class AttrCursor;
std::unique_ptr<Sync<State>> _state;
std::shared_ptr<AttrDb> db;
EvalState & state;
typedef std::function<Value *()> RootLoader;
RootLoader rootLoader;
RootValue value;
EvalCache();
Value * getRootValue();
public:
struct Derivation
{
StorePath drvPath;
StorePath outPath;
std::string outputName;
};
EvalCache(
bool useCache,
const Hash & fingerprint,
EvalState & state,
RootLoader rootLoader);
void addDerivation(
const Fingerprint & fingerprint,
const std::string & attrPath,
const Derivation & drv);
std::shared_ptr<AttrCursor> getRoot();
};
std::optional<Derivation> getDerivation(
const Fingerprint & fingerprint,
const std::string & attrPath);
enum AttrType {
Placeholder = 0,
FullAttrs = 1,
String = 2,
Missing = 3,
Misc = 4,
Failed = 5,
};
static EvalCache & singleton();
struct placeholder_t {};
struct missing_t {};
struct misc_t {};
struct failed_t {};
typedef uint64_t AttrId;
typedef std::pair<AttrId, Symbol> AttrKey;
typedef std::variant<std::vector<Symbol>, std::string, placeholder_t, missing_t, misc_t, failed_t> AttrValue;
class AttrCursor : public std::enable_shared_from_this<AttrCursor>
{
friend class EvalCache;
ref<EvalCache> root;
typedef std::optional<std::pair<std::shared_ptr<AttrCursor>, Symbol>> Parent;
Parent parent;
RootValue _value;
std::optional<std::pair<AttrId, AttrValue>> cachedValue;
AttrKey getKey();
Value & getValue();
public:
AttrCursor(
ref<EvalCache> root,
Parent parent,
Value * value = nullptr,
std::optional<std::pair<AttrId, AttrValue>> && cachedValue = {});
std::vector<Symbol> getAttrPath() const;
std::vector<Symbol> getAttrPath(Symbol name) const;
std::string getAttrPathStr() const;
std::string getAttrPathStr(Symbol name) const;
std::shared_ptr<AttrCursor> maybeGetAttr(Symbol name);
std::shared_ptr<AttrCursor> maybeGetAttr(std::string_view name);
std::shared_ptr<AttrCursor> getAttr(Symbol name);
std::shared_ptr<AttrCursor> getAttr(std::string_view name);
std::shared_ptr<AttrCursor> findAlongAttrPath(const std::vector<Symbol> & attrPath);
std::string getString();
std::vector<Symbol> getAttrs();
bool isDerivation();
Value & forceValue();
};
}