Skip to content

Commit 7f2649f

Browse files
committed
Add the set of diagnostic categories to each migratable feature
The name of a migratable feature might differ from the names of the diagnostic groups containing the diagnostics that are used to drive migration for that feature. Provide the set of diagnostic categories that are associated with each migratable feature as part of the supported features list.
1 parent 6a800c9 commit 7f2649f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/Basic/SupportedFeatures.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <array>
1414
#include <vector>
1515

16+
#include "swift/AST/DiagnosticGroups.h"
1617
#include "swift/Basic/Feature.h"
1718
#include "swift/Frontend/Frontend.h"
1819

@@ -22,6 +23,32 @@ using namespace swift;
2223

2324
namespace swift {
2425
namespace features {
26+
27+
/// The subset of diagnostic groups (called categories by the diagnostic machinery) whose diagnostics should be
28+
/// considered to be part of the migration for this feature.
29+
///
30+
/// When making a
31+
static std::vector<DiagGroupID> migratableCategories(Feature feature) {
32+
switch (feature) {
33+
case Feature::InnerKind::ExistentialAny:
34+
return { DiagGroupID::ExistentialAny };
35+
case Feature::InnerKind::InferIsolatedConformances:
36+
return { DiagGroupID::IsolatedConformances };
37+
case Feature::InnerKind::NonisolatedNonsendingByDefault:
38+
return { DiagGroupID::NonisolatedNonsendingByDefault };
39+
case Feature::InnerKind::StrictMemorySafety:
40+
return { DiagGroupID::StrictMemorySafety };
41+
42+
// Provide unreachable cases for all of the non-migratable features.
43+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) case Feature::FeatureName:
44+
#define MIGRATABLE_UPCOMING_FEATURE(FeatureName, SENumber, Version)
45+
#define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)
46+
#define MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE(FeatureName, SENumber, Name)
47+
#include "swift/Basic/Features.def"
48+
llvm_unreachable("Not a migratable feature");
49+
}
50+
}
51+
2552
/// Print information about what features upcoming/experimental are
2653
/// supported by the compiler.
2754
/// The information includes whether a feature is adoptable and for
@@ -50,6 +77,15 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
5077
out << "{ \"name\": \"" << feature.getName() << "\"";
5178
if (feature.isMigratable()) {
5279
out << ", \"migratable\": true";
80+
81+
auto categories = migratableCategories(feature);
82+
out << ", \"categories\": [";
83+
llvm::interleave(categories, [&out](DiagGroupID diagGroupID) {
84+
out << "\"" << getDiagGroupInfoByID(diagGroupID).name << "\"";
85+
}, [&out] {
86+
out << ", ";
87+
});
88+
out << "]";
5389
}
5490
if (auto version = feature.getLanguageVersion()) {
5591
out << ", \"enabled_in\": \"" << *version << "\"";

test/Frontend/print-supported-features.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// CHECK: "features": {
44
// CHECK-NEXT: "upcoming": [
5-
// CHECK: { "name": "{{.*}}"{{, "migratable": true}}, "enabled_in": "{{.*}}" }
5+
// CHECK: { "name": "InferIsolatedConformances", "migratable": true, "categories": ["IsolatedConformances"], "enabled_in": "7" },
66
// CHECK: ],
7-
// CHECK-NEXT: "experimental": [
7+
// CHECK: "experimental": [
88
// CHECK: { "name": "{{.*}}" }
99
// CHECK: ]
1010
// CHECK: }

0 commit comments

Comments
 (0)