mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Get rid of virtual Goal::init()
Now, each class provides the initial coroutine by value. This avoids some sketchy virtual function stuff, and will also be further put to good use in the next commit.
This commit is contained in:
parent
0d3750e902
commit
c1085ce849
7 changed files with 9 additions and 24 deletions
|
@ -25,7 +25,7 @@ namespace nix {
|
||||||
|
|
||||||
DerivationGoal::DerivationGoal(const StorePath & drvPath,
|
DerivationGoal::DerivationGoal(const StorePath & drvPath,
|
||||||
const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode)
|
const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode)
|
||||||
: Goal(worker)
|
: Goal(worker, init())
|
||||||
, useDerivation(true)
|
, useDerivation(true)
|
||||||
, drvPath(drvPath)
|
, drvPath(drvPath)
|
||||||
, wantedOutputs(wantedOutputs)
|
, wantedOutputs(wantedOutputs)
|
||||||
|
@ -43,7 +43,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath,
|
||||||
|
|
||||||
DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv,
|
DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv,
|
||||||
const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode)
|
const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode)
|
||||||
: Goal(worker)
|
: Goal(worker, init())
|
||||||
, useDerivation(false)
|
, useDerivation(false)
|
||||||
, drvPath(drvPath)
|
, drvPath(drvPath)
|
||||||
, wantedOutputs(wantedOutputs)
|
, wantedOutputs(wantedOutputs)
|
||||||
|
|
|
@ -12,7 +12,7 @@ DrvOutputSubstitutionGoal::DrvOutputSubstitutionGoal(
|
||||||
Worker & worker,
|
Worker & worker,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
std::optional<ContentAddress> ca)
|
std::optional<ContentAddress> ca)
|
||||||
: Goal(worker)
|
: Goal(worker, init())
|
||||||
, id(id)
|
, id(id)
|
||||||
{
|
{
|
||||||
name = fmt("substitution of '%s'", id.to_string());
|
name = fmt("substitution of '%s'", id.to_string());
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
|
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
|
||||||
: Goal(worker)
|
: Goal(worker, init())
|
||||||
, storePath(storePath)
|
, storePath(storePath)
|
||||||
, repair(repair)
|
, repair(repair)
|
||||||
, ca(ca)
|
, ca(ca)
|
||||||
|
|
|
@ -166,7 +166,7 @@ struct DerivationGoal : public Goal
|
||||||
/**
|
/**
|
||||||
* The states.
|
* The states.
|
||||||
*/
|
*/
|
||||||
Co init() override;
|
Co init();
|
||||||
Co haveDerivation();
|
Co haveDerivation();
|
||||||
Co gaveUpOnSubstitution();
|
Co gaveUpOnSubstitution();
|
||||||
Co tryToBuild();
|
Co tryToBuild();
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
typedef void (DrvOutputSubstitutionGoal::*GoalState)();
|
typedef void (DrvOutputSubstitutionGoal::*GoalState)();
|
||||||
GoalState state;
|
GoalState state;
|
||||||
|
|
||||||
Co init() override;
|
Co init();
|
||||||
Co realisationFetched(Goals waitees, std::shared_ptr<const Realisation> outputInfo, nix::ref<nix::Store> sub);
|
Co realisationFetched(Goals waitees, std::shared_ptr<const Realisation> outputInfo, nix::ref<nix::Store> sub);
|
||||||
|
|
||||||
void timedOut(Error && ex) override { unreachable(); };
|
void timedOut(Error && ex) override { unreachable(); };
|
||||||
|
|
|
@ -338,17 +338,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
std::optional<Co> top_co;
|
std::optional<Co> top_co;
|
||||||
|
|
||||||
/**
|
|
||||||
* The entry point for the goal
|
|
||||||
*/
|
|
||||||
virtual Co init() = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper around @ref init since virtual functions
|
|
||||||
* can't be used in constructors.
|
|
||||||
*/
|
|
||||||
inline Co init_wrapper();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signals that the goal is done.
|
* Signals that the goal is done.
|
||||||
* `co_return` the result. If you're not inside a coroutine, you can ignore
|
* `co_return` the result. If you're not inside a coroutine, you can ignore
|
||||||
|
@ -376,8 +365,8 @@ public:
|
||||||
*/
|
*/
|
||||||
std::optional<Error> ex;
|
std::optional<Error> ex;
|
||||||
|
|
||||||
Goal(Worker & worker)
|
Goal(Worker & worker, Co init)
|
||||||
: worker(worker), top_co(init_wrapper())
|
: worker(worker), top_co(std::move(init))
|
||||||
{
|
{
|
||||||
// top_co shouldn't have a goal already, should be nullptr.
|
// top_co shouldn't have a goal already, should be nullptr.
|
||||||
assert(!top_co->handle.promise().goal);
|
assert(!top_co->handle.promise().goal);
|
||||||
|
@ -440,7 +429,3 @@ template<typename... ArgTypes>
|
||||||
struct std::coroutine_traits<nix::Goal::Co, ArgTypes...> {
|
struct std::coroutine_traits<nix::Goal::Co, ArgTypes...> {
|
||||||
using promise_type = nix::Goal::promise_type;
|
using promise_type = nix::Goal::promise_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
nix::Goal::Co nix::Goal::init_wrapper() {
|
|
||||||
co_return init();
|
|
||||||
}
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* The states.
|
* The states.
|
||||||
*/
|
*/
|
||||||
Co init() override;
|
Co init();
|
||||||
Co gotInfo();
|
Co gotInfo();
|
||||||
Co tryToRun(StorePath subPath, nix::ref<Store> sub, std::shared_ptr<const ValidPathInfo> info, bool & substituterFailed);
|
Co tryToRun(StorePath subPath, nix::ref<Store> sub, std::shared_ptr<const ValidPathInfo> info, bool & substituterFailed);
|
||||||
Co finished();
|
Co finished();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue