Skip to content

[NFC] Add IncrementalJobAction #34224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions include/swift/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class JobAction : public Action {
}
};

class CompileJobAction : public JobAction {
class IncrementalJobAction : public JobAction {
public:
struct InputInfo {
enum Status {
Expand All @@ -136,6 +136,8 @@ class CompileJobAction : public JobAction {
NeedsNonCascadingBuild,
NewlyAdded
};

public:
Status status = UpToDate;
llvm::sys::TimePoint<> previousModTime;

Expand All @@ -153,18 +155,32 @@ class CompileJobAction : public JobAction {
InputInfo inputInfo;

public:
CompileJobAction(file_types::ID OutputType)
: JobAction(Action::Kind::CompileJob, None, OutputType),
inputInfo() {}

CompileJobAction(Action *Input, file_types::ID OutputType, InputInfo info)
: JobAction(Action::Kind::CompileJob, Input, OutputType),
inputInfo(info) {}
IncrementalJobAction(Kind Kind, ArrayRef<const Action *> Inputs,
file_types::ID Type, InputInfo info)
: JobAction(Kind, Inputs, Type), inputInfo(info) {}

public:
InputInfo getInputInfo() const {
return inputInfo;
}

public:
static bool classof(const Action *A) {
return A->getKind() == Action::Kind::CompileJob;
}
};

class CompileJobAction : public IncrementalJobAction {
private:
virtual void anchor() override;

public:
CompileJobAction(file_types::ID OutputType)
: IncrementalJobAction(Action::Kind::CompileJob, None, OutputType, {}) {}
CompileJobAction(Action *Input, file_types::ID OutputType, InputInfo info)
: IncrementalJobAction(Action::Kind::CompileJob, Input, OutputType,
info) {}

static bool classof(const Action *A) {
return A->getKind() == Action::Kind::CompileJob;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void InputAction::anchor() {}

void JobAction::anchor() {}

void IncrementalJobAction::anchor() {}

void CompileJobAction::anchor() {}

void InterpretJobAction::anchor() {}
Expand Down
18 changes: 10 additions & 8 deletions lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ namespace driver {
computeFirstRoundCompileJobsForIncrementalCompilation();

for (const Job *Cmd : Comp.getJobs()) {
if (Cmd->getFirstSwiftPrimaryInput().empty() ||
if (!isa<IncrementalJobAction>(Cmd->getSource()) ||
compileJobsToSchedule.count(Cmd)) {
scheduleCommandIfNecessaryAndPossible(Cmd);
noteBuilding(Cmd, /*willBeBuilding*/ true, /*isTentative=*/false,
Expand Down Expand Up @@ -899,20 +899,22 @@ namespace driver {
CommandSet
computeDependenciesAndGetNeededCompileJobs(const bool forRanges) {
auto getEveryCompileJob = [&] {
CommandSet everyCompileJob;
CommandSet everyIncrementalJob;
for (const Job *Cmd : Comp.getJobs()) {
if (!Cmd->getFirstSwiftPrimaryInput().empty())
everyCompileJob.insert(Cmd);
if (isa<IncrementalJobAction>(Cmd->getSource()))
everyIncrementalJob.insert(Cmd);
}
return everyCompileJob;
return everyIncrementalJob;
};

CommandSet jobsToSchedule;
CommandSet initialCascadingCommands;
for (const Job *cmd : Comp.getJobs()) {
const StringRef primary = cmd->getFirstSwiftPrimaryInput();
if (primary.empty())
continue; // not Compile
// Skip jobs that have no associated incremental info.
if (!isa<IncrementalJobAction>(cmd->getSource())) {
continue;
}

const Optional<std::pair<bool, bool>> shouldSchedAndIsCascading =
computeShouldInitiallyScheduleJobAndDependendents(cmd, forRanges);
if (!shouldSchedAndIsCascading)
Expand Down