Skip to content

Commit 13a1505

Browse files
authored
Merge pull request #71230 from hborla/swift-6-statistics
2 parents 4d53245 + 32038d9 commit 13a1505

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/DeclNameLoc.h"
2323
#include "swift/AST/DiagnosticConsumer.h"
2424
#include "swift/AST/TypeLoc.h"
25+
#include "swift/Basic/Statistic.h"
2526
#include "swift/Basic/Version.h"
2627
#include "swift/Localization/LocalizationFormat.h"
2728
#include "llvm/ADT/BitVector.h"
@@ -888,6 +889,10 @@ namespace swift {
888889
/// until a specific language version, e.g. Swift 6.
889890
version::Version languageVersion;
890891

892+
/// The stats reporter used to keep track of Swift 6 errors
893+
/// diagnosed via \c warnUntilSwiftVersion(6).
894+
UnifiedStatsReporter *statsReporter = nullptr;
895+
891896
/// Whether we are actively pretty-printing a declaration as part of
892897
/// diagnostics.
893898
bool IsPrettyPrintingDecl = false;
@@ -959,6 +964,10 @@ namespace swift {
959964

960965
void setLanguageVersion(version::Version v) { languageVersion = v; }
961966

967+
void setStatsReporter(UnifiedStatsReporter *stats) {
968+
statsReporter = stats;
969+
}
970+
962971
void setLocalization(StringRef locale, StringRef path) {
963972
assert(!locale.empty());
964973
assert(!path.empty());

include/swift/Basic/Statistics.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ FRONTEND_STATISTIC(Sema, NumTypesDeserialized)
252252
/// Number of lazy iterable declaration contexts left unloaded.
253253
FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
254254

255+
/// Number of Swift 6 errors, including those that are downgraded to
256+
/// warnings in Swift 5 mode.
257+
FRONTEND_STATISTIC(Sema, NumSwift6Errors)
258+
255259
/// Number of lookups into a module and its imports.
256260

257261
/// All type check requests go into the Sema area.

lib/AST/DiagnosticEngine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ InFlightDiagnostic::warnUntilSwiftVersion(unsigned majorVersion) {
334334
.wrapIn(diag::error_in_future_swift_version, majorVersion);
335335
}
336336

337+
if (majorVersion == 6) {
338+
if (auto stats = Engine->statsReporter) {
339+
++stats->getFrontendCounters().NumSwift6Errors;
340+
}
341+
}
342+
337343
return *this;
338344
}
339345

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ void CompilerInstance::setupStatsReporter() {
375375
// Hand the stats reporter down to the ASTContext so the rest of the compiler
376376
// can use it.
377377
getASTContext().setStatsReporter(Reporter.get());
378+
Diagnostics.setStatsReporter(Reporter.get());
378379
Stats = std::move(Reporter);
379380
}
380381

0 commit comments

Comments
 (0)