Skip to content

Commit

Permalink
addToStore(): Do evaluation on the main stack
Browse files Browse the repository at this point in the history
This hopefully avoids the need for all our Boehm GC coroutine
workarounds, since the GC roots will be on the main stack of the
thread.

Fixes NixOS#11141.
  • Loading branch information
edolstra committed Jul 22, 2024
1 parent c4213f0 commit 5cc2e56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ StorePath LocalStore::addToStoreFromDump(
});
try {
got = source.read(dumpBuffer.get() + oldSize, want);
if (!got) break;
} catch (EndOfFile &) {
inMemory = true;
break;
Expand Down
16 changes: 9 additions & 7 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ StorePath Store::addToStore(
fsm = FileSerialisationMethod::NixArchive;
break;
}
auto source = sinkToSource([&](Sink & sink) {
dumpPath(path, sink, fsm, filter);
std::optional<StorePath> storePath;
auto sink = sourceToSink([&](Source & source) {
LengthSource lengthSource(source);
storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair);
if (lengthSource.total >= settings.warnLargePathThreshold)
warn("copied large path '%s' to the store (%s)", path, renderSize(lengthSource.total));
});
LengthSource lengthSource(*source);
auto storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair);
if (lengthSource.total >= settings.warnLargePathThreshold)
warn("copied large path '%s' to the store (%s)", path, renderSize(lengthSource.total));
return storePath;
dumpPath(path, *sink, fsm, filter);
sink->finish();
return storePath.value();
}

void Store::addMultipleToStore(
Expand Down
8 changes: 4 additions & 4 deletions src/libutil/serialise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
if (!coro) {
CoroutineContext ctx;
coro = coro_t::push_type(VirtualStackAllocator{}, [&](coro_t::pull_type & yield) {
LambdaSource source([&](char *out, size_t out_len) {
LambdaSource source([&](char * out, size_t out_len) {
if (cur.empty()) {
yield();
if (yield.get()) {
return (size_t)0;
return (size_t) 0;
}
}

Expand All @@ -271,12 +271,12 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
void finish() override
{
if (!coro) return;
if (!*coro) abort();
//if (!*coro) abort();
{
CoroutineContext ctx;
(*coro)(true);
}
if (*coro) abort();
//if (*coro) abort();
}
};

Expand Down

0 comments on commit 5cc2e56

Please sign in to comment.