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