@@ -244,7 +244,7 @@ namespace driver {
244
244
std::unique_ptr<TaskQueue> TQ;
245
245
246
246
// / Cumulative result of PerformJobs(), accumulated from subprocesses.
247
- int Result = EXIT_SUCCESS;
247
+ int ResultCode = EXIT_SUCCESS;
248
248
249
249
// / True if any Job crashed.
250
250
bool AnyAbnormalExit = false ;
@@ -719,8 +719,8 @@ namespace driver {
719
719
// Store this task's ReturnCode as our Result if we haven't stored
720
720
// anything yet.
721
721
722
- if (Result == EXIT_SUCCESS)
723
- Result = ReturnCode;
722
+ if (ResultCode == EXIT_SUCCESS)
723
+ ResultCode = ReturnCode;
724
724
725
725
if (!isa<CompileJobAction>(FinishedCmd->getSource ()) ||
726
726
ReturnCode != EXIT_FAILURE) {
@@ -825,7 +825,7 @@ namespace driver {
825
825
}
826
826
827
827
// Since the task signalled, unconditionally set result to -2.
828
- Result = -2 ;
828
+ ResultCode = -2 ;
829
829
AnyAbnormalExit = true ;
830
830
831
831
return TaskFinishedResponse::StopExecution;
@@ -1536,7 +1536,7 @@ namespace driver {
1536
1536
_3, _4, _5, _6),
1537
1537
std::bind (&PerformJobsState::taskSignalled, this , _1,
1538
1538
_2, _3, _4, _5, _6, _7))) {
1539
- if (Result == EXIT_SUCCESS) {
1539
+ if (ResultCode == EXIT_SUCCESS) {
1540
1540
// FIXME: Error from task queue while Result == EXIT_SUCCESS most
1541
1541
// likely means some fork/exec or posix_spawn failed; TaskQueue saw
1542
1542
// "an error" at some stage before even calling us with a process
@@ -1546,21 +1546,21 @@ namespace driver {
1546
1546
Comp.getDiags ().diagnose (SourceLoc (),
1547
1547
diag::error_unable_to_execute_command,
1548
1548
" <unknown>" );
1549
- Result = -2 ;
1549
+ ResultCode = -2 ;
1550
1550
AnyAbnormalExit = true ;
1551
1551
return ;
1552
1552
}
1553
1553
}
1554
1554
1555
1555
// Returning without error from TaskQueue::execute should mean either an
1556
1556
// empty TaskQueue or a failed subprocess.
1557
- assert (!(Result == 0 && TQ->hasRemainingTasks ()));
1557
+ assert (!(ResultCode == 0 && TQ->hasRemainingTasks ()));
1558
1558
1559
1559
// Task-exit callbacks from TaskQueue::execute may have unblocked jobs,
1560
1560
// which means there might be PendingExecution jobs to enqueue here. If
1561
1561
// there are, we need to continue trying to make progress on the
1562
1562
// TaskQueue before we start marking deferred jobs as skipped, below.
1563
- if (!PendingExecution.empty () && Result == 0 ) {
1563
+ if (!PendingExecution.empty () && ResultCode == 0 ) {
1564
1564
formBatchJobsAndAddPendingJobsToTaskQueue ();
1565
1565
continue ;
1566
1566
}
@@ -1585,11 +1585,11 @@ namespace driver {
1585
1585
1586
1586
// If we added jobs to the TaskQueue, and we are not in an error state,
1587
1587
// we want to give the TaskQueue another run.
1588
- } while (Result == 0 && TQ->hasRemainingTasks ());
1588
+ } while (ResultCode == 0 && TQ->hasRemainingTasks ());
1589
1589
}
1590
1590
1591
1591
void checkUnfinishedJobs () {
1592
- if (Result == 0 ) {
1592
+ if (ResultCode == 0 ) {
1593
1593
assert (BlockingCommands.empty () &&
1594
1594
" some blocking commands never finished properly" );
1595
1595
} else {
@@ -1693,10 +1693,14 @@ namespace driver {
1693
1693
});
1694
1694
}
1695
1695
1696
- int getResult () {
1697
- if (Result == 0 )
1698
- Result = Comp.getDiags ().hadAnyError ();
1699
- return Result;
1696
+ Compilation::Result takeResult () && {
1697
+ if (ResultCode == 0 )
1698
+ ResultCode = Comp.getDiags ().hadAnyError ();
1699
+ const bool forRanges = Comp.getEnableSourceRangeDependencies ();
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)};
1700
1704
}
1701
1705
1702
1706
bool hadAnyAbnormalExit () {
@@ -1756,6 +1760,12 @@ namespace driver {
1756
1760
getFineGrainedDepGraph (const bool forRanges) const {
1757
1761
return forRanges ? FineGrainedDepGraphForRanges : FineGrainedDepGraph;
1758
1762
}
1763
+
1764
+ fine_grained_dependencies::ModuleDepGraph &&
1765
+ takeFineGrainedDepGraph (const bool forRanges) && {
1766
+ return forRanges ? std::move (FineGrainedDepGraphForRanges)
1767
+ : std::move (FineGrainedDepGraph);
1768
+ }
1759
1769
};
1760
1770
} // namespace driver
1761
1771
} // namespace swift
@@ -1936,8 +1946,8 @@ static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
1936
1946
return ok;
1937
1947
}
1938
1948
1939
- int Compilation::performJobsImpl ( bool &abnormalExit,
1940
- std::unique_ptr<TaskQueue> &&TQ) {
1949
+ Compilation::Result
1950
+ Compilation::performJobsImpl ( std::unique_ptr<TaskQueue> &&TQ) {
1941
1951
PerformJobsState State (*this , std::move (TQ));
1942
1952
1943
1953
State.runJobs ();
@@ -1946,36 +1956,39 @@ int Compilation::performJobsImpl(bool &abnormalExit,
1946
1956
InputInfoMap InputInfo;
1947
1957
State.populateInputInfoMap (InputInfo);
1948
1958
checkForOutOfDateInputs (Diags, InputInfo);
1959
+
1960
+ auto result = std::move (State).takeResult ();
1949
1961
writeCompilationRecord (CompilationRecordPath, ArgsHash, BuildStartTime,
1950
1962
InputInfo);
1963
+ return result;
1964
+ } else {
1965
+ return std::move (State).takeResult ();
1951
1966
}
1952
- abnormalExit = State.hadAnyAbnormalExit ();
1953
- return State.getResult ();
1954
1967
}
1955
1968
1956
- int Compilation::performSingleCommand (const Job *Cmd) {
1969
+ Compilation::Result Compilation::performSingleCommand (const Job *Cmd) {
1957
1970
assert (Cmd->getInputs ().empty () &&
1958
1971
" This can only be used to run a single command with no inputs" );
1959
1972
1960
1973
switch (Cmd->getCondition ()) {
1961
1974
case Job::Condition::CheckDependencies:
1962
- return 0 ;
1975
+ return Compilation::Result::code ( 0 ) ;
1963
1976
case Job::Condition::RunWithoutCascading:
1964
1977
case Job::Condition::Always:
1965
1978
case Job::Condition::NewlyAdded:
1966
1979
break ;
1967
1980
}
1968
1981
1969
1982
if (!writeFilelistIfNecessary (Cmd, *TranslatedArgs.get (), Diags))
1970
- return 1 ;
1983
+ return Compilation::Result::code ( 1 ) ;
1971
1984
1972
1985
switch (Level) {
1973
1986
case OutputLevel::Normal:
1974
1987
case OutputLevel::Parseable:
1975
1988
break ;
1976
1989
case OutputLevel::PrintJobs:
1977
1990
Cmd->printCommandLineAndEnvironment (llvm::outs ());
1978
- return 0 ;
1991
+ return Compilation::Result::code ( 0 ) ;
1979
1992
case OutputLevel::Verbose:
1980
1993
Cmd->printCommandLine (llvm::errs ());
1981
1994
break ;
@@ -1999,11 +2012,12 @@ int Compilation::performSingleCommand(const Job *Cmd) {
1999
2012
" expected environment variable to be set successfully" );
2000
2013
// Bail out early in release builds.
2001
2014
if (envResult != 0 ) {
2002
- return envResult;
2015
+ return Compilation::Result::code ( envResult) ;
2003
2016
}
2004
2017
}
2005
2018
2006
- return ExecuteInPlace (ExecPath, argv);
2019
+ const auto returnCode = ExecuteInPlace (ExecPath, argv);
2020
+ return Compilation::Result::code (returnCode);
2007
2021
}
2008
2022
2009
2023
static bool writeAllSourcesFile (DiagnosticEngine &diags, StringRef path,
@@ -2026,10 +2040,10 @@ static bool writeAllSourcesFile(DiagnosticEngine &diags, StringRef path,
2026
2040
return true ;
2027
2041
}
2028
2042
2029
- int Compilation::performJobs (std::unique_ptr<TaskQueue> &&TQ) {
2043
+ Compilation::Result Compilation::performJobs (std::unique_ptr<TaskQueue> &&TQ) {
2030
2044
if (AllSourceFilesPath)
2031
2045
if (!writeAllSourcesFile (Diags, AllSourceFilesPath, getInputFiles ()))
2032
- return EXIT_FAILURE;
2046
+ return Compilation::Result::code ( EXIT_FAILURE) ;
2033
2047
2034
2048
// If we don't have to do any cleanup work, just exec the subprocess.
2035
2049
if (Level < OutputLevel::Parseable &&
@@ -2044,20 +2058,19 @@ int Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
2044
2058
Diags.diagnose (SourceLoc (), diag::warning_parallel_execution_not_supported);
2045
2059
}
2046
2060
2047
- bool abnormalExit;
2048
- int result = performJobsImpl (abnormalExit, std::move (TQ));
2061
+ auto result = performJobsImpl (std::move (TQ));
2049
2062
2050
2063
if (IncrementalComparator)
2051
2064
IncrementalComparator->outputComparison ();
2052
2065
2053
2066
if (!SaveTemps) {
2054
2067
for (const auto &pathPair : TempFilePaths) {
2055
- if (!abnormalExit || pathPair.getValue () == PreserveOnSignal::No)
2068
+ if (!result. hadAbnormalExit || pathPair.getValue () == PreserveOnSignal::No)
2056
2069
(void )llvm::sys::fs::remove (pathPair.getKey ());
2057
2070
}
2058
2071
}
2059
2072
if (Stats)
2060
- Stats->noteCurrentProcessExitStatus (result);
2073
+ Stats->noteCurrentProcessExitStatus (result. exitCode );
2061
2074
return result;
2062
2075
}
2063
2076
0 commit comments