@@ -52,11 +52,31 @@ static std::vector<DiagGroupID> migratableCategories(Feature feature) {
52
52
}
53
53
}
54
54
55
+ // / For optional language features, return the flag name used by the compiler to enable the feature. For all others,
56
+ // / returns an empty optional.
57
+ static std::optional<std::string_view> optionalFlagName (Feature feature) {
58
+ switch (feature) {
59
+ case Feature::StrictMemorySafety:
60
+ return " -strict-memory-safety" ;
61
+
62
+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) case Feature::FeatureName:
63
+ #define OPTIONAL_LANGUAGE_FEATURE (FeatureName, SENumber, Description )
64
+ #include " swift/Basic/Features.def"
65
+ return std::nullopt;
66
+ }
67
+ }
68
+
55
69
// / Print information about what features upcoming/experimental are
56
70
// / supported by the compiler.
57
71
// / The information includes whether a feature is adoptable and for
58
72
// / upcoming features - what is the first mode it's introduced.
59
73
void printSupportedFeatures (llvm::raw_ostream &out) {
74
+ std::array optional{
75
+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description )
76
+ #define OPTIONAL_LANGUAGE_FEATURE (FeatureName, SENumber, Description ) Feature::FeatureName,
77
+ #include " swift/Basic/Features.def"
78
+ };
79
+
60
80
std::array upcoming{
61
81
#define LANGUAGE_FEATURE (FeatureName, SENumber, Description )
62
82
#define UPCOMING_FEATURE (FeatureName, SENumber, Version ) Feature::FeatureName,
@@ -93,10 +113,19 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
93
113
if (auto version = feature.getLanguageVersion ()) {
94
114
out << " , \" enabled_in\" : \" " << *version << " \" " ;
95
115
}
116
+
117
+ if (auto flagName = optionalFlagName (feature)) {
118
+ out << " , \" flag_name\" : \" " << *flagName << " \" " ;
119
+ }
120
+
96
121
out << " }" ;
97
122
};
98
123
99
124
out << " \" features\" : {\n " ;
125
+ out << " \" optional\" : [\n " ;
126
+ llvm::interleave (optional, printFeature, [&out] { out << " ,\n " ; });
127
+ out << " \n ],\n " ;
128
+
100
129
out << " \" upcoming\" : [\n " ;
101
130
llvm::interleave (upcoming, printFeature, [&out] { out << " ,\n " ; });
102
131
out << " \n ],\n " ;
0 commit comments