Skip to content

Commit c1085ce

Browse files
committed
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.
1 parent 0d3750e commit c1085ce

7 files changed

Lines changed: 9 additions & 24 deletions

File tree

src/libstore/build/derivation-goal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace nix {
2525

2626
DerivationGoal::DerivationGoal(const StorePath & drvPath,
2727
const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode)
28-
: Goal(worker)
28+
: Goal(worker, init())
2929
, useDerivation(true)
3030
, drvPath(drvPath)
3131
, wantedOutputs(wantedOutputs)
@@ -43,7 +43,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath,
4343

4444
DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv,
4545
const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode)
46-
: Goal(worker)
46+
: Goal(worker, init())
4747
, useDerivation(false)
4848
, drvPath(drvPath)
4949
, wantedOutputs(wantedOutputs)

src/libstore/build/drv-output-substitution-goal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DrvOutputSubstitutionGoal::DrvOutputSubstitutionGoal(
1212
Worker & worker,
1313
RepairFlag repair,
1414
std::optional<ContentAddress> ca)
15-
: Goal(worker)
15+
: Goal(worker, init())
1616
, id(id)
1717
{
1818
name = fmt("substitution of '%s'", id.to_string());

src/libstore/build/substitution-goal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace nix {
1010

1111
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
12-
: Goal(worker)
12+
: Goal(worker, init())
1313
, storePath(storePath)
1414
, repair(repair)
1515
, ca(ca)

src/libstore/include/nix/store/build/derivation-goal.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct DerivationGoal : public Goal
166166
/**
167167
* The states.
168168
*/
169-
Co init() override;
169+
Co init();
170170
Co haveDerivation();
171171
Co gaveUpOnSubstitution();
172172
Co tryToBuild();

src/libstore/include/nix/store/build/drv-output-substitution-goal.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public:
3333
typedef void (DrvOutputSubstitutionGoal::*GoalState)();
3434
GoalState state;
3535

36-
Co init() override;
36+
Co init();
3737
Co realisationFetched(Goals waitees, std::shared_ptr<const Realisation> outputInfo, nix::ref<nix::Store> sub);
3838

3939
void timedOut(Error && ex) override { unreachable(); };

src/libstore/include/nix/store/build/goal.hh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,6 @@ protected:
338338
*/
339339
std::optional<Co> top_co;
340340

341-
/**
342-
* The entry point for the goal
343-
*/
344-
virtual Co init() = 0;
345-
346-
/**
347-
* Wrapper around @ref init since virtual functions
348-
* can't be used in constructors.
349-
*/
350-
inline Co init_wrapper();
351-
352341
/**
353342
* Signals that the goal is done.
354343
* `co_return` the result. If you're not inside a coroutine, you can ignore
@@ -376,8 +365,8 @@ public:
376365
*/
377366
std::optional<Error> ex;
378367

379-
Goal(Worker & worker)
380-
: worker(worker), top_co(init_wrapper())
368+
Goal(Worker & worker, Co init)
369+
: worker(worker), top_co(std::move(init))
381370
{
382371
// top_co shouldn't have a goal already, should be nullptr.
383372
assert(!top_co->handle.promise().goal);
@@ -440,7 +429,3 @@ template<typename... ArgTypes>
440429
struct std::coroutine_traits<nix::Goal::Co, ArgTypes...> {
441430
using promise_type = nix::Goal::promise_type;
442431
};
443-
444-
nix::Goal::Co nix::Goal::init_wrapper() {
445-
co_return init();
446-
}

src/libstore/include/nix/store/build/substitution-goal.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public:
6464
/**
6565
* The states.
6666
*/
67-
Co init() override;
67+
Co init();
6868
Co gotInfo();
6969
Co tryToRun(StorePath subPath, nix::ref<Store> sub, std::shared_ptr<const ValidPathInfo> info, bool & substituterFailed);
7070
Co finished();

0 commit comments

Comments
 (0)