From 4b109ec1a8fc4550150f56f0f46f2f41d844bda8 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 9 Jul 2024 23:14:46 +0200 Subject: [PATCH] libstore: remove upcast_goal upcast_goal was only ever needed to break circular includes, but the same solution that gave us upcast_goal also lets us fully remove it: just upcast goals without a wrapper function, but only in .cc files. Change-Id: I9c71654b2535121459ba7dcfd6c5da5606904032 --- src/libstore/build/derivation-goal.cc | 20 ++++++++++---------- src/libstore/build/worker.cc | 11 ----------- src/libstore/build/worker.hh | 15 --------------- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 7c18f8b60..51597428d 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -12,6 +12,8 @@ #include "topo-sort.hh" #include "local-store.hh" // TODO remove, along with remaining downcasts #include "logging-json.hh" +#include "substitution-goal.hh" +#include "drv-output-substitution-goal.hh" #include #include @@ -175,7 +177,7 @@ void DerivationGoal::getDerivation() return; } - addWaitee(upcast_goal(worker.makePathSubstitutionGoal(drvPath))); + addWaitee(worker.makePathSubstitutionGoal(drvPath)); state = &DerivationGoal::loadDerivation; } @@ -276,19 +278,17 @@ void DerivationGoal::haveDerivation() if (!status.wanted) continue; if (!status.known) addWaitee( - upcast_goal( - worker.makeDrvOutputSubstitutionGoal( - DrvOutput{status.outputHash, outputName}, - buildMode == bmRepair ? Repair : NoRepair - ) + worker.makeDrvOutputSubstitutionGoal( + DrvOutput{status.outputHash, outputName}, + buildMode == bmRepair ? Repair : NoRepair ) ); else { auto * cap = getDerivationCA(*drv); - addWaitee(upcast_goal(worker.makePathSubstitutionGoal( + addWaitee(worker.makePathSubstitutionGoal( status.known->path, buildMode == bmRepair ? Repair : NoRepair, - cap ? std::optional { *cap } : std::nullopt))); + cap ? std::optional { *cap } : std::nullopt)); } } @@ -426,7 +426,7 @@ void DerivationGoal::gaveUpOnSubstitution() if (!settings.useSubstitutes) throw Error("dependency '%s' of '%s' does not exist, and substitution is disabled", worker.store.printStorePath(i), worker.store.printStorePath(drvPath)); - addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i))); + addWaitee(worker.makePathSubstitutionGoal(i)); } if (waitees.empty()) /* to prevent hang (no wake-up event) */ @@ -479,7 +479,7 @@ void DerivationGoal::repairClosure() worker.store.printStorePath(i), worker.store.printStorePath(drvPath)); auto drvPath2 = outputsToDrv.find(i); if (drvPath2 == outputsToDrv.end()) - addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i, Repair))); + addWaitee(worker.makePathSubstitutionGoal(i, Repair)); else addWaitee(worker.makeGoal( DerivedPath::Built { diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index a7a298c34..e3fec292a 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -537,15 +537,4 @@ void Worker::markContentsGood(const StorePath & path) pathContentsGoodCache.insert_or_assign(path, true); } - -GoalPtr upcast_goal(std::shared_ptr subGoal) -{ - return subGoal; -} - -GoalPtr upcast_goal(std::shared_ptr subGoal) -{ - return subGoal; -} - } diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh index ba4cd88d7..e1d8e5031 100644 --- a/src/libstore/build/worker.hh +++ b/src/libstore/build/worker.hh @@ -17,21 +17,6 @@ struct DerivationGoal; struct PathSubstitutionGoal; class DrvOutputSubstitutionGoal; -/** - * Workaround for not being able to declare a something like - * - * ```c++ - * class PathSubstitutionGoal : public Goal; - * ``` - * even when Goal is a complete type. - * - * This is still a static cast. The purpose of exporting it is to define it in - * a place where `PathSubstitutionGoal` is concrete, and use it in a place where it - * is opaque. - */ -GoalPtr upcast_goal(std::shared_ptr subGoal); -GoalPtr upcast_goal(std::shared_ptr subGoal); - typedef std::chrono::time_point steady_time_point; /**