1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Move the InputCache to EvalState

This commit is contained in:
Eelco Dolstra 2025-04-14 14:29:14 +02:00
parent e3042f10af
commit 4966217b6a
7 changed files with 16 additions and 13 deletions

View file

@ -28,7 +28,6 @@
#include "nix/expr/print.hh" #include "nix/expr/print.hh"
#include "nix/util/ref.hh" #include "nix/util/ref.hh"
#include "nix/expr/value.hh" #include "nix/expr/value.hh"
#include "nix/fetchers/input-cache.hh"
#include "nix/util/strings.hh" #include "nix/util/strings.hh"
@ -459,7 +458,6 @@ ProcessLineResult NixRepl::processLine(std::string line)
else if (command == ":l" || command == ":load") { else if (command == ":l" || command == ":load") {
state->resetFileCache(); state->resetFileCache();
fetchers::InputCache::getCache()->clear();
loadFile(arg); loadFile(arg);
} }
@ -469,7 +467,6 @@ ProcessLineResult NixRepl::processLine(std::string line)
else if (command == ":r" || command == ":reload") { else if (command == ":r" || command == ":reload") {
state->resetFileCache(); state->resetFileCache();
fetchers::InputCache::getCache()->clear();
reloadFiles(); reloadFiles();
} }

View file

@ -19,6 +19,7 @@
#include "nix/util/url.hh" #include "nix/util/url.hh"
#include "nix/fetchers/fetch-to-store.hh" #include "nix/fetchers/fetch-to-store.hh"
#include "nix/fetchers/tarball.hh" #include "nix/fetchers/tarball.hh"
#include "nix/fetchers/input-cache.hh"
#include "parser-tab.hh" #include "parser-tab.hh"
@ -310,6 +311,7 @@ EvalState::EvalState(
)} )}
, store(store) , store(store)
, buildStore(buildStore ? buildStore : store) , buildStore(buildStore ? buildStore : store)
, inputCache(fetchers::InputCache::create())
, debugRepl(nullptr) , debugRepl(nullptr)
, debugStop(false) , debugStop(false)
, trylevel(0) , trylevel(0)
@ -1152,6 +1154,7 @@ void EvalState::resetFileCache()
{ {
fileEvalCache.clear(); fileEvalCache.clear();
fileParseCache.clear(); fileParseCache.clear();
inputCache->clear();
} }

View file

@ -33,7 +33,10 @@ namespace nix {
constexpr size_t maxPrimOpArity = 8; constexpr size_t maxPrimOpArity = 8;
class Store; class Store;
namespace fetchers { struct Settings; } namespace fetchers {
struct Settings;
struct InputCache;
}
struct EvalSettings; struct EvalSettings;
class EvalState; class EvalState;
class StorePath; class StorePath;
@ -300,6 +303,8 @@ public:
RootValue vImportedDrvToDerivation = nullptr; RootValue vImportedDrvToDerivation = nullptr;
ref<fetchers::InputCache> inputCache;
/** /**
* Debugger * Debugger
*/ */

View file

@ -25,7 +25,7 @@ struct InputCache
virtual void clear() = 0; virtual void clear() = 0;
static ref<InputCache> getCache(); static ref<InputCache> create();
}; };
} }

View file

@ -72,10 +72,9 @@ struct InputCacheImpl : InputCache
} }
}; };
ref<InputCache> InputCache::getCache() ref<InputCache> InputCache::create()
{ {
static auto cache = make_ref<InputCacheImpl>(); return make_ref<InputCacheImpl>();
return cache;
} }
} }

View file

@ -7,7 +7,6 @@
#include "nix_api_fetchers.h" #include "nix_api_fetchers.h"
#include "nix/flake/flake.hh" #include "nix/flake/flake.hh"
#include "nix/fetchers/input-cache.hh"
nix_flake_settings * nix_flake_settings_new(nix_c_context * context) nix_flake_settings * nix_flake_settings_new(nix_c_context * context)
{ {
@ -178,7 +177,7 @@ nix_locked_flake * nix_flake_lock(
{ {
nix_clear_err(context); nix_clear_err(context);
try { try {
nix::fetchers::InputCache::getCache()->clear(); eval_state->state.resetFileCache();
auto lockedFlake = nix::make_ref<nix::flake::LockedFlake>(nix::flake::lockFlake( auto lockedFlake = nix::make_ref<nix::flake::LockedFlake>(nix::flake::lockFlake(
*flakeSettings->settings, eval_state->state, *flakeReference->flakeRef, *flags->lockFlags)); *flakeSettings->settings, eval_state->state, *flakeReference->flakeRef, *flags->lockFlags));
return new nix_locked_flake{lockedFlake}; return new nix_locked_flake{lockedFlake};

View file

@ -341,7 +341,7 @@ static Flake getFlake(
const InputAttrPath & lockRootAttrPath) const InputAttrPath & lockRootAttrPath)
{ {
// Fetch a lazy tree first. // Fetch a lazy tree first.
auto cachedInput = fetchers::InputCache::getCache()->getAccessor(state.store, originalRef.input, useRegistries); auto cachedInput = state.inputCache->getAccessor(state.store, originalRef.input, useRegistries);
auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), originalRef.subdir); auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), originalRef.subdir);
auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), originalRef.subdir); auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), originalRef.subdir);
@ -356,7 +356,7 @@ static Flake getFlake(
debug("refetching input '%s' due to self attribute", newLockedRef); debug("refetching input '%s' due to self attribute", newLockedRef);
// FIXME: need to remove attrs that are invalidated by the changed input attrs, such as 'narHash'. // FIXME: need to remove attrs that are invalidated by the changed input attrs, such as 'narHash'.
newLockedRef.input.attrs.erase("narHash"); newLockedRef.input.attrs.erase("narHash");
auto cachedInput2 = fetchers::InputCache::getCache()->getAccessor(state.store, newLockedRef.input, useRegistries); auto cachedInput2 = state.inputCache->getAccessor(state.store, newLockedRef.input, useRegistries);
cachedInput.accessor = cachedInput2.accessor; cachedInput.accessor = cachedInput2.accessor;
lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir); lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir);
} }
@ -717,7 +717,7 @@ LockedFlake lockFlake(
if (auto resolvedPath = resolveRelativePath()) { if (auto resolvedPath = resolveRelativePath()) {
return {*resolvedPath, *input.ref}; return {*resolvedPath, *input.ref};
} else { } else {
auto cachedInput = fetchers::InputCache::getCache()->getAccessor(state.store, input.ref->input, useRegistries); auto cachedInput = state.inputCache->getAccessor(state.store, input.ref->input, useRegistries);
auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), input.ref->subdir); auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), input.ref->subdir);