Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
eval.hh
Go to the documentation of this file.
1#pragma once
3
5#include "nix/expr/eval-error.hh"
7#include "nix/util/types.hh"
8#include "nix/expr/value.hh"
9#include "nix/expr/nixexpr.hh"
13#include "nix/util/position.hh"
14#include "nix/util/pos-table.hh"
15#include "nix/util/source-accessor.hh"
17#include "nix/expr/repl-exit-status.hh"
18#include "nix/util/ref.hh"
19#include "nix/expr/counter.hh"
20
21// For `NIX_USE_BOEHMGC`, and if that's set, `GC_THREADS`
22#include "nix/expr/config.hh"
23
24#include <boost/unordered/unordered_flat_map.hpp>
25#include <boost/unordered/concurrent_flat_map_fwd.hpp>
26
27#include <map>
28#include <optional>
29#include <functional>
30#include <span>
31
32namespace nix {
33
39constexpr size_t maxPrimOpArity = 8;
40
41class Store;
42
43namespace fetchers {
44struct Settings;
45struct InputCache;
46struct Input;
47} // namespace fetchers
48struct EvalSettings;
49class EvalState;
50class StorePath;
51struct SingleDerivedPath;
52enum RepairFlag : bool;
53struct MemorySourceAccessor;
54struct MountedSourceAccessor;
55
56namespace eval_cache {
57class EvalCache;
58}
59
63class CallDepth
64{
65 size_t & count;
66
67public:
68 CallDepth(size_t & count)
69 : count(count)
70 {
71 ++count;
72 }
73
74 ~CallDepth()
75 {
76 --count;
77 }
78};
79
97{
100};
101
105using PrimOpFun = void(EvalState & state, CallSite callSite, Value * const * args, Value & v);
106
110struct PrimOp
111{
115 std::string name;
116
121 std::vector<std::string> args;
122
129 size_t arity = 0;
130
134 std::optional<std::string> doc;
135
141 bool addTrace = true;
142
147
151 std::optional<ExperimentalFeature> experimentalFeature;
152
156 bool internal = false;
157
162 void check();
163};
164
165std::ostream & operator<<(std::ostream & output, const PrimOp & primOp);
166
171{
177 ValueType type = nThunk;
178
182 const char * doc = nullptr;
183
187 bool impureOnly = false;
188};
189
190typedef std::
191 map<std::string, Value *, std::less<std::string>, traceable_allocator<std::pair<const std::string, Value *>>>
192 ValMap;
193
194typedef boost::unordered_flat_map<PosIdx, DocComment, std::hash<PosIdx>> DocCommentMap;
195
196struct Env
197{
198 Env * up;
199 Value * values[0];
200};
201
202void printEnvBindings(const EvalState & es, const Expr & expr, const Env & env);
203void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, int lvl = 0);
204
205std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env);
206
207void copyContext(
208 const Value & v,
209 NixStringContext & context,
210 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
211
212std::string printValue(EvalState & state, Value & v);
213std::ostream & operator<<(std::ostream & os, const ValueType t);
214
225{
226 const Value & v;
227};
228
229std::ostream & operator<<(std::ostream & os, WhileTryingToUse w);
230
231struct RegexCache;
232
233ref<RegexCache> makeRegexCache();
234
236{
237 /* WARNING: Converting PosIdx -> Pos should be done with extra care. This is
238 due to the fact that operator[] of PosTable is incredibly expensive. */
239 std::variant<Pos, PosIdx> pos;
240 const Expr & expr;
241 const Env & env;
242 HintFmt hint;
243 bool isError;
244
245 Pos getPos(const PosTable & table) const
246 {
247 return std::visit(
249 [&](PosIdx idx) {
250 // Prefer direct pos, but if noPos then try the expr.
251 if (!idx)
252 idx = expr.getPos();
253 return table[idx];
254 },
255 [&](Pos pos) { return pos; },
256 },
257 pos);
258 }
259};
260
262{
263 Symbol with, outPath, drvPath, type, meta, name, value, system, overrides, outputs, outputName, ignoreNulls, file,
264 line, column, functor, toString, right, wrong, structuredAttrs, json, allowedReferences, allowedRequisites,
265 disallowedReferences, disallowedRequisites, maxSize, maxClosureSize, builder, args, contentAddressed, impure,
266 outputHash, outputHashAlgo, outputHashMode, recurseForDerivations, description, self, epsilon, startSet,
267 operator_, key, path, prefix, outputSpecified, requiredSystemFeatures;
268
269 Expr::AstSymbols exprSymbols;
270
271 static constexpr auto preallocate()
272 {
273 StaticSymbolTable alloc;
274
275 StaticEvalSymbols staticSymbols = {
276 .with = alloc.create("<with>"),
277 .outPath = alloc.create("outPath"),
278 .drvPath = alloc.create("drvPath"),
279 .type = alloc.create("type"),
280 .meta = alloc.create("meta"),
281 .name = alloc.create("name"),
282 .value = alloc.create("value"),
283 .system = alloc.create("system"),
284 .overrides = alloc.create("__overrides"),
285 .outputs = alloc.create("outputs"),
286 .outputName = alloc.create("outputName"),
287 .ignoreNulls = alloc.create("__ignoreNulls"),
288 .file = alloc.create("file"),
289 .line = alloc.create("line"),
290 .column = alloc.create("column"),
291 .functor = alloc.create("__functor"),
292 .toString = alloc.create("__toString"),
293 .right = alloc.create("right"),
294 .wrong = alloc.create("wrong"),
295 .structuredAttrs = alloc.create("__structuredAttrs"),
296 .json = alloc.create("__json"),
297 .allowedReferences = alloc.create("allowedReferences"),
298 .allowedRequisites = alloc.create("allowedRequisites"),
299 .disallowedReferences = alloc.create("disallowedReferences"),
300 .disallowedRequisites = alloc.create("disallowedRequisites"),
301 .maxSize = alloc.create("maxSize"),
302 .maxClosureSize = alloc.create("maxClosureSize"),
303 .builder = alloc.create("builder"),
304 .args = alloc.create("args"),
305 .contentAddressed = alloc.create("__contentAddressed"),
306 .impure = alloc.create("__impure"),
307 .outputHash = alloc.create("outputHash"),
308 .outputHashAlgo = alloc.create("outputHashAlgo"),
309 .outputHashMode = alloc.create("outputHashMode"),
310 .recurseForDerivations = alloc.create("recurseForDerivations"),
311 .description = alloc.create("description"),
312 .self = alloc.create("self"),
313 .epsilon = alloc.create(""),
314 .startSet = alloc.create("startSet"),
315 .operator_ = alloc.create("operator"),
316 .key = alloc.create("key"),
317 .path = alloc.create("path"),
318 .prefix = alloc.create("prefix"),
319 .outputSpecified = alloc.create("outputSpecified"),
320 .requiredSystemFeatures = alloc.create("requiredSystemFeatures"),
321 .exprSymbols = {
322 .sub = alloc.create("__sub"),
323 .lessThan = alloc.create("__lessThan"),
324 .mul = alloc.create("__mul"),
325 .div = alloc.create("__div"),
326 .or_ = alloc.create("or"),
327 .findFile = alloc.create("__findFile"),
328 .nixPath = alloc.create("__nixPath"),
329 .body = alloc.create("body"),
330 }};
331
332 return std::pair{staticSymbols, alloc};
333 }
334
335 static consteval StaticEvalSymbols create()
336 {
337 return preallocate().first;
338 }
339
340 static constexpr StaticSymbolTable staticSymbolTable()
341 {
342 return preallocate().second;
343 }
344};
345
346class EvalMemory
347{
348public:
350 {
351 Counter nrEnvs;
352 Counter nrValuesInEnvs;
353 Counter nrValues;
354 Counter nrAttrsets;
355 Counter nrAttrsInAttrsets;
356 Counter nrListElems;
357 };
358
359 EvalMemory();
360
361 EvalMemory(const EvalMemory &) = delete;
362 EvalMemory(EvalMemory &&) = delete;
363 EvalMemory & operator=(const EvalMemory &) = delete;
364 EvalMemory & operator=(EvalMemory &&) = delete;
365
366 inline void * allocBytes(size_t n);
367
372 template<typename T, std::size_t N = 0>
373 inline void * allocBytes(size_t count);
374
379 inline void * allocBytesAtomic(size_t n);
380
386 template<typename T, std::size_t N = 0>
387 inline void * allocBytesAtomic(size_t count);
388
389 inline Value * allocValue();
390 inline Env & allocEnv(size_t size);
391
392 Bindings * allocBindings(size_t capacity);
393
394 BindingsBuilder buildBindings(SymbolTable & symbols, size_t capacity)
395 {
396 return BindingsBuilder(*this, symbols, allocBindings(capacity), capacity);
397 }
398
399 ListBuilder buildList(size_t size)
400 {
401 stats.nrListElems += size;
402 return ListBuilder(*this, size);
403 }
404
405 const Statistics & getStats() const &
406 {
407 return stats;
408 }
409
414
415private:
416 Statistics stats;
417};
418
419class EvalState : public std::enable_shared_from_this<EvalState>
420{
421public:
422 static constexpr StaticEvalSymbols s = StaticEvalSymbols::create();
423
424 const fetchers::Settings & fetchSettings;
425 const EvalSettings & settings;
426
427 SymbolTable symbols;
428 PosTable positions;
429
430 EvalMemory mem;
431
436 RepairFlag repair;
437
442
447
452
458
459 const SourcePath derivationInternal;
460 const SourcePath importedDrvToDerivation;
461
466
471
472 const ref<fetchers::InputCache> inputCache;
473
477 ReplExitStatus (*debugRepl)(ref<EvalState> es, const ValMap & extraEnv);
478 bool debugStop;
479 bool inDebugger = false;
480 int trylevel;
481 std::list<DebugTrace> debugTraces;
482 boost::unordered_flat_map<const Expr *, const std::shared_ptr<const StaticEnv>> exprEnvs;
483
484 const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr & expr) const
485 {
486 auto i = exprEnvs.find(&expr);
487 if (i != exprEnvs.end())
488 return i->second;
489 else
490 return std::shared_ptr<const StaticEnv>();
491 ;
492 }
493
495 bool canDebug();
496
498 void runDebugRepl(const Error * error);
499
506 void runDebugRepl(const Error * error, const Env & env, const Expr & expr);
507
508 template<class T, typename... Args>
509 [[nodiscard, gnu::noinline]]
510 EvalErrorBuilder<T> & error(const Args &... args)
511 {
512 // `EvalErrorBuilder::debugThrow` performs the corresponding `delete`.
513 return *new EvalErrorBuilder<T>(*this, args...);
514 }
515
519 std::map<const Hash, ref<eval_cache::EvalCache>> evalCaches;
520
521private:
522
528
532 const ref<boost::concurrent_flat_map<
534 Value *,
535 std::hash<SourcePath>,
536 std::equal_to<SourcePath>,
537 gc_root_allocator<std::pair<const SourcePath, Value *>>>>
538 fileEvalCache;
539
545
546 LookupPath lookupPath;
547
548 struct LookupPathResolvedState
549 {
550 SourcePath path;
552 };
553
554 const ref<
555 boost::
556 concurrent_flat_map<std::string, std::shared_ptr<LookupPathResolvedState>, StringViewHash, std::equal_to<>>>
557 lookupPathResolved;
558
562 const ref<RegexCache> regexCache;
563
564public:
565
573 EvalState(
574 const LookupPath & lookupPath,
576 const fetchers::Settings & fetchSettings,
577 const EvalSettings & settings,
578 std::shared_ptr<Store> buildStore = nullptr);
579 ~EvalState();
580
585 inline Value * allocValue()
586 {
587 return mem.allocValue();
588 }
589
590 LookupPath getLookupPath()
591 {
592 return lookupPath;
593 }
594
599 SourcePath rootPath(CanonPath path);
600
604 SourcePath rootPath(std::string_view path);
605
613 SourcePath storePath(const StorePath & path);
614
621 void allowPathLegacy(const std::string & path);
622
627 void allowPath(const StorePath & storePath);
628
632 void allowClosure(const StorePath & storePath);
633
637 void allowAndSetStorePathString(const StorePath & storePath, Value & v);
638
639 void checkURI(const std::string & uri);
640
644 StorePath mountInput(fetchers::Input & input, const fetchers::Input & originalInput, ref<SourceAccessor> accessor);
645
649 Expr * parseExprFromFile(const SourcePath & path);
650 Expr * parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv);
651
655 Expr *
656 parseExprFromString(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
657 Expr * parseExprFromString(std::string s, const SourcePath & basePath);
658
663 ExprAttrs *
664 parseReplBindings(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
665 ExprAttrs * parseReplBindings(
666 std::string s,
667 std::string errorSource,
668 const SourcePath & basePath,
669 const std::shared_ptr<StaticEnv> & staticEnv);
670
671 Expr * parseStdin();
672
678 void evalFile(const SourcePath & path, Value & v, bool mustBeTrivial = false);
679
680 void resetFileCache();
681
685 SourcePath findFile(const std::string_view path);
686 SourcePath findFile(const LookupPath & lookupPath, const std::string_view path, const PosIdx pos = noPos);
687
695 std::shared_ptr<LookupPathResolvedState>
696 resolveLookupPathPath(const LookupPath::Path & elem, bool initAccessControl = false);
697
703 void eval(Expr * e, Value & v);
704
709 inline bool evalBool(Env & env, Expr * e);
710 inline bool evalBool(Env & env, Expr * e, std::string_view errorCtx);
711 inline void evalAttrs(Env & env, Expr * e, Value & v, std::string_view errorCtx);
712
719 inline void forceValue(Value & v, const PosIdx pos);
720
721private:
722
728 void handleEvalExceptionForThunk(Env * env, Expr * expr, Value & v, const PosIdx pos);
729
735 void handleEvalExceptionForApp(Value & v, const Value & savedApp);
736
737 void handleEvalFailed(Value & v, PosIdx pos);
738
739 void tryFixupBlackHolePos(Value & v, PosIdx pos);
740
741public:
742
747 void forceValueDeep(Value & v);
748
752 NixInt forceInt(Value & v, const PosIdx pos, std::string_view errorCtx);
753 NixFloat forceFloat(Value & v, const PosIdx pos, std::string_view errorCtx);
754 bool forceBool(Value & v, const PosIdx pos, std::string_view errorCtx);
755
756 void forceAttrs(Value & v, const PosIdx pos, std::string_view errorCtx);
757
758 template<typename Callable>
759 inline void forceAttrs(Value & v, Callable getPos, std::string_view errorCtx);
760
761 inline void forceList(Value & v, const PosIdx pos, std::string_view errorCtx);
765 void forceFunction(Value & v, const PosIdx pos, std::string_view errorCtx);
766 std::string_view forceString(Value & v, const PosIdx pos, std::string_view errorCtx);
767 std::string_view forceString(
768 Value & v,
769 NixStringContext & context,
770 const PosIdx pos,
771 std::string_view errorCtx,
772 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
773 std::string_view forceStringNoCtx(Value & v, const PosIdx pos, std::string_view errorCtx);
774
778 const Attr * getAttr(Symbol attrSym, const Bindings * attrSet, std::string_view errorCtx);
779
780 template<typename... Args>
781 [[gnu::noinline]]
782 void addErrorTrace(Error & e, const Args &... formatArgs) const;
783 template<typename... Args>
784 [[gnu::noinline]]
785 void addErrorTrace(Error & e, const PosIdx pos, const Args &... formatArgs) const;
786
787public:
792 bool isDerivation(Value & v);
793
820 template<typename Cb>
821 auto peelToStringOutPath(const PosIdx pos, Value & v, bool checkToStringReturn, Cb && cb)
822 -> std::invoke_result_t<Cb, Value *, bool>;
823
824 enum class CopyLazyPaths : bool {
825 PreserveLazy = false,
826 Copy = true,
827 };
828
836 void ensureLazyPathCopied(const StorePath & path);
837
842 void ensureLazyPathsCopied(const NixStringContext & context);
843
853 const PosIdx pos,
854 Value & v,
855 NixStringContext & context,
856 std::string_view errorCtx,
857 bool coerceMore = false,
858 bool copyToStore = true,
859 bool canonicalizePath = true);
860
861 StorePath copyPathToStore(NixStringContext & context, const SourcePath & path);
862
870 SourcePath coerceToPath(const PosIdx pos, Value & v, NixStringContext & context, std::string_view errorCtx);
871
875 StorePath coerceToStorePath(const PosIdx pos, Value & v, NixStringContext & context, std::string_view errorCtx);
876
880 std::pair<SingleDerivedPath, std::string_view> coerceToSingleDerivedPathUnchecked(
881 const PosIdx pos,
882 Value & v,
883 std::string_view errorCtx,
884 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
885
901 SingleDerivedPath coerceToSingleDerivedPath(const PosIdx pos, Value & v, std::string_view errorCtx);
902
903#if NIX_USE_BOEHMGC
905 const std::shared_ptr<Env *> baseEnvP;
906#endif
907
908public:
909
915
919 const std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
920
924 boost::unordered_flat_map<
925 std::string,
926 Value *,
928 std::equal_to<>,
929 traceable_allocator<std::pair<const std::string, Value *>>>
931
938 std::vector<std::pair<std::string, Constant>> constantInfos;
939
940private:
941
942 unsigned int baseEnvDispl = 0;
943
944 void createBaseEnv(const EvalSettings & settings);
945
946 Value * addConstant(const std::string & name, Value & v, Constant info);
947
948 void addConstant(const std::string & name, Value * v, Constant info);
949
950 Value * addPrimOp(PrimOp && primOp);
951
952public:
953
959 Value & getBuiltin(const std::string & name);
960
965 Value & getBuiltins();
966
967 struct Doc
968 {
969 Pos pos;
970 std::optional<std::string> name;
971 size_t arity;
972 std::vector<std::string> args;
977 const char * doc;
978 };
979
986 std::optional<Doc> getDoc(Value & v);
987
988private:
989
990 inline Value * lookupVar(Env * env, const ExprVar & var, bool noEval);
991
992 friend struct ExprVar;
993 friend struct ExprAttrs;
994 friend struct ExprLet;
995
996 Expr * parse(
997 char * text,
998 size_t length,
999 Pos::Origin origin,
1000 const SourcePath & basePath,
1001 const std::shared_ptr<StaticEnv> & staticEnv);
1002
1003 ExprAttrs * parseReplBindings(
1004 char * text,
1005 size_t length,
1006 Pos::Origin origin,
1007 const SourcePath & basePath,
1008 const std::shared_ptr<StaticEnv> & staticEnv);
1009
1014 size_t callDepth = 0;
1015
1016public:
1017
1021 inline CallDepth addCallDepth(const PosIdx pos);
1022
1027 bool eqValues(Value & v1, Value & v2, const PosIdx pos, std::string_view errorCtx);
1028
1036 void assertEqValues(Value & v1, Value & v2, const PosIdx pos, std::string_view errorCtx);
1037
1038 bool isFunctor(const Value & fun) const;
1039
1040 void callFunction(Value & fun, std::span<Value * const> args, Value & vRes, const PosIdx pos);
1041
1042 void callFunction(Value & fun, Value & arg, Value & vRes, const PosIdx pos)
1043 {
1044 callFunction(fun, std::to_array({&arg}), vRes, pos);
1045 }
1046
1051 void autoCallFunction(const Bindings & args, Value & fun, Value & res);
1052
1053 BindingsBuilder buildBindings(size_t capacity)
1054 {
1055 return mem.buildBindings(symbols, capacity);
1056 }
1057
1058 ListBuilder buildList(size_t size)
1059 {
1060 return mem.buildList(size);
1061 }
1062
1066 Value * getBool(bool b);
1067
1068 void mkThunk_(Value & v, Expr * expr);
1069 void mkPos(Value & v, PosIdx pos);
1070
1077 void mkStorePathString(const StorePath & storePath, Value & v);
1078
1099 void mkOutputString(
1100 Value & value,
1101 const SingleDerivedPath::Built & b,
1102 std::optional<StorePath> optStaticOutputPath,
1103 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
1104
1110 void mkSingleDerivedPathString(const SingleDerivedPath & p, Value & v);
1111
1115 void concatLists(Value & v, std::span<Value * const> lists, const PosIdx pos, std::string_view errorCtx);
1116
1123 void maybePrintStats();
1124
1128 void printStatistics();
1129
1136 bool fullGC();
1137
1144 [[nodiscard]] StringMap
1145 realiseContext(const NixStringContext & context, StorePathSet * maybePaths = nullptr, bool isIFD = true);
1146
1152 SourcePath realisePath(
1153 const PosIdx pos,
1154 Value & v,
1155 std::optional<SymlinkResolution> resolveSymlinks = SymlinkResolution::Full,
1156 CopyLazyPaths copyLazyPaths = CopyLazyPaths::PreserveLazy);
1157
1166 std::string
1167 realiseString(Value & str, StorePathSet * storePathsOutMaybe, bool isIFD = true, const PosIdx pos = noPos);
1168
1169 /* Call the binary path filter predicate used builtins.path etc. */
1170 bool callPathFilter(Value * filterFun, const SourcePath & path, PosIdx pos);
1171
1172 DocComment getDocCommentForPos(PosIdx pos);
1173
1174private:
1175
1180 std::string mkOutputStringRaw(
1181 const SingleDerivedPath::Built & b,
1182 std::optional<StorePath> optStaticOutputPath,
1183 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
1184
1189 std::string mkSingleDerivedPathStringRaw(const SingleDerivedPath & p);
1190
1191 Counter nrLookups;
1192 Counter nrAvoided;
1193 Counter nrOpUpdates;
1194 Counter nrOpUpdateValuesCopied;
1195 Counter nrListConcats;
1196 Counter nrPrimOpCalls;
1197 Counter nrFunctionCalls;
1198
1199 const bool countCalls;
1200
1201 typedef boost::concurrent_flat_map<std::string, size_t, StringViewHash, std::equal_to<>> PrimOpCalls;
1202 const ref<PrimOpCalls> primOpCalls;
1203
1204 typedef boost::concurrent_flat_map<ExprLambda *, size_t> FunctionCalls;
1205 const ref<FunctionCalls> functionCalls;
1206
1208 MultiEvalProfiler profiler;
1209
1210 void incrFunctionCall(ExprLambda * fun);
1211
1212 typedef boost::concurrent_flat_map<PosIdx, size_t, std::hash<PosIdx>> AttrSelects;
1213 const ref<AttrSelects> attrSelects;
1214
1215 friend struct ExprOpUpdate;
1216 friend struct ExprOpConcatLists;
1217 friend struct ExprVar;
1218 friend struct ExprString;
1219 friend struct ExprInt;
1220 friend struct ExprFloat;
1221 friend struct ExprPath;
1222 friend struct ExprSelect;
1223 friend void prim_getAttr(EvalState & state, CallSite callSite, Value * const * args, Value & v);
1224 friend void prim_match(EvalState & state, CallSite callSite, Value * const * args, Value & v);
1225 friend void prim_split(EvalState & state, CallSite callSite, Value * const * args, Value & v);
1226
1227 friend struct Value;
1228 friend class ListBuilder;
1229};
1230
1231struct DebugTraceStacker
1232{
1233 DebugTraceStacker(EvalState & evalState, DebugTrace t);
1234
1235 ~DebugTraceStacker()
1236 {
1237 evalState.debugTraces.pop_front();
1238 }
1239
1240 EvalState & evalState;
1241 DebugTrace trace;
1242};
1243
1250std::string_view showType(ValueType type, bool withArticle = true);
1251std::string showType(const Value & v);
1252
1258SourcePath resolveExprPath(SourcePath path, bool addDefaultNix = true);
1259
1263bool isAllowedURI(std::string_view uri, const Strings & allowedPaths);
1264
1265} // namespace nix
1266
1267#include "nix/expr/eval-inline.hh"
Definition args.hh:29
Definition types.hh:84
Definition attr-set.hh:448
Definition attr-set.hh:67
Definition eval.hh:64
Definition error.hh:310
Definition eval-error.hh:148
Definition eval.hh:347
void * allocBytes(size_t n)
Definition eval-inline.hh:16
void * allocBytesAtomic(size_t n)
Definition eval-inline.hh:60
Exprs exprs
Definition eval.hh:413
Definition eval.hh:420
SourcePath rootPath(CanonPath path)
Definition paths.cc:8
const ref< MountedSourceAccessor > storeFS
Definition eval.hh:441
std::optional< Doc > getDoc(Value &v)
Definition eval.cc:605
SourcePath coerceToPath(const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx)
Definition eval.cc:2654
void maybePrintStats()
Definition eval.cc:3066
void allowPathLegacy(const std::string &path)
Definition eval.cc:401
const Attr * getAttr(Symbol attrSym, const Bindings *attrSet, std::string_view errorCtx)
Definition eval.cc:2429
StorePath coerceToStorePath(const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx)
Definition eval.cc:2674
void forceValueDeep(Value &v)
Definition eval.cc:2329
bool evalBool(Env &env, Expr *e)
void allowPath(const StorePath &storePath)
Definition eval.cc:407
const ref< Store > buildStore
Definition eval.hh:470
RepairFlag repair
Definition eval.hh:436
Env & baseEnv
Definition eval.hh:914
NixInt forceInt(Value &v, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2375
void forceValue(Value &v, const PosIdx pos)
Definition eval-inline.hh:142
void mkOutputString(Value &value, const SingleDerivedPath::Built &b, std::optional< StorePath > optStaticOutputPath, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
Definition eval.cc:1027
void allowClosure(const StorePath &storePath)
Definition eval.cc:413
Value * allocValue()
Definition eval.hh:585
std::shared_ptr< LookupPathResolvedState > resolveLookupPathPath(const LookupPath::Path &elem, bool initAccessControl=false)
Definition eval.cc:3350
void evalFile(const SourcePath &path, Value &v, bool mustBeTrivial=false)
Definition eval.cc:1162
std::string realiseString(Value &str, StorePathSet *storePathsOutMaybe, bool isIFD=true, const PosIdx pos=noPos)
Definition primops.cc:66
const ref< MemorySourceAccessor > corepkgsFS
Definition eval.hh:451
void allowAndSetStorePathString(const StorePath &storePath, Value &v)
Definition eval.cc:424
StringMap realiseContext(const NixStringContext &context, StorePathSet *maybePaths=nullptr, bool isIFD=true)
Definition primops.cc:75
bool canDebug()
Definition eval.cc:801
SourcePath storePath(const StorePath &path)
Definition paths.cc:20
const ref< MemorySourceAccessor > internalFS
Definition eval.hh:457
std::pair< SingleDerivedPath, std::string_view > coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value &v, std::string_view errorCtx, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
Definition eval.cc:2682
StorePath mountInput(fetchers::Input &input, const fetchers::Input &originalInput, ref< SourceAccessor > accessor)
Definition paths.cc:64
bool eqValues(Value &v1, Value &v2, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2955
BackedStringView coerceToString(const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx, bool coerceMore=false, bool copyToStore=true, bool canonicalizePath=true)
Definition eval.cc:2521
void runDebugRepl(const Error *error)
Definition eval.cc:806
bool fullGC()
Definition eval.cc:3049
SingleDerivedPath coerceToSingleDerivedPath(const PosIdx pos, Value &v, std::string_view errorCtx)
Definition eval.cc:2711
std::map< const Hash, ref< eval_cache::EvalCache > > evalCaches
Definition eval.hh:519
void ensureLazyPathCopied(const StorePath &path)
Definition paths.cc:25
boost::unordered_flat_map< std::string, Value *, StringViewHash, std::equal_to<>, traceable_allocator< std::pair< const std::string, Value * > > > internalPrimOps
Definition eval.hh:930
void mkSingleDerivedPathString(const SingleDerivedPath &p, Value &v)
Definition eval.cc:1062
Expr * parseExprFromFile(const SourcePath &path)
Definition eval.cc:3238
const ref< SourceAccessor > rootFS
Definition eval.hh:446
SourcePath realisePath(const PosIdx pos, Value &v, std::optional< SymlinkResolution > resolveSymlinks=SymlinkResolution::Full, CopyLazyPaths copyLazyPaths=CopyLazyPaths::PreserveLazy)
Definition primops.cc:170
bool isDerivation(Value &v)
Definition eval.cc:2508
const std::shared_ptr< StaticEnv > staticBaseEnv
Definition eval.hh:919
auto peelToStringOutPath(const PosIdx pos, Value &v, bool checkToStringReturn, Cb &&cb) -> std::invoke_result_t< Cb, Value *, bool >
Definition eval-inline.hh:212
Value & getBuiltins()
Definition eval.cc:591
SourcePath findFile(const std::string_view path)
Definition eval.cc:3295
ReplExitStatus(*) debugRepl(ref< EvalState > es, const ValMap &extraEnv)
Definition eval.hh:477
Value * getBool(bool b)
Definition eval.cc:974
void printStatistics()
Definition eval.cc:3079
void eval(Expr *e, Value &v)
Definition eval.cc:1208
void autoCallFunction(const Bindings &args, Value &fun, Value &res)
Definition eval.cc:1847
void assertEqValues(Value &v1, Value &v2, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2744
ExprAttrs * parseReplBindings(std::string s, const SourcePath &basePath, const std::shared_ptr< StaticEnv > &staticEnv)
Definition eval.cc:3268
void forceFunction(Value &v, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2443
EvalState(const LookupPath &lookupPath, ref< Store > store, const fetchers::Settings &fetchSettings, const EvalSettings &settings, std::shared_ptr< Store > buildStore=nullptr)
Definition eval.cc:241
const ref< Store > store
Definition eval.hh:465
Value & getBuiltin(const std::string &name)
Definition eval.cc:596
void mkStorePathString(const StorePath &storePath, Value &v)
Definition eval.cc:1004
CallDepth addCallDepth(const PosIdx pos)
Definition eval-inline.hh:202
void concatLists(Value &v, std::span< Value *const > lists, const PosIdx pos, std::string_view errorCtx)
Concatenate values with an n-ary version of the ++ operator.
Definition eval.cc:2102
void ensureLazyPathsCopied(const NixStringContext &context)
Definition paths.cc:55
Expr * parseExprFromString(std::string s, const SourcePath &basePath, const std::shared_ptr< StaticEnv > &staticEnv)
Definition eval.cc:3251
std::vector< std::pair< std::string, Constant > > constantInfos
Definition eval.hh:938
Definition nixexpr.hh:836
Definition fmt.hh:169
Definition value.hh:173
Definition pos-idx.hh:10
Definition pos-table.hh:15
Definition globals.hh:106
Definition symbol-table.hh:234
Definition path.hh:33
Definition store-api.hh:397
Definition symbol-table.hh:266
Definition symbol-table.hh:24
Definition fun.hh:19
Definition ref.hh:58
void(EvalState &state, CallSite callSite, Value *const *args, Value &v) PrimOpFun
Definition eval.hh:105
constexpr size_t maxPrimOpArity
Definition eval.hh:39
std::set< NixStringContextElem > NixStringContext
Definition context.hh:103
Pos and AbstractPos.
Definition attr-set.hh:24
Definition eval.hh:97
PosIdx pos
Definition eval.hh:99
Definition eval.hh:171
const char * doc
Definition eval.hh:182
bool impureOnly
Definition eval.hh:187
ValueType type
Definition eval.hh:177
Definition counter.hh:15
Definition eval.hh:236
Definition eval.hh:197
Definition eval.hh:350
Definition eval-settings.hh:50
Definition eval.hh:968
const char * doc
Definition eval.hh:977
Definition configuration.hh:558
Definition nixexpr.hh:102
Definition nixexpr.hh:100
Definition search-path.hh:16
Definition position.hh:20
Definition eval.hh:111
std::vector< std::string > args
Definition eval.hh:121
bool addTrace
Definition eval.hh:141
std::optional< std::string > doc
Definition eval.hh:134
bool internal
Definition eval.hh:156
void check()
Definition eval.cc:520
std::optional< ExperimentalFeature > experimentalFeature
Definition eval.hh:151
fun< PrimOpFun > impl
Definition eval.hh:146
std::string name
Definition eval.hh:115
size_t arity
Definition eval.hh:129
Definition primops.cc:3664
Definition derived-path.hh:105
Definition source-path.hh:22
Definition nixexpr.hh:897
Definition eval.hh:262
Definition strings.hh:142
Definition value.hh:1166
Definition eval.hh:225
Definition fetch-settings.hh:27
Definition util.hh:444
std::map< std::string, std::string, std::less<> > StringMap
Definition types.hh:26
ValueType
Definition value.hh:77