@@ -52,11 +52,31 @@ static std::vector<DiagGroupID> migratableCategories(Feature feature) {
5252 }
5353}
5454
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+
5569// / Print information about what features upcoming/experimental are
5670// / supported by the compiler.
5771// / The information includes whether a feature is adoptable and for
5872// / upcoming features - what is the first mode it's introduced.
5973void 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+
6080 std::array upcoming{
6181#define LANGUAGE_FEATURE (FeatureName, SENumber, Description )
6282#define UPCOMING_FEATURE (FeatureName, SENumber, Version ) Feature::FeatureName,
@@ -93,10 +113,19 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
93113 if (auto version = feature.getLanguageVersion ()) {
94114 out << " , \" enabled_in\" : \" " << *version << " \" " ;
95115 }
116+
117+ if (auto flagName = optionalFlagName (feature)) {
118+ out << " , \" flag_name\" : \" " << *flagName << " \" " ;
119+ }
120+
96121 out << " }" ;
97122 };
98123
99124 out << " \" features\" : {\n " ;
125+ out << " \" optional\" : [\n " ;
126+ llvm::interleave (optional, printFeature, [&out] { out << " ,\n " ; });
127+ out << " \n ],\n " ;
128+
100129 out << " \" upcoming\" : [\n " ;
101130 llvm::interleave (upcoming, printFeature, [&out] { out << " ,\n " ; });
102131 out << " \n ],\n " ;
0 commit comments