Skip to content

Commit cc32f93

Browse files
modocachejrose-apple
authored andcommitted
[SR-2400] Add -continue-building-after-errors (#4437)
Currently the Swift driver stops invoking frontend commands as soon as one of them reports an error. Add a flag to control this behavior, so that users can choose whether to see all the errors at once or bail out early.
1 parent 7a0ba75 commit cc32f93

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def warnings_as_errors : Flag<["-"], "warnings-as-errors">,
234234
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
235235
HelpText<"Treat warnings as errors">;
236236

237+
def continue_building_after_errors : Flag<["-"], "continue-building-after-errors">,
238+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
239+
HelpText<"Continue building, even after errors are encountered">;
240+
237241
// Platform options.
238242
def enable_app_extension : Flag<["-"], "application-extension">,
239243
Flags<[FrontendOption, NoInteractiveOption]>,

lib/Driver/Driver.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ std::unique_ptr<Compilation> Driver::buildCompilation(
367367
!ArgList->hasArg(options::OPT_embed_bitcode);
368368

369369
bool SaveTemps = ArgList->hasArg(options::OPT_save_temps);
370+
bool ContinueBuildingAfterErrors =
371+
ArgList->hasArg(options::OPT_continue_building_after_errors);
370372

371373
std::unique_ptr<DerivedArgList> TranslatedArgList(
372374
translateInputArgs(*ArgList));
@@ -506,10 +508,11 @@ std::unique_ptr<Compilation> Driver::buildCompilation(
506508
buildJobs(Actions, OI, OFM.get(), *TC, *C);
507509

508510
// For updating code we need to go through all the files and pick up changes,
509-
// even if they have compiler errors.
510-
// Also for getting bulk fixits.
511+
// even if they have compiler errors. Also for getting bulk fixits, or for when
512+
// users explicitly request to continue building despite errors.
511513
if (OI.CompilerMode == OutputInfo::Mode::UpdateCode ||
512-
OI.ShouldGenerateFixitEdits)
514+
OI.ShouldGenerateFixitEdits ||
515+
ContinueBuildingAfterErrors)
513516
C->setContinueBuildingAfterErrors();
514517

515518
if (ShowIncrementalBuildDecisions)

test/Driver/Inputs/error.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct Foo {
2+
let bar: Int
3+
init() {
4+
self.bar = self.bar
5+
}
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: not %swiftc_driver %S/Inputs/error.swift %s 2>&1 | %FileCheck %s
2+
// RUN: not %swiftc_driver -continue-building-after-errors %S/Inputs/error.swift %s 2>&1 | %FileCheck -check-prefix=CHECK-CONTINUE %s
3+
4+
// CHECK: self.bar = self.bar
5+
// CHECK-NOT: self.baz = self.baz
6+
// CHECK-CONTINUE: self.bar = self.bar
7+
// CHECK-CONTINUE: self.baz = self.baz
8+
struct Bar {
9+
let baz: Int
10+
init() {
11+
self.baz = self.baz
12+
}
13+
}

0 commit comments

Comments
 (0)