Skip to content

Commit 9a86d2e

Browse files
committed
Add diagnostic categories indicating deprecations and non-usage
1 parent 204827c commit 9a86d2e

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,12 @@ namespace swift {
10171017
/// diagnostic.
10181018
bool isAPIDigesterBreakageDiagnostic(DiagID id) const;
10191019

1020+
/// \returns true if the diagnostic is marking a deprecation.
1021+
bool isDeprecationDiagnostic(DiagID id) const;
1022+
1023+
/// \returns true if the diagnostic is marking an unused element.
1024+
bool isNoUsageDiagnostic(DiagID id) const;
1025+
10201026
/// \returns true if any diagnostic consumer gave an error while invoking
10211027
//// \c finishProcessing.
10221028
bool finishProcessing();

lib/AST/DiagnosticEngine.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,34 @@ enum class DiagnosticOptions {
5555

5656
/// An API or ABI breakage diagnostic emitted by the API digester.
5757
APIDigesterBreakage,
58+
59+
/// A deprecation warning or error.
60+
Deprecation,
61+
62+
/// A diagnostic warning about an unused element.
63+
NoUsage,
5864
};
5965
struct StoredDiagnosticInfo {
6066
DiagnosticKind kind : 2;
6167
bool pointsToFirstBadToken : 1;
6268
bool isFatal : 1;
6369
bool isAPIDigesterBreakage : 1;
70+
bool isDeprecation : 1;
71+
bool isNoUsage : 1;
6472

6573
constexpr StoredDiagnosticInfo(DiagnosticKind k, bool firstBadToken,
66-
bool fatal, bool isAPIDigesterBreakage)
74+
bool fatal, bool isAPIDigesterBreakage,
75+
bool deprecation, bool noUsage)
6776
: kind(k), pointsToFirstBadToken(firstBadToken), isFatal(fatal),
68-
isAPIDigesterBreakage(isAPIDigesterBreakage) {}
77+
isAPIDigesterBreakage(isAPIDigesterBreakage), isDeprecation(deprecation),
78+
isNoUsage(noUsage) {}
6979
constexpr StoredDiagnosticInfo(DiagnosticKind k, DiagnosticOptions opts)
7080
: StoredDiagnosticInfo(k,
7181
opts == DiagnosticOptions::PointsToFirstBadToken,
7282
opts == DiagnosticOptions::Fatal,
73-
opts == DiagnosticOptions::APIDigesterBreakage) {}
83+
opts == DiagnosticOptions::APIDigesterBreakage,
84+
opts == DiagnosticOptions::Deprecation,
85+
opts == DiagnosticOptions::NoUsage) {}
7486
};
7587

7688
// Reproduce the DiagIDs, as we want both the size and access to the raw ids
@@ -332,6 +344,14 @@ bool DiagnosticEngine::isAPIDigesterBreakageDiagnostic(DiagID ID) const {
332344
return storedDiagnosticInfos[(unsigned)ID].isAPIDigesterBreakage;
333345
}
334346

347+
bool DiagnosticEngine::isDeprecationDiagnostic(DiagID ID) const {
348+
return storedDiagnosticInfos[(unsigned)ID].isDeprecation;
349+
}
350+
351+
bool DiagnosticEngine::isNoUsageDiagnostic(DiagID ID) const {
352+
return storedDiagnosticInfos[(unsigned)ID].isNoUsage;
353+
}
354+
335355
bool DiagnosticEngine::finishProcessing() {
336356
bool hadError = false;
337357
for (auto &Consumer : Consumers) {
@@ -1108,10 +1128,13 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
11081128
}
11091129
}
11101130

1111-
// Currently, only API digester diagnostics are assigned a category.
11121131
StringRef Category;
11131132
if (isAPIDigesterBreakageDiagnostic(diagnostic.getID()))
11141133
Category = "api-digester-breaking-change";
1134+
if (isDeprecationDiagnostic(diagnostic.getID()))
1135+
Category = "deprecation";
1136+
if (isNoUsageDiagnostic(diagnostic.getID()))
1137+
Category = "no-usage";
11151138

11161139
return DiagnosticInfo(
11171140
diagnostic.getID(), loc, toDiagnosticKind(behavior),

0 commit comments

Comments
 (0)