2019-06-07 23:25:48 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2019-06-07 23:25:48 +03:00
|
|
|
|
|
|
|
#include "sync.hh"
|
2020-04-20 14:13:52 +03:00
|
|
|
#include "hash.hh"
|
|
|
|
#include "eval.hh"
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-07-16 17:58:53 +03:00
|
|
|
#include <functional>
|
2020-04-20 14:13:52 +03:00
|
|
|
#include <variant>
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
namespace nix::eval_cache {
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-08-07 15:46:00 +03:00
|
|
|
MakeError(CachedEvalError, EvalError);
|
|
|
|
|
2020-10-06 15:00:42 +03:00
|
|
|
struct AttrDb;
|
2020-04-20 14:13:52 +03:00
|
|
|
class AttrCursor;
|
|
|
|
|
|
|
|
class EvalCache : public std::enable_shared_from_this<EvalCache>
|
|
|
|
{
|
|
|
|
friend class AttrCursor;
|
|
|
|
|
|
|
|
std::shared_ptr<AttrDb> db;
|
|
|
|
EvalState & state;
|
|
|
|
typedef std::function<Value *()> RootLoader;
|
|
|
|
RootLoader rootLoader;
|
|
|
|
RootValue value;
|
|
|
|
|
|
|
|
Value * getRootValue();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
EvalCache(
|
2020-07-16 17:58:53 +03:00
|
|
|
std::optional<std::reference_wrapper<const Hash>> useCache,
|
2020-04-20 14:13:52 +03:00
|
|
|
EvalState & state,
|
|
|
|
RootLoader rootLoader);
|
|
|
|
|
2022-04-14 15:04:19 +03:00
|
|
|
ref<AttrCursor> getRoot();
|
2020-04-20 14:13:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum AttrType {
|
|
|
|
Placeholder = 0,
|
|
|
|
FullAttrs = 1,
|
|
|
|
String = 2,
|
|
|
|
Missing = 3,
|
|
|
|
Misc = 4,
|
|
|
|
Failed = 5,
|
2020-04-27 17:29:26 +03:00
|
|
|
Bool = 6,
|
2022-04-20 17:39:47 +03:00
|
|
|
ListOfStrings = 7,
|
2022-05-16 03:28:21 +03:00
|
|
|
Int = 8,
|
2020-04-20 14:13:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct placeholder_t {};
|
|
|
|
struct missing_t {};
|
|
|
|
struct misc_t {};
|
|
|
|
struct failed_t {};
|
2022-05-16 17:36:21 +03:00
|
|
|
struct int_t { NixInt x; };
|
2020-04-20 14:13:52 +03:00
|
|
|
typedef uint64_t AttrId;
|
2022-04-26 15:16:20 +03:00
|
|
|
typedef std::pair<AttrId, Symbol> AttrKey;
|
2021-03-10 04:20:32 +02:00
|
|
|
typedef std::pair<std::string, NixStringContext> string_t;
|
2020-06-29 20:08:37 +03:00
|
|
|
|
|
|
|
typedef std::variant<
|
|
|
|
std::vector<Symbol>,
|
|
|
|
string_t,
|
|
|
|
placeholder_t,
|
|
|
|
missing_t,
|
|
|
|
misc_t,
|
|
|
|
failed_t,
|
2022-04-20 17:39:47 +03:00
|
|
|
bool,
|
2022-05-16 16:17:35 +03:00
|
|
|
int_t,
|
2022-04-20 17:39:47 +03:00
|
|
|
std::vector<std::string>
|
2020-06-29 20:08:37 +03:00
|
|
|
> AttrValue;
|
2020-04-20 14:13:52 +03:00
|
|
|
|
|
|
|
class AttrCursor : public std::enable_shared_from_this<AttrCursor>
|
2019-06-07 23:25:48 +03:00
|
|
|
{
|
2020-04-20 14:13:52 +03:00
|
|
|
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;
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
AttrKey getKey();
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
Value & getValue();
|
2019-06-07 23:25:48 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
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;
|
|
|
|
|
2022-03-04 10:44:00 +02:00
|
|
|
Suggestions getSuggestionsForAttr(Symbol name);
|
|
|
|
|
2022-04-26 15:01:21 +03:00
|
|
|
std::shared_ptr<AttrCursor> maybeGetAttr(Symbol name, bool forceErrors = false);
|
2020-04-20 14:13:52 +03:00
|
|
|
|
2022-04-26 15:01:21 +03:00
|
|
|
std::shared_ptr<AttrCursor> maybeGetAttr(std::string_view name);
|
|
|
|
|
|
|
|
ref<AttrCursor> getAttr(Symbol name, bool forceErrors = false);
|
|
|
|
|
|
|
|
ref<AttrCursor> getAttr(std::string_view name);
|
2020-04-20 14:13:52 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Get an attribute along a chain of attrsets. Note that this does
|
|
|
|
* not auto-call functors or functions.
|
|
|
|
*/
|
2022-03-04 10:44:00 +02:00
|
|
|
OrSuggestions<ref<AttrCursor>> findAlongAttrPath(const std::vector<Symbol> & attrPath, bool force = false);
|
2020-04-20 14:13:52 +03:00
|
|
|
|
|
|
|
std::string getString();
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-06-29 20:08:37 +03:00
|
|
|
string_t getStringWithContext();
|
|
|
|
|
2020-04-27 17:29:26 +03:00
|
|
|
bool getBool();
|
|
|
|
|
2022-05-13 23:02:28 +03:00
|
|
|
NixInt getInt();
|
|
|
|
|
2022-04-20 17:39:47 +03:00
|
|
|
std::vector<std::string> getListOfStrings();
|
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
std::vector<Symbol> getAttrs();
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
bool isDerivation();
|
2019-06-07 23:25:48 +03:00
|
|
|
|
2020-04-20 14:13:52 +03:00
|
|
|
Value & forceValue();
|
2020-06-29 17:39:41 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Force creation of the .drv file in the Nix store.
|
|
|
|
*/
|
2020-06-29 17:39:41 +03:00
|
|
|
StorePath forceDerivation();
|
2019-06-07 23:25:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|