@@ -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,12 @@ 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
+ return Compilation::Result{
1701
+ ResultCode, std::move (*this ).takeFineGrainedDepGraph (forRanges)};
1700
1702
}
1701
1703
1702
1704
bool hadAnyAbnormalExit () {
@@ -1756,6 +1758,12 @@ namespace driver {
1756
1758
getFineGrainedDepGraph (const bool forRanges) const {
1757
1759
return forRanges ? FineGrainedDepGraphForRanges : FineGrainedDepGraph;
1758
1760
}
1761
+
1762
+ fine_grained_dependencies::ModuleDepGraph &&
1763
+ takeFineGrainedDepGraph (const bool forRanges) && {
1764
+ return forRanges ? std::move (FineGrainedDepGraphForRanges)
1765
+ : std::move (FineGrainedDepGraph);
1766
+ }
1759
1767
};
1760
1768
} // namespace driver
1761
1769
} // namespace swift
@@ -1936,8 +1944,9 @@ static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
1936
1944
return ok;
1937
1945
}
1938
1946
1939
- int Compilation::performJobsImpl (bool &abnormalExit,
1940
- std::unique_ptr<TaskQueue> &&TQ) {
1947
+ Compilation::Result
1948
+ Compilation::performJobsImpl (bool &abnormalExit,
1949
+ std::unique_ptr<TaskQueue> &&TQ) {
1941
1950
PerformJobsState State (*this , std::move (TQ));
1942
1951
1943
1952
State.runJobs ();
@@ -1946,36 +1955,41 @@ int Compilation::performJobsImpl(bool &abnormalExit,
1946
1955
InputInfoMap InputInfo;
1947
1956
State.populateInputInfoMap (InputInfo);
1948
1957
checkForOutOfDateInputs (Diags, InputInfo);
1958
+
1959
+ abnormalExit = State.hadAnyAbnormalExit ();
1960
+ auto result = std::move (State).takeResult ();
1949
1961
writeCompilationRecord (CompilationRecordPath, ArgsHash, BuildStartTime,
1950
1962
InputInfo);
1963
+ return result;
1964
+ } else {
1965
+ abnormalExit = State.hadAnyAbnormalExit ();
1966
+ return std::move (State).takeResult ();
1951
1967
}
1952
- abnormalExit = State.hadAnyAbnormalExit ();
1953
- return State.getResult ();
1954
1968
}
1955
1969
1956
- int Compilation::performSingleCommand (const Job *Cmd) {
1970
+ Compilation::Result Compilation::performSingleCommand (const Job *Cmd) {
1957
1971
assert (Cmd->getInputs ().empty () &&
1958
1972
" This can only be used to run a single command with no inputs" );
1959
1973
1960
1974
switch (Cmd->getCondition ()) {
1961
1975
case Job::Condition::CheckDependencies:
1962
- return 0 ;
1976
+ return Compilation::Result{ 0 , fine_grained_dependencies::ModuleDepGraph ()} ;
1963
1977
case Job::Condition::RunWithoutCascading:
1964
1978
case Job::Condition::Always:
1965
1979
case Job::Condition::NewlyAdded:
1966
1980
break ;
1967
1981
}
1968
1982
1969
1983
if (!writeFilelistIfNecessary (Cmd, *TranslatedArgs.get (), Diags))
1970
- return 1 ;
1984
+ return Compilation::Result{ 1 , fine_grained_dependencies::ModuleDepGraph ()} ;
1971
1985
1972
1986
switch (Level) {
1973
1987
case OutputLevel::Normal:
1974
1988
case OutputLevel::Parseable:
1975
1989
break ;
1976
1990
case OutputLevel::PrintJobs:
1977
1991
Cmd->printCommandLineAndEnvironment (llvm::outs ());
1978
- return 0 ;
1992
+ return Compilation::Result{ 0 , fine_grained_dependencies::ModuleDepGraph ()} ;
1979
1993
case OutputLevel::Verbose:
1980
1994
Cmd->printCommandLine (llvm::errs ());
1981
1995
break ;
@@ -1999,11 +2013,14 @@ int Compilation::performSingleCommand(const Job *Cmd) {
1999
2013
" expected environment variable to be set successfully" );
2000
2014
// Bail out early in release builds.
2001
2015
if (envResult != 0 ) {
2002
- return envResult;
2016
+ return Compilation::Result{envResult,
2017
+ fine_grained_dependencies::ModuleDepGraph ()};
2003
2018
}
2004
2019
}
2005
2020
2006
- return ExecuteInPlace (ExecPath, argv);
2021
+ const auto returnCode = ExecuteInPlace (ExecPath, argv);
2022
+ return Compilation::Result{returnCode,
2023
+ fine_grained_dependencies::ModuleDepGraph ()};
2007
2024
}
2008
2025
2009
2026
static bool writeAllSourcesFile (DiagnosticEngine &diags, StringRef path,
@@ -2026,10 +2043,11 @@ static bool writeAllSourcesFile(DiagnosticEngine &diags, StringRef path,
2026
2043
return true ;
2027
2044
}
2028
2045
2029
- int Compilation::performJobs (std::unique_ptr<TaskQueue> &&TQ) {
2046
+ Compilation::Result Compilation::performJobs (std::unique_ptr<TaskQueue> &&TQ) {
2030
2047
if (AllSourceFilesPath)
2031
2048
if (!writeAllSourcesFile (Diags, AllSourceFilesPath, getInputFiles ()))
2032
- return EXIT_FAILURE;
2049
+ return Compilation::Result{EXIT_FAILURE,
2050
+ fine_grained_dependencies::ModuleDepGraph ()};
2033
2051
2034
2052
// If we don't have to do any cleanup work, just exec the subprocess.
2035
2053
if (Level < OutputLevel::Parseable &&
@@ -2045,7 +2063,7 @@ int Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
2045
2063
}
2046
2064
2047
2065
bool abnormalExit;
2048
- int result = performJobsImpl (abnormalExit, std::move (TQ));
2066
+ auto result = performJobsImpl (abnormalExit, std::move (TQ));
2049
2067
2050
2068
if (IncrementalComparator)
2051
2069
IncrementalComparator->outputComparison ();
@@ -2057,7 +2075,7 @@ int Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
2057
2075
}
2058
2076
}
2059
2077
if (Stats)
2060
- Stats->noteCurrentProcessExitStatus (result);
2078
+ Stats->noteCurrentProcessExitStatus (result. exitCode );
2061
2079
return result;
2062
2080
}
2063
2081
0 commit comments