#pragma once #include "sync.hh" #include "hash.hh" #include "eval.hh" #include namespace nix::eval_cache { class AttrDb; class AttrCursor; class EvalCache : public std::enable_shared_from_this { friend class AttrCursor; std::shared_ptr db; EvalState & state; typedef std::function RootLoader; RootLoader rootLoader; RootValue value; Value * getRootValue(); public: EvalCache( bool useCache, const Hash & fingerprint, EvalState & state, RootLoader rootLoader); std::shared_ptr getRoot(); }; enum AttrType { Placeholder = 0, FullAttrs = 1, String = 2, Missing = 3, Misc = 4, Failed = 5, Bool = 6, }; struct placeholder_t {}; struct missing_t {}; struct misc_t {}; struct failed_t {}; typedef uint64_t AttrId; typedef std::pair AttrKey; typedef std::variant, std::string, placeholder_t, missing_t, misc_t, failed_t, bool> AttrValue; class AttrCursor : public std::enable_shared_from_this { friend class EvalCache; ref root; typedef std::optional, Symbol>> Parent; Parent parent; RootValue _value; std::optional> cachedValue; AttrKey getKey(); Value & getValue(); public: AttrCursor( ref root, Parent parent, Value * value = nullptr, std::optional> && cachedValue = {}); std::vector getAttrPath() const; std::vector getAttrPath(Symbol name) const; std::string getAttrPathStr() const; std::string getAttrPathStr(Symbol name) const; std::shared_ptr maybeGetAttr(Symbol name); std::shared_ptr maybeGetAttr(std::string_view name); std::shared_ptr getAttr(Symbol name); std::shared_ptr getAttr(std::string_view name); std::shared_ptr findAlongAttrPath(const std::vector & attrPath); std::string getString(); bool getBool(); std::vector getAttrs(); bool isDerivation(); Value & forceValue(); /* Force creation of the .drv file in the Nix store. */ StorePath forceDerivation(); }; }