1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-02 05:11:47 +02:00

Move the InputCache to EvalState

This commit is contained in:
Eelco Dolstra 2025-04-14 14:29:14 +02:00
parent 62565ce7ce
commit e099a5bc67
7 changed files with 16 additions and 12 deletions

View file

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

View file

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

View file

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

View file

@ -202,7 +202,7 @@ static void fetchTree(
throw Error("input '%s' is not allowed to use the '__final' attribute", input.to_string());
}
auto cachedInput = fetchers::InputCache::getCache()->getAccessor(state.store, input, false);
auto cachedInput = state.inputCache->getAccessor(state.store, input, false);
auto storePath = StorePath::random(input.getName());

View file

@ -25,7 +25,7 @@ struct InputCache
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 cache;
return make_ref<InputCacheImpl>();
}
}

View file

@ -353,7 +353,7 @@ static Flake getFlake(
CopyMode copyMode)
{
// 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 lockedRef = FlakeRef(std::move(cachedInput.lockedInput), originalRef.subdir);
@ -368,7 +368,7 @@ static Flake getFlake(
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'.
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;
lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir);
}
@ -734,7 +734,7 @@ LockedFlake lockFlake(
if (auto resolvedPath = resolveRelativePath()) {
return {*resolvedPath, *input.ref};
} 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);