addToStore(): Do evaluation on the main stack

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 #11141.
This commit is contained in:
Eelco Dolstra 2024-07-22 15:10:47 +02:00
parent b13ba7490c
commit 0194f81587
3 changed files with 14 additions and 11 deletions

View file

@ -1245,6 +1245,7 @@ StorePath LocalStore::addToStoreFromDump(
}); });
try { try {
got = source.read(dumpBuffer.get() + oldSize, want); got = source.read(dumpBuffer.get() + oldSize, want);
if (!got) break;
} catch (EndOfFile &) { } catch (EndOfFile &) {
inMemory = true; inMemory = true;
break; break;

View file

@ -210,14 +210,16 @@ StorePath Store::addToStore(
fsm = FileSerialisationMethod::NixArchive; fsm = FileSerialisationMethod::NixArchive;
break; break;
} }
auto source = sinkToSource([&](Sink & sink) { std::optional<StorePath> storePath;
dumpPath(path, sink, fsm, filter); 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); dumpPath(path, *sink, fsm, filter);
auto storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair); sink->finish();
if (lengthSource.total >= settings.warnLargePathThreshold) return storePath.value();
warn("copied large path '%s' to the store (%s)", path, renderSize(lengthSource.total));
return storePath;
} }
void Store::addMultipleToStore( void Store::addMultipleToStore(

View file

@ -243,11 +243,11 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
if (!coro) { if (!coro) {
CoroutineContext ctx; CoroutineContext ctx;
coro = coro_t::push_type(VirtualStackAllocator{}, [&](coro_t::pull_type & yield) { 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()) { if (cur.empty()) {
yield(); yield();
if (yield.get()) { if (yield.get()) {
return (size_t)0; return (size_t) 0;
} }
} }
@ -271,12 +271,12 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
void finish() override void finish() override
{ {
if (!coro) return; if (!coro) return;
if (!*coro) abort(); //if (!*coro) abort();
{ {
CoroutineContext ctx; CoroutineContext ctx;
(*coro)(true); (*coro)(true);
} }
if (*coro) abort(); //if (*coro) abort();
} }
}; };