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,33 @@ using namespace swift;
2223
2324namespace swift {
2425namespace 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 feature migratable, ensure that all of the warnings that are used to drive the migration are
31+ // / part of a diagnostic group, and put that diagnostic group into the list for that feature here.
32+ static std::vector<DiagGroupID> migratableCategories (Feature feature) {
33+ switch (feature) {
34+ case Feature::InnerKind::ExistentialAny:
35+ return { DiagGroupID::ExistentialAny };
36+ case Feature::InnerKind::InferIsolatedConformances:
37+ return { DiagGroupID::IsolatedConformances };
38+ case Feature::InnerKind::NonisolatedNonsendingByDefault:
39+ return { DiagGroupID::NonisolatedNonsendingByDefault };
40+ case Feature::InnerKind::StrictMemorySafety:
41+ return { DiagGroupID::StrictMemorySafety };
42+
43+ // Provide unreachable cases for all of the non-migratable features.
44+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) case Feature::FeatureName:
45+ #define MIGRATABLE_UPCOMING_FEATURE (FeatureName, SENumber, Version )
46+ #define MIGRATABLE_EXPERIMENTAL_FEATURE (FeatureName, AvailableInProd )
47+ #define MIGRATABLE_OPTIONAL_LANGUAGE_FEATURE (FeatureName, SENumber, Name )
48+ #include " swift/Basic/Features.def"
49+ llvm_unreachable (" Not a migratable feature" );
50+ }
51+ }
52+
2553// / Print information about what features upcoming/experimental are
2654// / supported by the compiler.
2755// / The information includes whether a feature is adoptable and for
@@ -50,9 +78,18 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
5078 out << " { \" name\" : \" " << feature.getName () << " \" " ;
5179 if (feature.isMigratable ()) {
5280 out << " , \" migratable\" : true" ;
81+
82+ auto categories = migratableCategories (feature);
83+ out << " , \" categories\" : [" ;
84+ llvm::interleave (categories, [&out](DiagGroupID diagGroupID) {
85+ out << " \" " << getDiagGroupInfoByID (diagGroupID).name << " \" " ;
86+ }, [&out] {
87+ out << " , " ;
88+ });
89+ out << " ]" ;
5390 }
5491 if (auto version = feature.getLanguageVersion ()) {
55- out << " , \" enabled_in\" : " << *version;
92+ out << " , \" enabled_in\" : \" " << *version << " \" " ;
5693 }
5794 out << " }" ;
5895 };
@@ -71,4 +108,4 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
71108}
72109
73110} // end namespace features
74- } // end namespace swift
111+ } // end namespace swift
0 commit comments