Skip to content

Commit f9fd6a3

Browse files
committed
[Driver] -enable-batch-mode implies -continue-building-after-errors
The logic in 46b8ad3 to avoid putting certain diagnostics into serialized diagnostic files only makes sense if 1. every diagnostic emitted in file A.swift while processing a different file B.swift would be emitted if we processed A.swift on its own 2. we actually do process A.swift on its own in the same build, or have previously done an incremental build and produced the same diagnostic But the latter isn't actually guaranteed: if one batch job exits with a failure status, the driver will exit as well, assuming there's no point in continuing. Fortunately, we do have a flag that overrides this behavior, -continue-building-after-errors. (As noted in the patch, -continue-building-after-errors isn't *exactly* what we want. But it's conservatively correct.)
1 parent 014f6f3 commit f9fd6a3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

lib/Driver/Compilation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ namespace driver {
528528
ReturnCode);
529529
}
530530

531+
// See how ContinueBuildingAfterErrors gets set up in Driver.cpp for
532+
// more info.
533+
assert((Comp.ContinueBuildingAfterErrors || !Comp.EnableBatchMode) &&
534+
"batch mode diagnostics require ContinueBuildingAfterErrors");
535+
531536
return Comp.ContinueBuildingAfterErrors ?
532537
TaskFinishedResponse::ContinueExecution :
533538
TaskFinishedResponse::StopExecution;

lib/Driver/Driver.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,6 @@ Driver::buildCompilation(const ToolChain &TC,
667667
}
668668

669669
bool SaveTemps = ArgList->hasArg(options::OPT_save_temps);
670-
bool ContinueBuildingAfterErrors =
671-
ArgList->hasArg(options::OPT_continue_building_after_errors);
672670
bool ShowDriverTimeCompilation =
673671
ArgList->hasArg(options::OPT_driver_time_compilation);
674672

@@ -703,6 +701,21 @@ Driver::buildCompilation(const ToolChain &TC,
703701
OI.CompilerMode = computeCompilerMode(*TranslatedArgList, Inputs, BatchMode);
704702
buildOutputInfo(TC, *TranslatedArgList, BatchMode, Inputs, OI);
705703

704+
// Note: Batch mode handling of serialized diagnostics requires that all
705+
// batches get to run, in order to make sure that all diagnostics emitted
706+
// during the compilation end up in at least one serialized diagnostic file.
707+
// Therefore, treat batch mode as implying -continue-building-after-errors.
708+
// (This behavior could be limited to only when serialized diagnostics are
709+
// being emitted, but this seems more consistent and less surprising for
710+
// users.)
711+
// FIXME: We don't really need (or want) a full ContinueBuildingAfterErrors.
712+
// If we fail to precompile a bridging header, for example, there's no need
713+
// to go on to compilation of source files, and if compilation of source files
714+
// fails, we shouldn't try to link. Instead, we'd want to let all jobs finish
715+
// but not schedule any new ones.
716+
const bool ContinueBuildingAfterErrors =
717+
BatchMode || ArgList->hasArg(options::OPT_continue_building_after_errors);
718+
706719
if (Diags.hadAnyError())
707720
return nullptr;
708721

test/Driver/continue-building-after-errors.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
// RUN: not %target-build-swift %S/Inputs/error.swift %s 2>&1 | %FileCheck %s
22
// RUN: not %target-build-swift -continue-building-after-errors %S/Inputs/error.swift %s 2>&1 | %FileCheck -check-prefix=CHECK-CONTINUE %s
33

4+
// Check that batch mode implies -continue-building-after-errors.
5+
// RUN: touch %t.empty.swift
6+
// RUN: not %target-build-swift -enable-batch-mode -j2 %S/Inputs/error.swift %S/../Inputs/empty.swift %s %t.empty.swift 2>&1 | %FileCheck -check-prefix=CHECK-BATCH %s
7+
48
// CHECK: self.bar = self.bar
59
// CHECK-NOT: self.baz = self.baz
610
// CHECK-CONTINUE: self.bar = self.bar
711
// CHECK-CONTINUE: self.baz = self.baz
12+
// CHECK-BATCH-DAG: self.bar = self.bar
13+
// CHECK-BATCH-DAG: self.baz = self.baz
814
struct Bar {
915
let baz: Int
1016
init() {

0 commit comments

Comments
 (0)