Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
eval-cache.hh
Go to the documentation of this file.
1#pragma once
3
4#include "nix/util/sync.hh"
5#include "nix/util/hash.hh"
6#include "nix/expr/eval.hh"
8
9#include <functional>
10#include <variant>
11
12namespace nix::eval_cache {
13
14struct AttrDb;
15class AttrCursor;
16
17struct CachedEvalError : CloneableError<CachedEvalError, EvalError>
18{
19private:
20 void anchor() override;
21public:
22 const ref<AttrCursor> cursor;
23 const Symbol attr;
24
25 CachedEvalError(ref<AttrCursor> cursor, Symbol attr);
26
31 [[noreturn]]
32 void force();
33};
34
35class EvalCache : public std::enable_shared_from_this<EvalCache>
36{
37 friend class AttrCursor;
38 friend struct CachedEvalError;
39
40 std::shared_ptr<AttrDb> db;
41 EvalState & state;
42 typedef fun<Value *()> RootLoader;
43 RootLoader rootLoader;
44 RootValue value;
45
46 Value * getRootValue();
47
48public:
49
50 EvalCache(std::optional<std::reference_wrapper<const Hash>> useCache, EvalState & state, RootLoader rootLoader);
51
52 ref<AttrCursor> getRoot();
53};
54
55enum AttrType {
56 Placeholder = 0,
57 FullAttrs = 1,
58 String = 2,
59 Missing = 3,
60 Misc = 4,
61 Failed = 5,
62 Bool = 6,
63 ListOfStrings = 7,
64 Int = 8,
65};
66
68{};
69
71{};
72
73struct misc_t
74{};
75
77{};
78
79struct int_t
80{
81 NixInt x;
82};
83
84typedef uint64_t AttrId;
85typedef std::pair<AttrId, Symbol> AttrKey;
86typedef std::pair<std::string, NixStringContext> string_t;
87
88typedef std::variant<
89 std::vector<Symbol>,
90 string_t,
93 misc_t,
95 bool,
96 int_t,
97 std::vector<std::string>>
98 AttrValue;
99
100class AttrCursor : public std::enable_shared_from_this<AttrCursor>
101{
102 friend class EvalCache;
103 friend struct CachedEvalError;
104
105 ref<EvalCache> root;
106 using Parent = std::optional<std::pair<ref<AttrCursor>, Symbol>>;
107 Parent parent;
108 RootValue _value;
109 std::optional<std::pair<AttrId, AttrValue>> cachedValue;
110
111 AttrKey getKey();
112
113 Value & getValue();
114
121 void fetchCachedValue();
122
123public:
124
125 AttrCursor(
126 ref<EvalCache> root,
127 Parent parent,
128 Value * value = nullptr,
129 std::optional<std::pair<AttrId, AttrValue>> && cachedValue = {});
130
131 AttrPath getAttrPath() const;
132
133 AttrPath getAttrPath(Symbol name) const;
134
135 std::string getAttrPathStr() const;
136
137 std::string getAttrPathStr(Symbol name) const;
138
139 Suggestions getSuggestionsForAttr(Symbol name);
140
141 std::shared_ptr<AttrCursor> maybeGetAttr(Symbol name);
142
143 std::shared_ptr<AttrCursor> maybeGetAttr(std::string_view name);
144
145 ref<AttrCursor> getAttr(Symbol name);
146
147 ref<AttrCursor> getAttr(std::string_view name);
148
154
155 std::string getString();
156
157 string_t getStringWithContext();
158
159 bool getBool();
160
161 NixInt getInt();
162
163 std::vector<std::string> getListOfStrings();
164
165 std::vector<Symbol> getAttrs();
166
167 bool isDerivation();
168
169 Value & forceValue();
170
175};
176
177} // namespace nix::eval_cache
Definition eval.hh:420
Definition suggestions.hh:49
Definition path.hh:33
Definition suggestions.hh:28
Definition symbol-table.hh:24
Definition eval-cache.hh:101
OrSuggestions< ref< AttrCursor > > findAlongAttrPath(const AttrPath &attrPath)
Definition eval-cache.cc:589
StorePath forceDerivation()
Definition eval-cache.cc:813
Definition fun.hh:19
Definition ref.hh:58
Definition attr-path.hh:23
Definition value.hh:1166
Definition eval-cache.cc:50
void force()
Definition eval-cache.cc:23
Definition eval-cache.hh:77
Definition eval-cache.hh:80
Definition eval-cache.hh:74
Definition eval-cache.hh:71
Definition eval-cache.hh:68
std::shared_ptr< Value * > RootValue
Definition value.hh:1632