Nix 2.93.3
Lix: A modern, delicious implementation of the Nix 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 "lix/libutil/hash.hh"
5#include "lix/libexpr/eval.hh"
6
7#include <functional>
8#include <variant>
9
10namespace nix::eval_cache {
11
12struct AttrDb;
13class AttrCursor;
14
15typedef std::function<Value *(EvalState &)> RootLoader;
16
24class CachingEvaluator : public Evaluator
25{
29 std::map<Hash, ref<EvalCache>> caches;
30
31public:
32 using Evaluator::Evaluator;
33
34 ref<EvalCache> getCacheFor(Hash hash, RootLoader rootLoader);
35};
36
37class EvalCache : public std::enable_shared_from_this<EvalCache>
38{
39 friend class AttrCursor;
40
41 std::shared_ptr<AttrDb> db;
42 RootLoader rootLoader;
43 RootValue value;
44
45 Value * getRootValue(EvalState & state);
46
47public:
48
49 EvalCache(
50 std::optional<std::reference_wrapper<const Hash>> useCache,
51 RootLoader rootLoader);
52
53 ref<AttrCursor> getRoot();
54};
55
56enum AttrType {
57 Placeholder = 0,
58 FullAttrs = 1,
59 String = 2,
60 Missing = 3,
61 Misc = 4,
62 Failed = 5,
63 Bool = 6,
64 ListOfStrings = 7,
65 Int = 8,
66};
67
68struct placeholder_t {};
69struct fullattr_t { std::vector<std::string> p; };
70struct missing_t {};
71struct misc_t {};
72struct failed_t {};
73struct int_t { NixInt x; };
74typedef uint64_t AttrId;
75typedef std::pair<AttrId, std::string> AttrKey;
76typedef std::pair<std::string, NixStringContext> string_t;
77
78typedef std::variant<
80 string_t,
83 misc_t,
85 bool,
86 int_t,
87 std::vector<std::string>
88 > AttrValue;
89
90class AttrCursor : public std::enable_shared_from_this<AttrCursor>
91{
92 friend class EvalCache;
93
94 ref<EvalCache> root;
95 typedef std::optional<std::pair<std::shared_ptr<AttrCursor>, std::string>> Parent;
96 Parent parent;
97 RootValue _value;
98 std::optional<std::pair<AttrId, AttrValue>> cachedValue;
99
100 AttrKey getKey();
101
102 Value & getValue(EvalState & state);
103
104public:
105
106 AttrCursor(
107 ref<EvalCache> root,
108 Parent parent,
109 Value * value = nullptr,
110 std::optional<std::pair<AttrId, AttrValue>> && cachedValue = {});
111
112 std::vector<std::string> getAttrPath(EvalState & state) const;
113
114 std::vector<std::string> getAttrPath(EvalState & state, std::string_view name) const;
115
116 std::string getAttrPathStr(EvalState & state) const;
117
118 std::string getAttrPathStr(EvalState & state, std::string_view name) const;
119
120 Suggestions getSuggestionsForAttr(EvalState & state, const std::string & name);
121
122 std::shared_ptr<AttrCursor> maybeGetAttr(EvalState & state, const std::string & name);
123
124 ref<AttrCursor> getAttr(EvalState & state, const std::string & name);
125
130 OrSuggestions<ref<AttrCursor>> findAlongAttrPath(EvalState & state, const std::vector<std::string> & attrPath);
131
132 std::string getString(EvalState & state);
133
134 string_t getStringWithContext(EvalState & state);
135
136 bool getBool(EvalState & state);
137
138 NixInt getInt(EvalState & state);
139
140 std::vector<std::string> getListOfStrings(EvalState & state);
141
142 std::vector<std::string> getAttrs(EvalState & state);
143
144 bool isDerivation(EvalState & state);
145
146 Value & forceValue(EvalState & state);
147
152};
153
154}
Definition eval.hh:685
Definition suggestions.hh:55
Definition path.hh:21
Definition suggestions.hh:29
Definition eval-cache.hh:91
OrSuggestions< ref< AttrCursor > > findAlongAttrPath(EvalState &state, const std::vector< std::string > &attrPath)
Definition eval-cache.cc:532
StorePath forceDerivation(EvalState &state)
Definition eval-cache.cc:729
Definition eval-cache.hh:25
Definition ref.hh:19
Definition hash.hh:41
Definition value.hh:190
Definition eval-cache.cc:22
Definition eval-cache.hh:72
Definition eval-cache.hh:69
Definition eval-cache.hh:73
Definition eval-cache.hh:71
Definition eval-cache.hh:70
Definition eval-cache.hh:68
std::shared_ptr< Value * > RootValue
Definition value.hh:848