Skip to content

Commit f14efce

Browse files
committed
---
yaml --- r: 349347 b: refs/heads/master-next c: 6bca134 h: refs/heads/master i: 349345: 21414e6 349343: f3ff42a
1 parent 89c6c4c commit f14efce

File tree

10 files changed

+74
-7
lines changed

10 files changed

+74
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 2f37dd154c6385a0824e39577a2a3ff20f59cc12
3+
refs/heads/master-next: 6bca134a930a7dd2e77da52aa8264b0b49a7ec81
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/docs/DebuggingTheCompiler.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ diagnostic engine to assert on the first error/warning:
8686
These allow one to dump a stack trace of where the diagnostic is being emitted
8787
(if run without a debugger) or drop into the debugger if a debugger is attached.
8888

89+
Finding Diagnostic Names
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
Some diagnostics rely heavily on format string arguments, so it can be difficult
93+
to find their implementation by searching for parts of the emitted message in
94+
the codebase. To print the corresponding diagnostic name at the end of each
95+
emitted message, use the ``-Xfrontend -debug-diagnostic-names`` argument.
96+
8997
Debugging the Type Checker
9098
--------------------------
9199

branches/master-next/include/swift/AST/DiagnosticEngine.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ namespace swift {
583583
/// input being compiled.
584584
/// May be invalid.
585585
SourceLoc bufferIndirectlyCausingDiagnostic;
586+
587+
/// Print diagnostic names after their messages
588+
bool printDiagnosticNames = false;
586589

587590
friend class InFlightDiagnostic;
588591
friend class DiagnosticTransaction;
@@ -618,6 +621,14 @@ namespace swift {
618621
return state.getWarningsAsErrors();
619622
}
620623

624+
/// Whether to print diagnostic names after their messages
625+
void setPrintDiagnosticNames(bool val) {
626+
printDiagnosticNames = val;
627+
}
628+
bool getPrintDiagnosticNames() const {
629+
return printDiagnosticNames;
630+
}
631+
621632
void ignoreDiagnostic(DiagID id) {
622633
state.setDiagnosticBehavior(id, DiagnosticState::Behavior::Ignore);
623634
}
@@ -826,7 +837,8 @@ namespace swift {
826837
void emitTentativeDiagnostics();
827838

828839
public:
829-
static const char *diagnosticStringFor(const DiagID id);
840+
static const char *diagnosticStringFor(const DiagID id,
841+
bool printDiagnosticName);
830842

831843
/// If there is no clear .dia file for a diagnostic, put it in the one
832844
/// corresponding to the SourceLoc given here.

branches/master-next/include/swift/Basic/DiagnosticOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class DiagnosticOptions {
5252
/// Treat all warnings as errors
5353
bool WarningsAsErrors = false;
5454

55+
// When printing diagnostics, include the diagnostic name at the end
56+
bool PrintDiagnosticNames = false;
57+
5558
/// Return a hash code of any components from these options that should
5659
/// contribute to a Swift Bridging PCH hash.
5760
llvm::hash_code getPCHHashComponents() const {

branches/master-next/include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ def color_diagnostics : Flag<["-"], "color-diagnostics">,
306306
def no_color_diagnostics : Flag<["-"], "no-color-diagnostics">,
307307
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
308308
HelpText<"Do not print diagnostics in color">;
309+
def debug_diagnostic_names : Flag<["-"], "debug-diagnostic-names">,
310+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, HelpHidden]>,
311+
HelpText<"Include diagnostic names when printing">;
309312

310313
def module_cache_path : Separate<["-"], "module-cache-path">,
311314
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,

branches/master-next/lib/AST/DiagnosticEngine.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ static constexpr const char * const diagnosticStrings[] = {
9999
"<not a diagnostic>",
100100
};
101101

102+
static constexpr const char *const debugDiagnosticStrings[] = {
103+
#define ERROR(ID, Options, Text, Signature) Text " [" #ID "]",
104+
#define WARNING(ID, Options, Text, Signature) Text " [" #ID "]",
105+
#define NOTE(ID, Options, Text, Signature) Text " [" #ID "]",
106+
#define REMARK(ID, Options, Text, Signature) Text " [" #ID "]",
107+
#include "swift/AST/DiagnosticsAll.def"
108+
"<not a diagnostic>",
109+
};
110+
102111
DiagnosticState::DiagnosticState() {
103112
// Initialize our per-diagnostic state to default
104113
perDiagnosticBehavior.resize(LocalDiagID::NumDiags, Behavior::Unspecified);
@@ -893,14 +902,18 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
893902
Info.Ranges = diagnostic.getRanges();
894903
Info.FixIts = diagnostic.getFixIts();
895904
for (auto &Consumer : Consumers) {
896-
Consumer->handleDiagnostic(SourceMgr, loc, toDiagnosticKind(behavior),
897-
diagnosticStringFor(Info.ID),
898-
diagnostic.getArgs(), Info,
899-
getDefaultDiagnosticLoc());
905+
Consumer->handleDiagnostic(
906+
SourceMgr, loc, toDiagnosticKind(behavior),
907+
diagnosticStringFor(Info.ID, getPrintDiagnosticNames()),
908+
diagnostic.getArgs(), Info, getDefaultDiagnosticLoc());
900909
}
901910
}
902911

903-
const char *DiagnosticEngine::diagnosticStringFor(const DiagID id) {
912+
const char *DiagnosticEngine::diagnosticStringFor(const DiagID id,
913+
bool printDiagnosticName) {
914+
if (printDiagnosticName) {
915+
return debugDiagnosticStrings[(unsigned)id];
916+
}
904917
return diagnosticStrings[(unsigned)id];
905918
}
906919

branches/master-next/lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
233233
options::OPT_experimental_dependency_include_intrafile);
234234
inputArgs.AddLastArg(arguments, options::OPT_package_description_version);
235235
inputArgs.AddLastArg(arguments, options::OPT_serialize_diagnostics_path);
236+
inputArgs.AddLastArg(arguments, options::OPT_debug_diagnostic_names);
236237
inputArgs.AddLastArg(arguments, options::OPT_enable_astscope_lookup);
237238
inputArgs.AddLastArg(arguments, options::OPT_disable_astscope_lookup);
238239
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);

branches/master-next/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
670670
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
671671
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
672672
Opts.WarningsAsErrors |= Args.hasArg(OPT_warnings_as_errors);
673+
Opts.PrintDiagnosticNames |= Args.hasArg(OPT_debug_diagnostic_names);
673674

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

branches/master-next/lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
308308
if (Invocation.getDiagnosticOptions().WarningsAsErrors) {
309309
Diagnostics.setWarningsAsErrors(true);
310310
}
311+
if (Invocation.getDiagnosticOptions().PrintDiagnosticNames) {
312+
Diagnostics.setPrintDiagnosticNames(true);
313+
}
311314
}
312315

313316
bool CompilerInstance::setUpModuleLoaders() {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: not %target-swift-frontend -debug-diagnostic-names -typecheck %s 2>&1 | %FileCheck %s --check-prefix=CHECK_NAMES
2+
// RUN: not %target-swift-frontend -typecheck %s 2>&1 | %FileCheck %s --check-prefix=CHECK_NONAMES
3+
4+
let x =
5+
// CHECK_NAMES: error: expected initial value after '=' [expected_init_value]{{$}}
6+
// CHECK_NONAMES: error: expected initial value after '='{{$}}
7+
8+
guard let y = 0 else {}
9+
// CHECK_NAMES: error: initializer for conditional binding must have Optional type, not 'Int' [condition_optional_element_pattern_not_valid_type]{{$}}
10+
// CHECK_NONAMES: error: initializer for conditional binding must have Optional type, not 'Int'{{$}}
11+
12+
let z: Double = ""
13+
// CHECK_NAMES: error: cannot convert value of type 'String' to specified type 'Double' [cannot_convert_initializer_value]{{$}}
14+
// CHECK_NONAMES: error: cannot convert value of type 'String' to specified type 'Double'{{$}}
15+
16+
func foo() -> Int {
17+
return
18+
42
19+
}
20+
// CHECK_NAMES: warning: expression following 'return' is treated as an argument of the 'return' [unindented_code_after_return]{{$}}
21+
// CHECK_NAMES: note: indent the expression to silence this warning [indent_expression_to_silence]{{$}}
22+
// CHECK_NONAMES: warning: expression following 'return' is treated as an argument of the 'return'{{$}}
23+
// CHECK_NONAMES: note: indent the expression to silence this warning{{$}}

0 commit comments

Comments
 (0)