Skip to content

Commit d4e76d0

Browse files
committed
[NFC] Use Result::code to Simplify Some Callsites
1 parent d402292 commit d4e76d0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

include/swift/Driver/Compilation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class Compilation {
9090

9191
Result &operator=(const Result &) = delete;
9292
Result &operator=(Result &&) = default;
93+
94+
static Result code(int code) {
95+
return Compilation::Result{false, code,
96+
fine_grained_dependencies::ModuleDepGraph()};
97+
}
9398
};
9499

95100
class IncrementalSchemeComparator {

lib/Driver/Compilation.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,8 +1697,10 @@ namespace driver {
16971697
if (ResultCode == 0)
16981698
ResultCode = Comp.getDiags().hadAnyError();
16991699
const bool forRanges = Comp.getEnableSourceRangeDependencies();
1700-
return Compilation::Result{
1701-
ResultCode, std::move(*this).takeFineGrainedDepGraph(forRanges)};
1700+
const bool hadAbnormalExit = hadAnyAbnormalExit();
1701+
const auto resultCode = ResultCode;
1702+
auto &&graph = std::move(*this).takeFineGrainedDepGraph(forRanges);
1703+
return Compilation::Result{hadAbnormalExit, resultCode, std::move(graph)};
17021704
}
17031705

17041706
bool hadAnyAbnormalExit() {
@@ -1970,23 +1972,23 @@ Compilation::Result Compilation::performSingleCommand(const Job *Cmd) {
19701972

19711973
switch (Cmd->getCondition()) {
19721974
case Job::Condition::CheckDependencies:
1973-
return Compilation::Result{0, fine_grained_dependencies::ModuleDepGraph()};
1975+
return Compilation::Result::code(0);
19741976
case Job::Condition::RunWithoutCascading:
19751977
case Job::Condition::Always:
19761978
case Job::Condition::NewlyAdded:
19771979
break;
19781980
}
19791981

19801982
if (!writeFilelistIfNecessary(Cmd, *TranslatedArgs.get(), Diags))
1981-
return Compilation::Result{1, fine_grained_dependencies::ModuleDepGraph()};
1983+
return Compilation::Result::code(1);
19821984

19831985
switch (Level) {
19841986
case OutputLevel::Normal:
19851987
case OutputLevel::Parseable:
19861988
break;
19871989
case OutputLevel::PrintJobs:
19881990
Cmd->printCommandLineAndEnvironment(llvm::outs());
1989-
return Compilation::Result{0, fine_grained_dependencies::ModuleDepGraph()};
1991+
return Compilation::Result::code(0);
19901992
case OutputLevel::Verbose:
19911993
Cmd->printCommandLine(llvm::errs());
19921994
break;
@@ -2010,14 +2012,12 @@ Compilation::Result Compilation::performSingleCommand(const Job *Cmd) {
20102012
"expected environment variable to be set successfully");
20112013
// Bail out early in release builds.
20122014
if (envResult != 0) {
2013-
return Compilation::Result{envResult,
2014-
fine_grained_dependencies::ModuleDepGraph()};
2015+
return Compilation::Result::code(envResult);
20152016
}
20162017
}
20172018

20182019
const auto returnCode = ExecuteInPlace(ExecPath, argv);
2019-
return Compilation::Result{returnCode,
2020-
fine_grained_dependencies::ModuleDepGraph()};
2020+
return Compilation::Result::code(returnCode);
20212021
}
20222022

20232023
static bool writeAllSourcesFile(DiagnosticEngine &diags, StringRef path,
@@ -2043,8 +2043,7 @@ static bool writeAllSourcesFile(DiagnosticEngine &diags, StringRef path,
20432043
Compilation::Result Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
20442044
if (AllSourceFilesPath)
20452045
if (!writeAllSourcesFile(Diags, AllSourceFilesPath, getInputFiles()))
2046-
return Compilation::Result{EXIT_FAILURE,
2047-
fine_grained_dependencies::ModuleDepGraph()};
2046+
return Compilation::Result::code(EXIT_FAILURE);
20482047

20492048
// If we don't have to do any cleanup work, just exec the subprocess.
20502049
if (Level < OutputLevel::Parseable &&

0 commit comments

Comments
 (0)