diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix index 244cfa0c2..e73c9912d 100644 --- a/doc/manual/generate-manpage.nix +++ b/doc/manual/generate-manpage.nix @@ -1,7 +1,7 @@ { command, renderLinks ? false }: with builtins; -with import ./utils.nix; +with import ; let diff --git a/doc/manual/local.mk b/doc/manual/local.mk index c1ce8aaeb..2d6612dd7 100644 --- a/doc/manual/local.mk +++ b/doc/manual/local.mk @@ -20,7 +20,7 @@ dummy-env = env -i \ NIX_STATE_DIR=/dummy \ NIX_CONFIG='cores = 0' -nix-eval = $(dummy-env) $(bindir)/nix eval --experimental-features nix-command -I nix/corepkgs=corepkgs --store dummy:// --impure --raw +nix-eval = $(dummy-env) $(bindir)/nix eval --experimental-features nix-command -I nix=doc/manual --store dummy:// --impure --raw $(d)/%.1: $(d)/src/command-ref/%.md @printf "Title: %s\n\n" "$$(basename $@ .1)" > $^.tmp diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index fd30d74be..2c1b64d7f 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1010,17 +1010,14 @@ Value * ExprPath::maybeThunk(EvalState & state, Env & env) void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) { - // FIXME: use SourcePath as cache key - auto pathKey = path.to_string(); FileEvalCache::iterator i; - if ((i = fileEvalCache.find(pathKey)) != fileEvalCache.end()) { + if ((i = fileEvalCache.find(path)) != fileEvalCache.end()) { v = i->second; return; } auto resolvedPath = resolveExprPath(path); - auto resolvedPathKey = resolvedPath.to_string(); - if ((i = fileEvalCache.find(resolvedPathKey)) != fileEvalCache.end()) { + if ((i = fileEvalCache.find(resolvedPath)) != fileEvalCache.end()) { v = i->second; return; } @@ -1028,7 +1025,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) printTalkative("evaluating file '%1%'", resolvedPath); Expr * e = nullptr; - auto j = fileParseCache.find(resolvedPathKey); + auto j = fileParseCache.find(resolvedPath); if (j != fileParseCache.end()) e = j->second; @@ -1038,24 +1035,6 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) e = parseExprFromFile(checkSourcePath(resolvedPath)); #endif - cacheFile(pathKey, resolvedPathKey, e, v, mustBeTrivial); -} - - -void EvalState::resetFileCache() -{ - fileEvalCache.clear(); - fileParseCache.clear(); -} - - -void EvalState::cacheFile( - const Path & path, - const Path & resolvedPath, - Expr * e, - Value & v, - bool mustBeTrivial) -{ fileParseCache[resolvedPath] = e; try { @@ -1066,7 +1045,7 @@ void EvalState::cacheFile( throw EvalError("file '%s' must be an attribute set", path); eval(e, v); } catch (Error & e) { - addErrorTrace(e, "while evaluating the file '%1%':", resolvedPath); + addErrorTrace(e, "while evaluating the file '%1%':", resolvedPath.to_string()); throw; } @@ -1075,6 +1054,13 @@ void EvalState::cacheFile( } +void EvalState::resetFileCache() +{ + fileEvalCache.clear(); + fileParseCache.clear(); +} + + void EvalState::eval(Expr * e, Value & v) { e->eval(*this, baseEnv, v); diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index f50a2ce26..6d7a9cb12 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -116,17 +116,17 @@ private: /* A cache from path names to parse trees. */ #if HAVE_BOEHMGC - typedef std::map, traceable_allocator > > FileParseCache; + typedef std::map, traceable_allocator>> FileParseCache; #else - typedef std::map FileParseCache; + typedef std::map FileParseCache; #endif FileParseCache fileParseCache; /* A cache from path names to values. */ #if HAVE_BOEHMGC - typedef std::map, traceable_allocator > > FileEvalCache; + typedef std::map, traceable_allocator >> FileEvalCache; #else - typedef std::map FileEvalCache; + typedef std::map FileEvalCache; #endif FileEvalCache fileEvalCache; @@ -200,14 +200,6 @@ public: trivial (i.e. doesn't require arbitrary computation). */ void evalFile(const SourcePath & path, Value & v, bool mustBeTrivial = false); - /* Like `cacheFile`, but with an already parsed expression. */ - void cacheFile( - const Path & path, - const Path & resolvedPath, - Expr * e, - Value & v, - bool mustBeTrivial = false); - void resetFileCache(); /* Look up a file in the search path. */ diff --git a/src/libfetchers/input-accessor.cc b/src/libfetchers/input-accessor.cc index 9f651dcaf..025114515 100644 --- a/src/libfetchers/input-accessor.cc +++ b/src/libfetchers/input-accessor.cc @@ -183,6 +183,7 @@ struct FSInputAccessorImpl : FSInputAccessor return false; if (allowedPaths) { + #if 0 // FIXME: this can be done more efficiently. auto p = (std::string) absPath.substr(root.size()); if (p == "") p = "/"; @@ -193,6 +194,7 @@ struct FSInputAccessorImpl : FSInputAccessor return false; p = dirOf(p); } + #endif } return true; diff --git a/src/libfetchers/input-accessor.hh b/src/libfetchers/input-accessor.hh index f58cf91af..ffa06ecd8 100644 --- a/src/libfetchers/input-accessor.hh +++ b/src/libfetchers/input-accessor.hh @@ -113,6 +113,11 @@ struct SourcePath return std::tie(accessor, path) == std::tie(x.accessor, x.path); } + bool operator != (const SourcePath & x) const + { + return std::tie(accessor, path) != std::tie(x.accessor, x.path); + } + bool operator < (const SourcePath & x) const { return std::tie(accessor, path) < std::tie(x.accessor, x.path); diff --git a/src/nix/main.cc b/src/nix/main.cc index 96ac676f5..fe78fe6af 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -178,14 +178,10 @@ static void showHelp(std::vector subcommand, MultiCommand & topleve #include "generate-manpage.nix.gen.hh" , "/"), *vGenerateManpage); - // FIXME: use MemoryAccessor - auto vUtils = state.allocValue(); - state.cacheFile( - "/utils.nix", "/utils.nix", - state.parseExprFromString( - #include "utils.nix.gen.hh" - , "/"), - *vUtils); + state.corepkgsFS->addFile( + "/utils.nix", + #include "utils.nix.gen.hh" + ); auto attrs = state.buildBindings(16); attrs.alloc("command").mkString(toplevel.toJSON().dump());