Nix 2.26.3
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 "sync.hh"
5#include "hash.hh"
6#include "eval.hh"
7
8#include <functional>
9#include <variant>
10
11namespace nix::eval_cache {
12
13struct AttrDb;
14class AttrCursor;
15
16struct CachedEvalError : EvalError
17{
18 const ref<AttrCursor> cursor;
19 const Symbol attr;
20
21 CachedEvalError(ref<AttrCursor> cursor, Symbol attr);
22
27 [[noreturn]]
28 void force();
29};
30
31class EvalCache : public std::enable_shared_from_this<EvalCache>
32{
33 friend class AttrCursor;
34 friend struct CachedEvalError;
35
36 std::shared_ptr<AttrDb> db;
37 EvalState & state;
38 typedef std::function<Value *()> RootLoader;
39 RootLoader rootLoader;
40 RootValue value;
41
42 Value * getRootValue();
43
44public:
45
46 EvalCache(
47 std::optional<std::reference_wrapper<const Hash>> useCache,
48 EvalState & state,
49 RootLoader rootLoader);
50
51 ref<AttrCursor> getRoot();
52};
53
54enum AttrType {
55 Placeholder = 0,
56 FullAttrs = 1,
57 String = 2,
58 Missing = 3,
59 Misc = 4,
60 Failed = 5,
61 Bool = 6,
62 ListOfStrings = 7,
63 Int = 8,
64};
65
66struct placeholder_t {};
67struct missing_t {};
68struct misc_t {};
69struct failed_t {};
70struct int_t { NixInt x; };
71typedef uint64_t AttrId;
72typedef std::pair<AttrId, Symbol> AttrKey;
73typedef std::pair<std::string, NixStringContext> string_t;
74
75typedef std::variant<
76 std::vector<Symbol>,
77 string_t,
80 misc_t,
82 bool,
83 int_t,
84 std::vector<std::string>
85 > AttrValue;
86
87class AttrCursor : public std::enable_shared_from_this<AttrCursor>
88{
89 friend class EvalCache;
90 friend struct CachedEvalError;
91
92 ref<EvalCache> root;
93 typedef std::optional<std::pair<std::shared_ptr<AttrCursor>, Symbol>> Parent;
94 Parent parent;
95 RootValue _value;
96 std::optional<std::pair<AttrId, AttrValue>> cachedValue;
97
98 AttrKey getKey();
99
100 Value & getValue();
101
102public:
103
104 AttrCursor(
105 ref<EvalCache> root,
106 Parent parent,
107 Value * value = nullptr,
108 std::optional<std::pair<AttrId, AttrValue>> && cachedValue = {});
109
110 std::vector<Symbol> getAttrPath() const;
111
112 std::vector<Symbol> getAttrPath(Symbol name) const;
113
114 std::string getAttrPathStr() const;
115
116 std::string getAttrPathStr(Symbol name) const;
117
118 Suggestions getSuggestionsForAttr(Symbol name);
119
120 std::shared_ptr<AttrCursor> maybeGetAttr(Symbol name);
121
122 std::shared_ptr<AttrCursor> maybeGetAttr(std::string_view name);
123
124 ref<AttrCursor> getAttr(Symbol name);
125
126 ref<AttrCursor> getAttr(std::string_view name);
127
132 OrSuggestions<ref<AttrCursor>> findAlongAttrPath(const std::vector<Symbol> & attrPath);
133
134 std::string getString();
135
136 string_t getStringWithContext();
137
138 bool getBool();
139
140 NixInt getInt();
141
142 std::vector<std::string> getListOfStrings();
143
144 std::vector<Symbol> getAttrs();
145
146 bool isDerivation();
147
148 Value & forceValue();
149
154};
155
156}
Definition eval.hh:182
Definition suggestions.hh:52
Definition path.hh:27
Definition suggestions.hh:26
Definition symbol-table.hh:58
Definition eval-cache.hh:88
OrSuggestions< ref< AttrCursor > > findAlongAttrPath(const std::vector< Symbol > &attrPath)
Definition eval-cache.cc:571
StorePath forceDerivation()
Definition eval-cache.cc:770
Definition ref.hh:15
const std::string_view & name
Definition lexer.l:1709
const T & value
Definition lexer.l:492
void forceValue(Value &v, const PosIdx pos)
Value * getBool(bool b)
bool isDerivation(Value &v)
Definition value.hh:167
Definition eval-cache.cc:43
void force()
Definition eval-cache.cc:17
Definition eval-cache.hh:69
Definition eval-cache.hh:70
Definition eval-cache.hh:68
Definition eval-cache.hh:67
Definition eval-cache.hh:66
std::shared_ptr< Value * > RootValue
Definition value.hh:509