Merge pull request #11086 from kognise/eval-cache-fixes

Eval cache: fix cache regressions
This commit is contained in:
Robert Hensing 2024-07-18 14:57:07 +02:00 committed by GitHub
commit 8ce4287409
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 26 additions and 8 deletions

View file

@ -66,7 +66,7 @@ struct ExtraPathInfoValue : ExtraPathInfo
};
/**
* An Installable which corresponds a Nix langauge value, in addition to
* An Installable which corresponds a Nix language value, in addition to
* a collection of \ref DerivedPath "derived paths".
*/
struct InstallableValue : Installable

View file

@ -95,7 +95,7 @@ struct AttrDb
{
try {
auto state(_state->lock());
if (!failed)
if (!failed && state->txn->active)
state->txn->commit();
state->txn.reset();
} catch (...) {

View file

@ -699,7 +699,11 @@ struct CmdDevelop : Common, MixEnvironment
}
}
runProgramInStore(store, UseLookupPath::Use, shell, args, buildEnvironment.getSystem());
// Release our references to eval caches to ensure they are persisted to disk, because
// we are about to exec out of this process without running C++ destructors.
getEvalState()->evalCaches.clear();
execProgramInStore(store, UseLookupPath::Use, shell, args, buildEnvironment.getSystem());
#endif
}
};

View file

@ -2,6 +2,7 @@
#include <queue>
#include "command.hh"
#include "eval.hh"
#include "run.hh"
#include "strings.hh"
@ -103,7 +104,11 @@ struct CmdShell : InstallablesCommand, MixEnvironment
for (auto & arg : command)
args.push_back(arg);
runProgramInStore(store, UseLookupPath::Use, *command.begin(), args);
// Release our references to eval caches to ensure they are persisted to disk, because
// we are about to exec out of this process without running C++ destructors.
getEvalState()->evalCaches.clear();
execProgramInStore(store, UseLookupPath::Use, *command.begin(), args);
}
};

View file

@ -1,5 +1,6 @@
#include "command.hh"
#include "installable-value.hh"
#include "eval.hh"
#include "run.hh"
using namespace nix;
@ -49,7 +50,11 @@ struct CmdFmt : SourceExprCommand {
}
}
runProgramInStore(store, UseLookupPath::DontUse, app.program, programArgs);
// Release our references to eval caches to ensure they are persisted to disk, because
// we are about to exec out of this process without running C++ destructors.
evalState->evalCaches.clear();
execProgramInStore(store, UseLookupPath::DontUse, app.program, programArgs);
};
};

View file

@ -25,7 +25,7 @@ std::string chrootHelperName = "__run_in_chroot";
namespace nix {
void runProgramInStore(ref<Store> store,
void execProgramInStore(ref<Store> store,
UseLookupPath useLookupPath,
const std::string & program,
const Strings & args,
@ -128,7 +128,11 @@ struct CmdRun : InstallableValueCommand
Strings allArgs{app.program};
for (auto & i : args) allArgs.push_back(i);
runProgramInStore(store, UseLookupPath::DontUse, app.program, allArgs);
// Release our references to eval caches to ensure they are persisted to disk, because
// we are about to exec out of this process without running C++ destructors.
state->evalCaches.clear();
execProgramInStore(store, UseLookupPath::DontUse, app.program, allArgs);
}
};

View file

@ -10,7 +10,7 @@ enum struct UseLookupPath {
DontUse
};
void runProgramInStore(ref<Store> store,
void execProgramInStore(ref<Store> store,
UseLookupPath useLookupPath,
const std::string & program,
const Strings & args,