1+ // ===--- SupportedFeatures.cpp - Supported features printing --------------===//
2+ //
3+ // This source file is part of the Swift.org open source project
4+ //
5+ // Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+ // Licensed under Apache License v2.0 with Runtime Library Exception
7+ //
8+ // See https://swift.org/LICENSE.txt for license information
9+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+ //
11+ // ===----------------------------------------------------------------------===//
12+
13+ #include < array>
14+ #include < vector>
15+
16+ #include " swift/Basic/Feature.h"
17+ #include " swift/Frontend/Frontend.h"
18+
19+ #include " llvm/Support/raw_ostream.h"
20+
21+ using namespace swift ;
22+
23+ namespace swift {
24+ namespace features {
25+ // / Print information about what features upcoming/experimental are
26+ // / supported by the compiler.
27+ // / The information includes whether a feature is adoptable and for
28+ // / upcoming features - what is the first mode it's introduced.
29+ void printSupportedFeatures (llvm::raw_ostream &out) {
30+ std::array upcoming{
31+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description )
32+ #define UPCOMING_FEATURE (FeatureName, SENumber, Version ) Feature::FeatureName,
33+ #include " swift/Basic/Features.def"
34+ };
35+
36+ std::vector<swift::Feature> experimental{{
37+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description )
38+ #define EXPERIMENTAL_FEATURE (FeatureName, AvailableInProd ) Feature::FeatureName,
39+ #include " swift/Basic/Features.def"
40+ }};
41+
42+ // Include only experimental features that are available in production.
43+ llvm::erase_if (experimental, [](auto &feature) {
44+ return feature.isAvailableInProduction ();
45+ });
46+
47+ out << " {\n " ;
48+ auto printFeature = [&out](const Feature &feature) {
49+ out << " " ;
50+ out << " { \" name\" : \" " << feature.getName () << " \" " ;
51+ if (feature.isAdoptable ()) {
52+ out << " , \" migratable\" : true" ;
53+ }
54+ if (auto version = feature.getLanguageVersion ()) {
55+ out << " , \" enabled_in\" : " << *version;
56+ }
57+ out << " }" ;
58+ };
59+
60+ out << " \" features\" : {\n " ;
61+ out << " \" upcoming\" : [\n " ;
62+ llvm::interleave (upcoming, printFeature, [&out] { out << " ,\n " ; });
63+ out << " \n ],\n " ;
64+
65+ out << " \" experimental\" : [\n " ;
66+ llvm::interleave (experimental, printFeature, [&out] { out << " ,\n " ; });
67+ out << " \n ]\n " ;
68+
69+ out << " }\n " ;
70+ out << " }\n " ;
71+ }
72+
73+ } // end namespace features
74+ } // end namespace swift
0 commit comments