mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Frontend] Add -print-supported-features option
This is a replacement for `-emit-supported-features` that prints
all of the upcoming/experimental features supported by the compiler
with some additional meta information in JSON format to stdout.
(cherry picked from commit 55bd906906)
This commit is contained in:
74
lib/Basic/SupportedFeatures.cpp
Normal file
74
lib/Basic/SupportedFeatures.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
//===--- SupportedFeatures.cpp - Supported features printing --------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "swift/Basic/Feature.h"
|
||||
#include "swift/Frontend/Frontend.h"
|
||||
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
namespace swift {
|
||||
namespace features {
|
||||
/// Print information about what features upcoming/experimental are
|
||||
/// supported by the compiler.
|
||||
/// The information includes whether a feature is adoptable and for
|
||||
/// upcoming features - what is the first mode it's introduced.
|
||||
void printSupportedFeatures(llvm::raw_ostream &out) {
|
||||
std::array upcoming{
|
||||
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
|
||||
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) Feature::FeatureName,
|
||||
#include "swift/Basic/Features.def"
|
||||
};
|
||||
|
||||
std::vector<swift::Feature> experimental{{
|
||||
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
|
||||
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) Feature::FeatureName,
|
||||
#include "swift/Basic/Features.def"
|
||||
}};
|
||||
|
||||
// Include only experimental features that are available in production.
|
||||
llvm::erase_if(experimental, [](auto &feature) {
|
||||
return feature.isAvailableInProduction();
|
||||
});
|
||||
|
||||
out << "{\n";
|
||||
auto printFeature = [&out](const Feature &feature) {
|
||||
out << " ";
|
||||
out << "{ \"name\": \"" << feature.getName() << "\"";
|
||||
if (feature.isAdoptable()) {
|
||||
out << ", \"migratable\": true";
|
||||
}
|
||||
if (auto version = feature.getLanguageVersion()) {
|
||||
out << ", \"enabled_in\": " << *version;
|
||||
}
|
||||
out << " }";
|
||||
};
|
||||
|
||||
out << " \"features\": {\n";
|
||||
out << " \"upcoming\": [\n";
|
||||
llvm::interleave(upcoming, printFeature, [&out] { out << ",\n"; });
|
||||
out << "\n ],\n";
|
||||
|
||||
out << " \"experimental\": [\n";
|
||||
llvm::interleave(experimental, printFeature, [&out] { out << ",\n"; });
|
||||
out << "\n ]\n";
|
||||
|
||||
out << " }\n";
|
||||
out << "}\n";
|
||||
}
|
||||
|
||||
} // end namespace features
|
||||
} // end namespace swift
|
||||
Reference in New Issue
Block a user