Skip to content

Commit 0a84879

Browse files
committed
[Diagnostics] Add -enable-experimental-descriptive-diagnostics frontend flag
This flag will feature-gate work on producing more descriptive diagnostic messages. It will remain a hidden frontend option until these improvements are ready to ship.
1 parent b32e82c commit 0a84879

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ namespace swift {
670670
/// Print diagnostic names after their messages
671671
bool printDiagnosticNames = false;
672672

673+
/// Use descriptive diagnostic style when available.
674+
bool useDescriptiveDiagnostics = false;
675+
673676
friend class InFlightDiagnostic;
674677
friend class DiagnosticTransaction;
675678
friend class CompoundDiagnosticTransaction;
@@ -713,6 +716,13 @@ namespace swift {
713716
return printDiagnosticNames;
714717
}
715718

719+
void setUseDescriptiveDiagnostics(bool val) {
720+
useDescriptiveDiagnostics = val;
721+
}
722+
bool getUseDescriptiveDiagnostics() const {
723+
return useDescriptiveDiagnostics;
724+
}
725+
716726
void ignoreDiagnostic(DiagID id) {
717727
state.setDiagnosticBehavior(id, DiagnosticState::Behavior::Ignore);
718728
}

include/swift/Basic/DiagnosticOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class DiagnosticOptions {
5555
// When printing diagnostics, include the diagnostic name at the end
5656
bool PrintDiagnosticNames = false;
5757

58+
/// If set to true, produce more descriptive diagnostic output if available.
59+
/// Descriptive diagnostic output is not intended to be machine-readable.
60+
bool EnableDescriptiveDiagnostics = false;
61+
5862
/// Return a hash code of any components from these options that should
5963
/// contribute to a Swift Bridging PCH hash.
6064
llvm::hash_code getPCHHashComponents() const {

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def verify_syntax_tree : Flag<["-"], "verify-syntax-tree">,
109109

110110
def show_diagnostics_after_fatal : Flag<["-"], "show-diagnostics-after-fatal">,
111111
HelpText<"Keep emitting subsequent diagnostics after a fatal error">;
112+
113+
def enable_descriptive_diagnostics : Flag<["-"], "enable-descriptive-diagnostics">,
114+
HelpText<"Show descriptive diagnostic information, if available.">;
112115

113116
def enable_swiftcall : Flag<["-"], "enable-swiftcall">,
114117
HelpText<"Enable the use of LLVM swiftcall support">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
678678
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
679679
Opts.WarningsAsErrors |= Args.hasArg(OPT_warnings_as_errors);
680680
Opts.PrintDiagnosticNames |= Args.hasArg(OPT_debug_diagnostic_names);
681+
Opts.EnableDescriptiveDiagnostics |=
682+
Args.hasArg(OPT_enable_descriptive_diagnostics);
681683

682684
assert(!(Opts.WarningsAsErrors && Opts.SuppressWarnings) &&
683685
"conflicting arguments; should have been caught by driver");

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
315315
if (Invocation.getDiagnosticOptions().PrintDiagnosticNames) {
316316
Diagnostics.setPrintDiagnosticNames(true);
317317
}
318+
if (Invocation.getDiagnosticOptions().EnableDescriptiveDiagnostics) {
319+
Diagnostics.setUseDescriptiveDiagnostics(true);
320+
}
318321
}
319322

320323
bool CompilerInstance::setUpModuleLoaders() {

0 commit comments

Comments
 (0)