mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Feature] Rename Feature APIs from adoption to migration
(cherry picked from commit 085078dd8a)
This commit is contained in:
@@ -59,9 +59,9 @@ GROUPED_WARNING(cannot_disable_feature_with_mode, StrictLanguageFeatures, none,
|
||||
"'%0' argument '%1' cannot specify a mode",
|
||||
(StringRef, StringRef))
|
||||
|
||||
GROUPED_WARNING(feature_does_not_support_adoption_mode, StrictLanguageFeatures,
|
||||
GROUPED_WARNING(feature_does_not_support_migration_mode, StrictLanguageFeatures,
|
||||
none,
|
||||
"feature '%0' does not support adoption mode",
|
||||
"feature '%0' does not support migration mode",
|
||||
(StringRef))
|
||||
|
||||
ERROR(error_unknown_library_level, none,
|
||||
|
||||
@@ -57,8 +57,8 @@ struct Feature {
|
||||
/// Determine the in-source name of the given feature.
|
||||
llvm::StringRef getName() const;
|
||||
|
||||
/// Determine whether the given feature supports adoption mode.
|
||||
bool isAdoptable() const;
|
||||
/// Determine whether the given feature supports migration mode.
|
||||
bool isMigratable() const;
|
||||
|
||||
/// Determine whether this feature should be included in the
|
||||
/// module interface
|
||||
|
||||
@@ -830,7 +830,7 @@ namespace swift {
|
||||
|
||||
/// A wrapper around the feature state enumeration.
|
||||
struct FeatureState {
|
||||
enum class Kind : uint8_t { Off, EnabledForAdoption, Enabled };
|
||||
enum class Kind : uint8_t { Off, EnabledForMigration, Enabled };
|
||||
|
||||
private:
|
||||
Feature feature;
|
||||
@@ -843,9 +843,9 @@ namespace swift {
|
||||
/// Returns whether the feature is enabled.
|
||||
bool isEnabled() const;
|
||||
|
||||
/// Returns whether the feature is enabled in adoption mode. Should only
|
||||
/// Returns whether the feature is enabled in migration mode. Should only
|
||||
/// be called if the feature is known to support this mode.
|
||||
bool isEnabledForAdoption() const;
|
||||
bool isEnabledForMigration() const;
|
||||
|
||||
operator Kind() const { return state; }
|
||||
};
|
||||
@@ -878,9 +878,9 @@ namespace swift {
|
||||
/// `false` if a feature by this name is not known.
|
||||
bool hasFeature(llvm::StringRef featureName) const;
|
||||
|
||||
/// Enables the given feature (enables in adoption mode if `forAdoption` is
|
||||
/// `true`).
|
||||
void enableFeature(Feature feature, bool forAdoption = false);
|
||||
/// Enables the given feature (enables in migration mode if `forMigration`
|
||||
/// is `true`).
|
||||
void enableFeature(Feature feature, bool forMigration = false);
|
||||
|
||||
/// Disables the given feature.
|
||||
void disableFeature(Feature feature);
|
||||
|
||||
@@ -69,7 +69,7 @@ std::optional<unsigned> Feature::getLanguageVersion() const {
|
||||
}
|
||||
}
|
||||
|
||||
bool Feature::isAdoptable() const {
|
||||
bool Feature::isMigratable() const {
|
||||
switch (kind) {
|
||||
#define MIGRATABLE_UPCOMING_FEATURE(FeatureName, SENumber, Version)
|
||||
#define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)
|
||||
|
||||
@@ -298,10 +298,10 @@ bool LangOptions::FeatureState::isEnabled() const {
|
||||
return state == FeatureState::Kind::Enabled;
|
||||
}
|
||||
|
||||
bool LangOptions::FeatureState::isEnabledForAdoption() const {
|
||||
ASSERT(feature.isAdoptable() && "You forgot to make the feature adoptable!");
|
||||
bool LangOptions::FeatureState::isEnabledForMigration() const {
|
||||
ASSERT(feature.isMigratable() && "You forgot to make the feature migratable!");
|
||||
|
||||
return state == FeatureState::Kind::EnabledForAdoption;
|
||||
return state == FeatureState::Kind::EnabledForMigration;
|
||||
}
|
||||
|
||||
LangOptions::FeatureStateStorage::FeatureStateStorage()
|
||||
@@ -357,10 +357,10 @@ bool LangOptions::hasFeature(llvm::StringRef featureName) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void LangOptions::enableFeature(Feature feature, bool forAdoption) {
|
||||
if (forAdoption) {
|
||||
ASSERT(feature.isAdoptable());
|
||||
featureStates.setState(feature, FeatureState::Kind::EnabledForAdoption);
|
||||
void LangOptions::enableFeature(Feature feature, bool forMigration) {
|
||||
if (forMigration) {
|
||||
ASSERT(feature.isMigratable());
|
||||
featureStates.setState(feature, FeatureState::Kind::EnabledForMigration);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
|
||||
auto printFeature = [&out](const Feature &feature) {
|
||||
out << " ";
|
||||
out << "{ \"name\": \"" << feature.getName() << "\"";
|
||||
if (feature.isAdoptable()) {
|
||||
if (feature.isMigratable()) {
|
||||
out << ", \"migratable\": true";
|
||||
}
|
||||
if (auto version = feature.getLanguageVersion()) {
|
||||
|
||||
@@ -872,7 +872,7 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
|
||||
|
||||
if (featureMode) {
|
||||
if (isEnableFeatureFlag) {
|
||||
const auto isAdoptable = feature->isAdoptable();
|
||||
const auto isMigratable = feature->isMigratable();
|
||||
|
||||
// Diagnose an invalid mode.
|
||||
StringRef validModeName = "adoption";
|
||||
@@ -880,13 +880,13 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
|
||||
Diags.diagnose(SourceLoc(), diag::invalid_feature_mode, *featureMode,
|
||||
featureName,
|
||||
/*didYouMean=*/validModeName,
|
||||
/*showDidYouMean=*/isAdoptable);
|
||||
/*showDidYouMean=*/isMigratable);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isAdoptable) {
|
||||
if (!isMigratable) {
|
||||
Diags.diagnose(SourceLoc(),
|
||||
diag::feature_does_not_support_adoption_mode,
|
||||
diag::feature_does_not_support_migration_mode,
|
||||
featureName);
|
||||
continue;
|
||||
}
|
||||
@@ -904,7 +904,7 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
|
||||
|
||||
// Enable the feature if requested.
|
||||
if (isEnableFeatureFlag)
|
||||
Opts.enableFeature(*feature, /*forAdoption=*/featureMode.has_value());
|
||||
Opts.enableFeature(*feature, /*forMigration=*/featureMode.has_value());
|
||||
}
|
||||
|
||||
// Since pseudo-features don't have a boolean on/off state, process them in
|
||||
|
||||
@@ -60,7 +60,7 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
|
||||
const auto feature = Feature::NonisolatedNonsendingByDefault;
|
||||
|
||||
ASSERT(node);
|
||||
ASSERT(ctx.LangOpts.getFeatureState(feature).isEnabledForAdoption());
|
||||
ASSERT(ctx.LangOpts.getFeatureState(feature).isEnabledForMigration());
|
||||
|
||||
ValueDecl *decl = nullptr;
|
||||
ClosureExpr *closure = nullptr;
|
||||
|
||||
@@ -4810,7 +4810,7 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
|
||||
isolation = isolation.withPreconcurrency(preconcurrency);
|
||||
|
||||
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
|
||||
.isEnabledForAdoption()) {
|
||||
.isEnabledForMigration()) {
|
||||
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, closure, isolation);
|
||||
}
|
||||
|
||||
@@ -6296,7 +6296,7 @@ InferredActorIsolation ActorIsolationRequest::evaluate(Evaluator &evaluator,
|
||||
|
||||
auto &ctx = value->getASTContext();
|
||||
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
|
||||
.isEnabledForAdoption()) {
|
||||
.isEnabledForMigration()) {
|
||||
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, value,
|
||||
inferredIsolation.isolation);
|
||||
}
|
||||
|
||||
@@ -4252,7 +4252,7 @@ NeverNullType TypeResolver::resolveASTFunctionType(
|
||||
isolation = FunctionTypeIsolation::forNonIsolated();
|
||||
} else {
|
||||
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
|
||||
.isEnabledForAdoption()) {
|
||||
.isEnabledForMigration()) {
|
||||
// Diagnose only in the interface stage, which is run once.
|
||||
if (inStage(TypeResolutionStage::Interface)) {
|
||||
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, repr, isolation);
|
||||
@@ -6578,7 +6578,7 @@ private:
|
||||
// A missing `any` or `some` is always diagnosed if this feature not
|
||||
// disabled.
|
||||
auto featureState = ctx.LangOpts.getFeatureState(Feature::ExistentialAny);
|
||||
if (featureState.isEnabled() || featureState.isEnabledForAdoption()) {
|
||||
if (featureState.isEnabled() || featureState.isEnabledForMigration()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6671,10 +6671,10 @@ private:
|
||||
/*isAlias=*/isa<TypeAliasDecl>(decl)));
|
||||
}
|
||||
|
||||
// If `ExistentialAny` is enabled in adoption mode, warn unconditionally.
|
||||
// If `ExistentialAny` is enabled in migration mode, warn unconditionally.
|
||||
// Otherwise, warn until the feature's coming-of-age language mode.
|
||||
const auto feature = Feature::ExistentialAny;
|
||||
if (Ctx.LangOpts.getFeatureState(feature).isEnabledForAdoption()) {
|
||||
if (Ctx.LangOpts.getFeatureState(feature).isEnabledForMigration()) {
|
||||
diag->limitBehavior(DiagnosticBehavior::Warning);
|
||||
} else {
|
||||
diag->warnUntilSwiftVersion(feature.getLanguageVersion().value());
|
||||
|
||||
@@ -51,8 +51,8 @@ void swift::PrintTo(const LangOptions::FeatureState::Kind &value,
|
||||
case LangOptions::FeatureState::Kind::Off:
|
||||
*os << "Off";
|
||||
break;
|
||||
case LangOptions::FeatureState::Kind::EnabledForAdoption:
|
||||
*os << "EnabledForAdoption";
|
||||
case LangOptions::FeatureState::Kind::EnabledForMigration:
|
||||
*os << "EnabledForMigration";
|
||||
break;
|
||||
case LangOptions::FeatureState::Kind::Enabled:
|
||||
*os << "Enabled";
|
||||
|
||||
@@ -38,27 +38,27 @@ TEST_F(IsFeatureEnabledTest, VerifyTestedFeatures) {
|
||||
{
|
||||
ASSERT_FALSE(Feature::getUpcomingFeature(feature.name));
|
||||
ASSERT_FALSE(Feature::getExperimentalFeature(feature.name));
|
||||
ASSERT_FALSE(feature.id.isAdoptable());
|
||||
ASSERT_FALSE(feature.id.isMigratable());
|
||||
}
|
||||
|
||||
feature = upcomingF;
|
||||
{
|
||||
ASSERT_TRUE(Feature::getUpcomingFeature(feature.name));
|
||||
ASSERT_FALSE(feature.id.isAdoptable());
|
||||
ASSERT_FALSE(feature.id.isMigratable());
|
||||
ASSERT_LT(defaultLangMode, feature.langMode);
|
||||
}
|
||||
|
||||
feature = adoptableUpcomingF;
|
||||
{
|
||||
ASSERT_TRUE(Feature::getUpcomingFeature(feature.name));
|
||||
ASSERT_TRUE(feature.id.isAdoptable());
|
||||
ASSERT_TRUE(feature.id.isMigratable());
|
||||
ASSERT_LT(defaultLangMode, feature.langMode);
|
||||
}
|
||||
|
||||
feature = strictConcurrencyF;
|
||||
{
|
||||
ASSERT_TRUE(Feature::getUpcomingFeature(feature.name));
|
||||
ASSERT_FALSE(feature.id.isAdoptable());
|
||||
ASSERT_FALSE(feature.id.isMigratable());
|
||||
ASSERT_LT(defaultLangMode, feature.langMode);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ TEST_F(IsFeatureEnabledTest, VerifyTestedFeatures) {
|
||||
// it for another experimental feature one that is available in production.
|
||||
ASSERT_TRUE(feature.id.isAvailableInProduction());
|
||||
ASSERT_TRUE(Feature::getExperimentalFeature(feature.name));
|
||||
ASSERT_FALSE(feature.id.isAdoptable());
|
||||
ASSERT_FALSE(feature.id.isMigratable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ static const IsFeatureEnabledTestCase singleEnableTestCases[] = {
|
||||
{{adoptableUpcomingF, FeatureState::Off}}),
|
||||
IsFeatureEnabledTestCase(
|
||||
{"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption"},
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}),
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
|
||||
// Swift 7 is asserts-only.
|
||||
#ifndef NDEBUG
|
||||
// Requesting adoption mode in target language mode has no effect.
|
||||
@@ -176,7 +176,7 @@ static const IsFeatureEnabledTestCase singleEnableTestCases[] = {
|
||||
{{adoptableUpcomingF, FeatureState::Off}}),
|
||||
IsFeatureEnabledTestCase(
|
||||
{"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption"},
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}),
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
|
||||
// Swift 7 is asserts-only.
|
||||
#ifndef NDEBUG
|
||||
// Requesting adoption mode in target language mode has no effect.
|
||||
@@ -396,7 +396,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
|
||||
"-enable-upcoming-feature", adoptableUpcomingF.name,
|
||||
"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption",
|
||||
},
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}),
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
|
||||
IsFeatureEnabledTestCase({
|
||||
"-enable-upcoming-feature", adoptableUpcomingF.name + ":undef",
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name,
|
||||
@@ -416,7 +416,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
|
||||
"-enable-upcoming-feature", adoptableUpcomingF.name,
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption",
|
||||
},
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}),
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
|
||||
IsFeatureEnabledTestCase({
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name + ":undef",
|
||||
"-enable-upcoming-feature", adoptableUpcomingF.name,
|
||||
@@ -436,7 +436,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name,
|
||||
"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption",
|
||||
},
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}),
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
|
||||
IsFeatureEnabledTestCase({
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name + ":undef",
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name,
|
||||
@@ -456,7 +456,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name,
|
||||
"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption",
|
||||
},
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}),
|
||||
{{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
|
||||
|
||||
// MARK: Experimental
|
||||
|
||||
|
||||
Reference in New Issue
Block a user