Files
swift-mirror/include/swift/Basic/Feature.h
Ben Barham d51c58a6f9 [Basic] hasFeature should succeed for promoted language features
Merge `$<Feature>` and `hasFeature` implementations.
  - `$<Feature>` did not support upcoming language features.
  - `hasFeature` did not support promoted language features and also
    didn't take into account `Options` in `Features.def`.

Remove `Options` entirely, it was always one of three cases:
  - `true`
  - `langOpts.hasFeature`
  - `hasSwiftSwiftParser`

Since `LangOptions::hasFeature` should always be used anyway, it's no
longer necessary. `hasSwiftSwiftParser` can be special cased when adding
the default promoted language features (by removing those features).

Resolves rdar://117917456.
2024-01-05 10:26:13 -08:00

74 lines
2.4 KiB
C++

//===--- Feature.h - Helpers related to Swift features ----------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_BASIC_FEATURES_H
#define SWIFT_BASIC_FEATURES_H
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
namespace swift {
class LangOptions;
/// Enumeration describing all of the named features.
enum class Feature {
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) FeatureName,
#include "swift/Basic/Features.def"
};
constexpr unsigned numFeatures() {
enum Features {
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) FeatureName,
#include "swift/Basic/Features.def"
NumFeatures
};
return NumFeatures;
}
/// Determine whether the given feature is suppressible.
bool isSuppressibleFeature(Feature feature);
/// Check whether the given feature is available in production compilers.
bool isFeatureAvailableInProduction(Feature feature);
/// Determine the in-source name of the given feature.
llvm::StringRef getFeatureName(Feature feature);
/// Determine whether the first feature is more recent (and thus implies
/// the existence of) the second feature. Only meaningful for suppressible
/// features.
inline bool featureImpliesFeature(Feature feature, Feature implied) {
// Suppressible features are expected to be listed in order of
// addition in Features.def.
return (unsigned) feature < (unsigned) implied;
}
/// Get the feature corresponding to this "future" feature, if there is one.
llvm::Optional<Feature> getUpcomingFeature(llvm::StringRef name);
/// Get the feature corresponding to this "experimental" feature, if there is
/// one.
llvm::Optional<Feature> getExperimentalFeature(llvm::StringRef name);
/// Get the major language version in which this feature was introduced, or
/// \c None if it does not have such a version.
llvm::Optional<unsigned> getFeatureLanguageVersion(Feature feature);
/// Determine whether this feature should be included in the
/// module interface
bool includeInModuleInterface(Feature feature);
}
#endif // SWIFT_BASIC_FEATURES_H