6#include "lix/libexpr/gc-alloc.hh"
19#include "lix/libutil/backed-string-view.hh"
23#include <unordered_map>
31struct SingleDerivedPath;
32enum RepairFlag : bool;
33struct MemoryInputAccessor;
57 std::vector<std::string>
args;
70 const char *
doc =
nullptr;
82 std::function<PrimOpImpl>
fun;
90std::ostream & operator<<(std::ostream & output,
PrimOp & primOp);
107 const char *
doc =
nullptr;
115using ValMap = GcMap<std::string, Value *>;
123void printEnvBindings(
const EvalState &es,
const Expr & expr,
const Env & env);
128void copyContext(
const Value & v, NixStringContext & context);
132std::ostream & operator << (std::ostream & os,
const ValueType t);
144 std::shared_ptr<Pos> pos;
149 std::shared_ptr<const DebugTrace> parent;
155 std::weak_ptr<const DebugTrace> latestTrace;
162 bool inDebugger =
false;
163 std::map<const Expr *, const std::shared_ptr<const StaticEnv>> exprEnvs;
171 : positions(positions)
173 , errorCallback(errorCallback)
175 assert(errorCallback);
180 const std::shared_ptr<const StaticEnv> staticEnvFor(
const Expr & expr)
const
182 if (
auto i = exprEnvs.find(&expr); i != exprEnvs.end()) {
197 const std::shared_ptr<const DebugTrace> entry =
nullptr;
199 explicit TraceFrame(std::shared_ptr<const DebugTrace> entry): entry(std::move(entry)) {}
211 for (
auto current = latestTrace.lock(); current; current = current->parent) {
212 co_yield current.get();
219 const Symbol outPath, drvPath, type, meta, name, value, system, overrides, outputs, outputName,
220 ignoreNulls, file, line, column, functor, toString, right, wrong, structuredAttrs,
221 allowedReferences, allowedRequisites, disallowedReferences, disallowedRequisites, maxSize,
222 maxClosureSize, builder, args, contentAddressed, impure, outputHash, outputHashAlgo,
223 outputHashMode, recurseForDerivations, description, self, startSet, operator_, key,
224 path, prefix, outputSpecified;
236 std::shared_ptr<void *> valueAllocCache;
241 std::shared_ptr<void *> env1AllocCache;
246 unsigned long nrEnvs = 0;
247 unsigned long nrValuesInEnvs = 0;
248 unsigned long nrValues = 0;
249 unsigned long nrAttrsets = 0;
250 unsigned long nrAttrsInAttrsets = 0;
251 unsigned long nrListElems = 0;
261 inline Value * allocValue();
262 inline Env & allocEnv(
size_t size);
264 Bindings * allocBindings(
size_t capacity);
265 Value newList(
size_t length);
272 const Statistics getStats()
const {
return stats; }
288 const Path & storeDir,
312 unsigned int baseEnvDispl = 0;
314 void createBaseEnv(
const SearchPath & searchPath,
const Path & storeDir);
318 void addConstant(
const std::string & name,
Value * v,
Constant info);
325 Value & get(
const std::string & name);
330 std::optional<std::string> name;
332 std::vector<std::string> args;
340 std::optional<Doc> getDoc(
Value & v);
358 std::map<SourcePath, std::shared_ptr<CachedEvalFile>>
fileEval;
366 template<
class T,
typename...
Args>
387 const SearchPath & searchPath()
const {
return searchPath_; }
395 using is_transparent = void;
398 std::map<std::string, AllowedPath, ComponentLess> children;
400 bool allowAllChildren =
false;
407 std::optional<AllowedPath> allowedPaths;
412 std::map<SourcePath, StorePath> srcToStore;
414 std::map<std::string, std::optional<std::string>> searchPathResolved;
419 std::unordered_map<Path, CheckedSourcePath> resolvedPaths;
449 void checkURI(
const std::string & uri);
468 template<
typename T,
typename E>
469 struct PathResult :
private std::variant<T, EvalErrorBuilder<E>>
471 PathResult(T p) : std::variant<T, EvalErrorBuilder<E>>(std::move(p)) {}
478 [](T & p) -> T {
return std::move(p); },
483 static_cast<std::variant<T, EvalErrorBuilder<E>
> &>(*this)
491 kj::Promise<Result<PathResult<SourcePath, ThrownError>>>
findFile(
const std::string_view path);
492 kj::Promise<Result<PathResult<SourcePath, ThrownError>>>
502 kj::Promise<Result<std::optional<std::string>>>
505 kj::Promise<Result<PathResult<StorePath, EvalError>>> copyPathToStore(
506 NixStringContext & context,
const SourcePath & path, RepairFlag repair = NoRepair
520 unsigned long nrLookups = 0;
521 unsigned long nrAvoided = 0;
522 unsigned long nrOpUpdates = 0;
523 unsigned long nrOpUpdateValuesCopied = 0;
524 unsigned long nrListConcats = 0;
525 unsigned long nrPrimOpCalls = 0;
526 unsigned long nrFunctionCalls = 0;
527 unsigned long nrThunks = 0;
529 bool countCalls =
false;
531 std::map<std::string, size_t> primOpCalls;
532 std::map<ExprLambda *, size_t> functionCalls;
533 std::map<PosIdx, size_t> attrSelects;
571 std::unique_ptr<DebugState> debug;
599 std::shared_ptr<StaticEnv> & staticEnv,
621 std::shared_ptr<StaticEnv> & staticEnv,
627 return mem.buildBindings(symbols, capacity);
694 void resetFileCache();
709 inline void evalAttrs(
Env & env,
Expr & e,
Value & v,
const PosIdx pos, std::string_view errorCtx);
731 NixFloat forceFloat(
Value & v,
const PosIdx pos, std::string_view errorCtx);
732 bool forceBool(
Value & v,
const PosIdx pos, std::string_view errorCtx);
734 void forceAttrs(
Value & v,
const PosIdx pos, std::string_view errorCtx);
735 inline void forceList(
Value & v,
const PosIdx pos, std::string_view errorCtx);
740 std::string_view forceString(
Value & v,
const PosIdx pos, std::string_view errorCtx);
741 std::string_view forceString(
Value & v, NixStringContext & context,
const PosIdx pos, std::string_view errorCtx);
742 std::string_view forceStringNoCtx(
Value & v,
const PosIdx pos, std::string_view errorCtx);
748 [[nodiscard]] StringMap
realiseContext(
const NixStringContext & context);
757 std::optional<std::string> tryAttrsToString(
const PosIdx pos,
Value & v,
758 NixStringContext & context,
bool coerceMore =
false,
bool copyToStore =
true);
769 std::string_view errorCtx,
770 bool coerceMore =
false,
bool copyToStore =
true,
771 bool canonicalizePath =
true);
820 size_t callDepth = 0;
830 bool isFunctor(
Value & fun);
837 Value * args[] = {&arg};
838 callFunction(fun, 1, args, vRes, pos);
847 void mkPos(Value & v, PosIdx pos);
871 const SingleDerivedPath::Built & b,
872 std::optional<StorePath> optStaticOutputPath,
873 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
881 const SingleDerivedPath & p,
884 void concatLists(Value & v,
size_t nrLists, Value * * lists,
const PosIdx pos, std::string_view errorCtx);
892 std::string mkOutputStringRaw(
893 const SingleDerivedPath::Built & b,
894 std::optional<StorePath> optStaticOutputPath,
895 const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
901 std::string mkSingleDerivedPathStringRaw(
902 const SingleDerivedPath & p);
911std::string_view showType(ValueType type,
bool withArticle =
true);
912std::string showType(
const Value & v);
914static constexpr std::string_view corepkgsPrefix{
"/__corepkgs__/"};
Definition backed-string-view.hh:17
Definition attr-set.hh:129
Definition attr-set.hh:49
Definition source-path.hh:89
Env & env
Definition eval.hh:296
std::vector< std::pair< std::string, Constant > > constantInfos
Definition eval.hh:309
std::shared_ptr< StaticEnv > staticEnv
Definition eval.hh:301
Definition eval-error.hh:59
Definition eval-error.hh:23
void allowPath(const Path &path)
Definition eval.cc:374
kj::Promise< Result< std::optional< std::string > > > resolveSearchPathPath(const SearchPath::Path &path)
Definition eval.cc:2840
void allowAndSetStorePathString(const StorePath &storePath, Value &v)
Definition eval.cc:395
CheckedSourcePath checkSourcePath(const SourcePath &path)
Definition eval.cc:402
CheckedSourcePath resolveExprPath(SourcePath path)
Definition eval.cc:2731
Path toRealPath(const Path &path, const NixStringContext &context)
Definition eval.cc:521
void mkStorePathString(const StorePath &storePath, Value &v)
Definition eval.cc:883
kj::Promise< Result< PathResult< SourcePath, ThrownError > > > findFile(const std::string_view path)
Definition eval.cc:2802
StringMap realiseContext(const NixStringContext &context)
Definition primops.cc:47
SourcePath coerceToPath(const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx)
Definition eval.cc:2431
StorePath coerceToStorePath(const PosIdx pos, Value &v, NixStringContext &context, std::string_view errorCtx)
Definition eval.cc:2440
void forceValueDeep(Value &v)
Definition eval.cc:2116
NixInt forceInt(Value &v, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2153
void forceValue(Value &v, const PosIdx pos)
Definition eval-inline.hh:69
void mkOutputString(Value &value, const SingleDerivedPath::Built &b, std::optional< StorePath > optStaticOutputPath, const ExperimentalFeatureSettings &xpSettings=experimentalFeatureSettings)
Definition eval.cc:908
std::pair< SingleDerivedPath, std::string_view > coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value &v, std::string_view errorCtx)
Definition eval.cc:2449
void evalFile(const SourcePath &path, Value &v)
Definition eval.cc:994
bool eqValues(Value &v1, Value &v2, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2506
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:2306
SingleDerivedPath coerceToSingleDerivedPath(const PosIdx pos, Value &v, std::string_view errorCtx)
Definition eval.cc:2479
void mkSingleDerivedPathString(const SingleDerivedPath &p, Value &v)
Definition eval.cc:946
bool isDerivation(Value &v)
Definition eval.cc:2280
void eval(Expr &e, Value &v)
Definition eval.cc:1040
void autoCallFunction(Bindings &args, Value &fun, Value &res)
Definition eval.cc:1789
void forceFunction(Value &v, const PosIdx pos, std::string_view errorCtx)
Definition eval.cc:2219
bool evalBool(Env &env, Expr &e)
void printStatistics()
Definition eval.cc:2613
void evalLazily(Expr &e, Value &v)
Definition eval.cc:863
box_ptr< EvalState > begin(AsyncIoRoot &aio)
Definition eval.cc:355
Expr & parseExprFromString(std::string s, const SourcePath &basePath, std::shared_ptr< StaticEnv > &staticEnv, const FeatureSettings &xpSettings=featureSettings)
Definition eval.cc:2769
const ref< Store > store
Definition eval.hh:564
RepairFlag repair
Definition eval.hh:559
bool fullGC()
Definition eval.cc:2584
Expr & parseExprFromFile(const CheckedSourcePath &path)
Definition eval.cc:2756
ref< Store > buildStore
Definition eval.hh:569
void maybePrintStats()
Definition eval.cc:2598
Definition pos-table.hh:16
Definition symbol-table.hh:75
Definition symbol-table.hh:52
void(EvalState &state, PosIdx pos, Value **args, Value &v) PrimOpImpl
Definition eval.hh:41
ReplExitStatus
Definition repl-exit-status.hh:9
const char * doc
Definition eval.hh:107
bool impureOnly
Definition eval.hh:112
ValueType type
Definition eval.hh:102
Generator< const DebugTrace * > traces()
Definition eval.hh:209
const char * doc
Definition eval.hh:337
std::shared_ptr< RegexCache > regexes
Definition eval.hh:353
std::map< SourcePath, std::shared_ptr< CachedEvalFile > > fileEval
Definition eval.hh:358
Definition nixexpr.hh:333
Definition nixexpr.hh:385
Definition nixexpr.hh:246
Definition nixexpr.hh:108
Definition generator.hh:236
Definition position.hh:19
std::vector< std::string > args
Definition eval.hh:57
bool isCompactTrace
Definition eval.hh:77
std::function< PrimOpImpl > fun
Definition eval.hh:82
std::optional< ExperimentalFeature > experimentalFeature
Definition eval.hh:87
std::string name
Definition eval.hh:51
size_t arity
Definition eval.hh:65
const char * doc
Definition eval.hh:70
Definition primops.cc:2567
Definition search-path.hh:83
Definition search-path.hh:16
Definition derived-path.hh:101
Definition source-path.hh:23
Definition nixexpr.hh:478
std::string Path
Definition types.hh:28
constexpr NeverAsync always_progresses
Definition types.hh:175
ValueType
Definition value.hh:49
std::shared_ptr< Value * > RootValue
Definition value.hh:851