Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval cache: fix cache regressions #11086

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcmd/installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...) {
Expand Down
6 changes: 5 additions & 1 deletion src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should also do this in nix shell, nix run etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to all commands.

i tried to come up with a good abstraction but couldn't come up with anything that didn't add a dependency from libcmd to nix, so i just went with the copypasta route. i also renamed runProgramInStore to execProgramInStore to better highlight the nature of the function.


execProgramInStore(store, UseLookupPath::Use, shell, args, buildEnvironment.getSystem());
#endif
}
};
Expand Down
7 changes: 6 additions & 1 deletion src/nix/env.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "command.hh"
#include "eval.hh"
#include "run.hh"
#include <queue>

Expand Down Expand Up @@ -99,7 +100,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);
}
};

Expand Down
7 changes: 6 additions & 1 deletion src/nix/fmt.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "command.hh"
#include "installable-value.hh"
#include "eval.hh"
#include "run.hh"

using namespace nix;
Expand Down Expand Up @@ -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);
};
};

Expand Down
8 changes: 6 additions & 2 deletions src/nix/run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/nix/run.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading