@@ -142,8 +142,8 @@ Goal::Co DerivationGoal::init() {
142142 substitute. */
143143
144144 if (buildMode != bmNormal || !worker.evalStore .isValidPath (drvPath)) {
145- addWaitee ( upcast_goal (worker.makePathSubstitutionGoal (drvPath))) ;
146- co_await Suspend{} ;
145+ Goals waitees{ upcast_goal (worker.makePathSubstitutionGoal (drvPath))} ;
146+ co_await await ( std::move (waitees)) ;
147147 }
148148
149149 trace (" loading derivation" );
@@ -235,14 +235,16 @@ Goal::Co DerivationGoal::haveDerivation()
235235 }
236236 }
237237
238+ Goals waitees;
239+
238240 /* We are first going to try to create the invalid output paths
239241 through substitutes. If that doesn't work, we'll build
240242 them. */
241243 if (settings.useSubstitutes && drvOptions->substitutesAllowed ())
242244 for (auto & [outputName, status] : initialOutputs) {
243245 if (!status.wanted ) continue ;
244246 if (!status.known )
245- addWaitee (
247+ waitees. insert (
246248 upcast_goal (
247249 worker.makeDrvOutputSubstitutionGoal (
248250 DrvOutput{status.outputHash , outputName},
@@ -252,14 +254,14 @@ Goal::Co DerivationGoal::haveDerivation()
252254 );
253255 else {
254256 auto * cap = getDerivationCA (*drv);
255- addWaitee (upcast_goal (worker.makePathSubstitutionGoal (
257+ waitees. insert (upcast_goal (worker.makePathSubstitutionGoal (
256258 status.known ->path ,
257259 buildMode == bmRepair ? Repair : NoRepair,
258260 cap ? std::optional { *cap } : std::nullopt )));
259261 }
260262 }
261263
262- if (!waitees. empty ()) co_await Suspend{}; /* to prevent hang (no wake-up event) */
264+ co_await await ( std::move (waitees));
263265
264266 trace (" all outputs substituted (maybe)" );
265267
@@ -342,6 +344,8 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
342344 is no need to restart. */
343345 needRestart = NeedRestartForMoreOutputs::BuildInProgressWillNotNeed;
344346
347+ Goals waitees;
348+
345349 std::map<ref<const SingleDerivedPath>, GoalPtr, value_comparison> inputGoals;
346350
347351 if (useDerivation) {
@@ -356,7 +360,7 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
356360 },
357361 buildMode == bmRepair ? bmRepair : bmNormal);
358362 inputGoals.insert_or_assign (inputDrv, g);
359- addWaitee (std::move (g));
363+ waitees. insert (std::move (g));
360364 }
361365 for (const auto & [outputName, childNode] : inputNode.childMap )
362366 addWaiteeDerivedPath (
@@ -397,10 +401,11 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
397401 if (!settings.useSubstitutes )
398402 throw Error (" dependency '%s' of '%s' does not exist, and substitution is disabled" ,
399403 worker.store .printStorePath (i), worker.store .printStorePath (drvPath));
400- addWaitee (upcast_goal (worker.makePathSubstitutionGoal (i)));
404+ waitees. insert (upcast_goal (worker.makePathSubstitutionGoal (i)));
401405 }
402406
403- if (!waitees.empty ()) co_await Suspend{}; /* to prevent hang (no wake-up event) */
407+ co_await await (std::move (waitees));
408+
404409
405410 trace (" all inputs realised" );
406411
@@ -495,9 +500,11 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
495500
496501 resolvedDrvGoal = worker.makeDerivationGoal (
497502 pathResolved, wantedOutputs, buildMode);
498- addWaitee (resolvedDrvGoal);
503+ {
504+ Goals waitees{resolvedDrvGoal};
505+ co_await await (std::move (waitees));
506+ }
499507
500- co_await Suspend{};
501508 co_return resolvedFinished ();
502509 }
503510
@@ -536,8 +543,7 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
536543 /* Okay, try to build. Note that here we don't wait for a build
537544 slot to become available, since we don't need one if there is a
538545 build hook. */
539- worker.wakeUp (shared_from_this ());
540- co_await Suspend{};
546+ co_await yield ();
541547 co_return tryToBuild ();
542548}
543549
@@ -602,8 +608,7 @@ Goal::Co DerivationGoal::tryToBuild()
602608 /* Wait then try locking again, repeat until success (returned
603609 boolean is true). */
604610 do {
605- worker.waitForAWhile (shared_from_this ());
606- co_await Suspend{};
611+ co_await waitForAWhile ();
607612 } while (!outputLocks.lockPaths (lockFiles, " " , false ));
608613 }
609614
@@ -667,8 +672,7 @@ Goal::Co DerivationGoal::tryToBuild()
667672
668673 actLock.reset ();
669674
670- worker.wakeUp (shared_from_this ());
671- co_await Suspend{};
675+ co_await yield ();
672676 co_return tryLocalBuild ();
673677}
674678
@@ -719,6 +723,8 @@ Goal::Co DerivationGoal::repairClosure()
719723 outputsToDrv.insert_or_assign (*j.second , i);
720724 }
721725
726+ Goals waitees;
727+
722728 /* Check each path (slow!). */
723729 for (auto & i : outputClosure) {
724730 if (worker.pathContentsGood (i)) continue ;
@@ -727,27 +733,25 @@ Goal::Co DerivationGoal::repairClosure()
727733 worker.store .printStorePath (i), worker.store .printStorePath (drvPath));
728734 auto drvPath2 = outputsToDrv.find (i);
729735 if (drvPath2 == outputsToDrv.end ())
730- addWaitee (upcast_goal (worker.makePathSubstitutionGoal (i, Repair)));
736+ waitees. insert (upcast_goal (worker.makePathSubstitutionGoal (i, Repair)));
731737 else
732- addWaitee (worker.makeGoal (
738+ waitees. insert (worker.makeGoal (
733739 DerivedPath::Built {
734740 .drvPath = makeConstantStorePathRef (drvPath2->second ),
735741 .outputs = OutputsSpec::All { },
736742 },
737743 bmRepair));
738744 }
739745
740- if (waitees.empty ()) {
741- co_return done (BuildResult::AlreadyValid, assertPathValidity ());
742- } else {
743- co_await Suspend{};
746+ co_await await (std::move (waitees));
744747
748+ if (!waitees.empty ()) {
745749 trace (" closure repaired" );
746750 if (nrFailed > 0 )
747751 throw Error (" some paths in the output closure of derivation '%s' could not be repaired" ,
748752 worker.store .printStorePath (drvPath));
749- co_return done (BuildResult::AlreadyValid, assertPathValidity ());
750753 }
754+ co_return done (BuildResult::AlreadyValid, assertPathValidity ());
751755}
752756
753757
0 commit comments