Skip to content

Commit 0c15021

Browse files
authored
Merge pull request swiftlang#27781 from owenv/descriptive-diagnostics-flag
[Diagnostics] Add -enable-experimental-descriptive-diagnostics frontend flag
2 parents e5c99ca + 0a84879 commit 0c15021

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
@@ -112,6 +112,9 @@ def verify_syntax_tree : Flag<["-"], "verify-syntax-tree">,
112112

113113
def show_diagnostics_after_fatal : Flag<["-"], "show-diagnostics-after-fatal">,
114114
HelpText<"Keep emitting subsequent diagnostics after a fatal error">;
115+
116+
def enable_descriptive_diagnostics : Flag<["-"], "enable-descriptive-diagnostics">,
117+
HelpText<"Show descriptive diagnostic information, if available.">;
115118

116119
def enable_swiftcall : Flag<["-"], "enable-swiftcall">,
117120
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
@@ -671,6 +671,8 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
671671
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
672672
Opts.WarningsAsErrors |= Args.hasArg(OPT_warnings_as_errors);
673673
Opts.PrintDiagnosticNames |= Args.hasArg(OPT_debug_diagnostic_names);
674+
Opts.EnableDescriptiveDiagnostics |=
675+
Args.hasArg(OPT_enable_descriptive_diagnostics);
674676

675677
assert(!(Opts.WarningsAsErrors && Opts.SuppressWarnings) &&
676678
"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
@@ -316,6 +316,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
316316
if (Invocation.getDiagnosticOptions().PrintDiagnosticNames) {
317317
Diagnostics.setPrintDiagnosticNames(true);
318318
}
319+
if (Invocation.getDiagnosticOptions().EnableDescriptiveDiagnostics) {
320+
Diagnostics.setUseDescriptiveDiagnostics(true);
321+
}
319322
}
320323

321324
// The ordering of ModuleLoaders is important!

0 commit comments

Comments
 (0)