181class EvalState :
public std::enable_shared_from_this<EvalState>
189 const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue,
190 sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls,
191 sFile, sLine, sColumn, sFunctor, sToString,
192 sRight, sWrong, sStructuredAttrs,
193 sAllowedReferences, sAllowedRequisites, sDisallowedReferences, sDisallowedRequisites,
194 sMaxSize, sMaxClosureSize,
196 sContentAddressed, sImpure,
197 sOutputHash, sOutputHashAlgo, sOutputHashMode,
198 sRecurseForDerivations,
199 sDescription, sSelf, sEpsilon, sStartSet, sOperator, sKey, sPath,
278 RootValue vImportedDrvToDerivation =
nullptr;
285 bool inDebugger =
false;
287 std::list<DebugTrace> debugTraces;
288 std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
289 const std::shared_ptr<const StaticEnv> getStaticEnv(
const Expr & expr)
const
291 auto i = exprEnvs.find(&expr);
292 if (
i != exprEnvs.end())
295 return std::shared_ptr<const StaticEnv>();;
312 template<
class T,
typename...
Args>
313 [[nodiscard, gnu::noinline]]
328 Sync<std::unordered_map<SourcePath, StorePath>> srcToStore;
333 typedef std::unordered_map<SourcePath, Expr *, std::hash<SourcePath>, std::equal_to<SourcePath>, traceable_allocator<std::pair<const SourcePath, Expr *>>> FileParseCache;
334 FileParseCache fileParseCache;
339 typedef std::unordered_map<SourcePath, Value, std::hash<SourcePath>, std::equal_to<SourcePath>, traceable_allocator<std::pair<const SourcePath, Value>>> FileEvalCache;
340 FileEvalCache fileEvalCache;
346 std::unordered_map<SourcePath, DocCommentMap> positionToDocComment;
350 std::map<std::string, std::optional<SourcePath>> lookupPathResolved;
355 std::shared_ptr<RegexCache> regexCache;
361 std::shared_ptr<void *> valueAllocCache;
366 std::shared_ptr<void *> env1AllocCache;
379 LookupPath getLookupPath() {
return lookupPath; }
413 void checkURI(
const std::string & uri);
447 void resetFileCache();
464 bool initAccessControl =
false);
479 inline void evalAttrs(
Env & env,
Expr * e, Value & v,
const PosIdx pos, std::string_view errorCtx);
489 void tryFixupBlackHolePos(Value & v,
PosIdx pos);
500 NixInt
forceInt(Value & v,
const PosIdx pos, std::string_view errorCtx);
501 NixFloat forceFloat(Value & v,
const PosIdx pos, std::string_view errorCtx);
502 bool forceBool(Value & v,
const PosIdx pos, std::string_view errorCtx);
504 void forceAttrs(Value & v,
const PosIdx pos, std::string_view errorCtx);
506 template <
typename Callable>
507 inline void forceAttrs(Value & v, Callable getPos, std::string_view errorCtx);
509 inline void forceList(Value & v,
const PosIdx pos, std::string_view errorCtx);
514 std::string_view forceString(Value & v,
const PosIdx pos, std::string_view errorCtx);
515 std::string_view forceString(Value & v, NixStringContext & context,
const PosIdx pos, std::string_view errorCtx);
516 std::string_view forceStringNoCtx(Value & v,
const PosIdx pos, std::string_view errorCtx);
518 template<
typename...
Args>
520 void addErrorTrace(Error & e,
const Args & ... formatArgs)
const;
521 template<
typename...
Args>
523 void addErrorTrace(Error & e,
const PosIdx pos,
const Args & ... formatArgs)
const;
532 std::optional<std::string> tryAttrsToString(
const PosIdx pos, Value & v,
533 NixStringContext & context,
bool coerceMore =
false,
bool copyToStore =
true);
544 std::string_view errorCtx,
545 bool coerceMore =
false,
bool copyToStore =
true,
546 bool canonicalizePath =
true);
588 std::shared_ptr<Env *> baseEnvP;
607 std::unordered_map<std::string, Value *, std::hash<std::string>, std::equal_to<std::string>, traceable_allocator<std::pair<const std::string, Value *>>>
internalPrimOps;
619 unsigned int baseEnvDispl = 0;
621 void createBaseEnv();
623 Value * addConstant(
const std::string &
name, Value & v,
Constant info);
625 void addConstant(
const std::string &
name, Value * v,
Constant info);
627 Value * addPrimOp(
PrimOp && primOp);
647 std::optional<std::string> name;
649 std::vector<std::string> args;
663 std::optional<Doc>
getDoc(Value & v);
667 inline Value * lookupVar(
Env * env,
const ExprVar & var,
bool noEval);
669 friend struct ExprVar;
670 friend struct ExprAttrs;
671 friend struct ExprLet;
678 std::shared_ptr<StaticEnv> & staticEnv);
683 size_t callDepth = 0;
696 bool eqValues(Value & v1, Value & v2,
const PosIdx pos, std::string_view errorCtx);
707 bool isFunctor(Value &
fun);
709 void callFunction(Value &
fun, std::span<Value *>
args, Value & vRes,
const PosIdx pos);
711 void callFunction(Value &
fun, Value & arg, Value & vRes,
const PosIdx pos)
713 Value *
args[] = {&arg};
714 callFunction(
fun,
args, vRes, pos);
727 inline Env & allocEnv(
size_t size);
729 Bindings * allocBindings(
size_t capacity);
731 BindingsBuilder buildBindings(
size_t capacity)
733 return BindingsBuilder(*
this, allocBindings(capacity));
736 ListBuilder buildList(
size_t size)
738 return ListBuilder(*
this, size);
746 void mkThunk_(Value & v, Expr * expr);
747 void mkPos(Value & v, PosIdx pos);
779 const SingleDerivedPath::Built & b,
780 std::optional<StorePath> optStaticOutputPath,
781 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
789 const SingleDerivedPath &
p,
792 void concatLists(Value & v,
size_t nrLists, Value *
const * lists,
const PosIdx pos, std::string_view errorCtx);
821 [[nodiscard]] StringMap
realiseContext(
const NixStringContext & context, StorePathSet * maybePaths =
nullptr,
bool isIFD =
true);
830 std::string
realiseString(Value &
str, StorePathSet * storePathsOutMaybe,
bool isIFD =
true,
const PosIdx pos = noPos);
835 const SourcePath &
path,
838 DocComment getDocCommentForPos(PosIdx pos);
847 const SingleDerivedPath::Built & b,
848 std::optional<StorePath> optStaticOutputPath,
849 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
856 const SingleDerivedPath &
p);
858 unsigned long nrEnvs = 0;
859 unsigned long nrValuesInEnvs = 0;
860 unsigned long nrValues = 0;
861 unsigned long nrListElems = 0;
862 unsigned long nrLookups = 0;
863 unsigned long nrAttrsets = 0;
864 unsigned long nrAttrsInAttrsets = 0;
865 unsigned long nrAvoided = 0;
866 unsigned long nrOpUpdates = 0;
867 unsigned long nrOpUpdateValuesCopied = 0;
868 unsigned long nrListConcats = 0;
869 unsigned long nrPrimOpCalls = 0;
870 unsigned long nrFunctionCalls = 0;
874 typedef std::map<std::string, size_t> PrimOpCalls;
875 PrimOpCalls primOpCalls;
877 typedef std::map<ExprLambda *, size_t> FunctionCalls;
878 FunctionCalls functionCalls;
880 void incrFunctionCall(ExprLambda *
fun);
882 typedef std::map<PosIdx, size_t> AttrSelects;
883 AttrSelects attrSelects;
885 friend struct ExprOpUpdate;
886 friend struct ExprOpConcatLists;
887 friend struct ExprVar;
888 friend struct ExprString;
889 friend struct ExprInt;
890 friend struct ExprFloat;
891 friend struct ExprPath;
892 friend struct ExprSelect;
893 friend void prim_getAttr(EvalState & state,
const PosIdx pos, Value * *
args, Value & v);
894 friend void prim_match(EvalState & state,
const PosIdx pos, Value * *
args, Value & v);
895 friend void prim_split(EvalState & state,
const PosIdx pos, Value * *
args, Value & v);
898 friend class ListBuilder;