[Feature] Rename Feature APIs from adoption to migration

(cherry picked from commit 085078dd8a)
This commit is contained in:
Pavel Yaskevich
2025-04-28 11:02:17 -07:00
parent 4e6071c1f8
commit 61c8e70c66
12 changed files with 44 additions and 44 deletions

View File

@@ -59,9 +59,9 @@ GROUPED_WARNING(cannot_disable_feature_with_mode, StrictLanguageFeatures, none,
"'%0' argument '%1' cannot specify a mode", "'%0' argument '%1' cannot specify a mode",
(StringRef, StringRef)) (StringRef, StringRef))
GROUPED_WARNING(feature_does_not_support_adoption_mode, StrictLanguageFeatures, GROUPED_WARNING(feature_does_not_support_migration_mode, StrictLanguageFeatures,
none, none,
"feature '%0' does not support adoption mode", "feature '%0' does not support migration mode",
(StringRef)) (StringRef))
ERROR(error_unknown_library_level, none, ERROR(error_unknown_library_level, none,

View File

@@ -57,8 +57,8 @@ struct Feature {
/// Determine the in-source name of the given feature. /// Determine the in-source name of the given feature.
llvm::StringRef getName() const; llvm::StringRef getName() const;
/// Determine whether the given feature supports adoption mode. /// Determine whether the given feature supports migration mode.
bool isAdoptable() const; bool isMigratable() const;
/// Determine whether this feature should be included in the /// Determine whether this feature should be included in the
/// module interface /// module interface

View File

@@ -830,7 +830,7 @@ namespace swift {
/// A wrapper around the feature state enumeration. /// A wrapper around the feature state enumeration.
struct FeatureState { struct FeatureState {
enum class Kind : uint8_t { Off, EnabledForAdoption, Enabled }; enum class Kind : uint8_t { Off, EnabledForMigration, Enabled };
private: private:
Feature feature; Feature feature;
@@ -843,9 +843,9 @@ namespace swift {
/// Returns whether the feature is enabled. /// Returns whether the feature is enabled.
bool isEnabled() const; 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. /// be called if the feature is known to support this mode.
bool isEnabledForAdoption() const; bool isEnabledForMigration() const;
operator Kind() const { return state; } operator Kind() const { return state; }
}; };
@@ -878,9 +878,9 @@ namespace swift {
/// `false` if a feature by this name is not known. /// `false` if a feature by this name is not known.
bool hasFeature(llvm::StringRef featureName) const; bool hasFeature(llvm::StringRef featureName) const;
/// Enables the given feature (enables in adoption mode if `forAdoption` is /// Enables the given feature (enables in migration mode if `forMigration`
/// `true`). /// is `true`).
void enableFeature(Feature feature, bool forAdoption = false); void enableFeature(Feature feature, bool forMigration = false);
/// Disables the given feature. /// Disables the given feature.
void disableFeature(Feature feature); void disableFeature(Feature feature);

View File

@@ -69,7 +69,7 @@ std::optional<unsigned> Feature::getLanguageVersion() const {
} }
} }
bool Feature::isAdoptable() const { bool Feature::isMigratable() const {
switch (kind) { switch (kind) {
#define MIGRATABLE_UPCOMING_FEATURE(FeatureName, SENumber, Version) #define MIGRATABLE_UPCOMING_FEATURE(FeatureName, SENumber, Version)
#define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) #define MIGRATABLE_EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)

View File

@@ -298,10 +298,10 @@ bool LangOptions::FeatureState::isEnabled() const {
return state == FeatureState::Kind::Enabled; return state == FeatureState::Kind::Enabled;
} }
bool LangOptions::FeatureState::isEnabledForAdoption() const { bool LangOptions::FeatureState::isEnabledForMigration() const {
ASSERT(feature.isAdoptable() && "You forgot to make the feature adoptable!"); ASSERT(feature.isMigratable() && "You forgot to make the feature migratable!");
return state == FeatureState::Kind::EnabledForAdoption; return state == FeatureState::Kind::EnabledForMigration;
} }
LangOptions::FeatureStateStorage::FeatureStateStorage() LangOptions::FeatureStateStorage::FeatureStateStorage()
@@ -357,10 +357,10 @@ bool LangOptions::hasFeature(llvm::StringRef featureName) const {
return false; return false;
} }
void LangOptions::enableFeature(Feature feature, bool forAdoption) { void LangOptions::enableFeature(Feature feature, bool forMigration) {
if (forAdoption) { if (forMigration) {
ASSERT(feature.isAdoptable()); ASSERT(feature.isMigratable());
featureStates.setState(feature, FeatureState::Kind::EnabledForAdoption); featureStates.setState(feature, FeatureState::Kind::EnabledForMigration);
return; return;
} }

View File

@@ -48,7 +48,7 @@ void printSupportedFeatures(llvm::raw_ostream &out) {
auto printFeature = [&out](const Feature &feature) { auto printFeature = [&out](const Feature &feature) {
out << " "; out << " ";
out << "{ \"name\": \"" << feature.getName() << "\""; out << "{ \"name\": \"" << feature.getName() << "\"";
if (feature.isAdoptable()) { if (feature.isMigratable()) {
out << ", \"migratable\": true"; out << ", \"migratable\": true";
} }
if (auto version = feature.getLanguageVersion()) { if (auto version = feature.getLanguageVersion()) {

View File

@@ -872,7 +872,7 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
if (featureMode) { if (featureMode) {
if (isEnableFeatureFlag) { if (isEnableFeatureFlag) {
const auto isAdoptable = feature->isAdoptable(); const auto isMigratable = feature->isMigratable();
// Diagnose an invalid mode. // Diagnose an invalid mode.
StringRef validModeName = "adoption"; StringRef validModeName = "adoption";
@@ -880,13 +880,13 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
Diags.diagnose(SourceLoc(), diag::invalid_feature_mode, *featureMode, Diags.diagnose(SourceLoc(), diag::invalid_feature_mode, *featureMode,
featureName, featureName,
/*didYouMean=*/validModeName, /*didYouMean=*/validModeName,
/*showDidYouMean=*/isAdoptable); /*showDidYouMean=*/isMigratable);
continue; continue;
} }
if (!isAdoptable) { if (!isMigratable) {
Diags.diagnose(SourceLoc(), Diags.diagnose(SourceLoc(),
diag::feature_does_not_support_adoption_mode, diag::feature_does_not_support_migration_mode,
featureName); featureName);
continue; continue;
} }
@@ -904,7 +904,7 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
// Enable the feature if requested. // Enable the feature if requested.
if (isEnableFeatureFlag) 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 // Since pseudo-features don't have a boolean on/off state, process them in

View File

@@ -60,7 +60,7 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
const auto feature = Feature::NonisolatedNonsendingByDefault; const auto feature = Feature::NonisolatedNonsendingByDefault;
ASSERT(node); ASSERT(node);
ASSERT(ctx.LangOpts.getFeatureState(feature).isEnabledForAdoption()); ASSERT(ctx.LangOpts.getFeatureState(feature).isEnabledForMigration());
ValueDecl *decl = nullptr; ValueDecl *decl = nullptr;
ClosureExpr *closure = nullptr; ClosureExpr *closure = nullptr;

View File

@@ -4810,7 +4810,7 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
isolation = isolation.withPreconcurrency(preconcurrency); isolation = isolation.withPreconcurrency(preconcurrency);
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault) if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
.isEnabledForAdoption()) { .isEnabledForMigration()) {
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, closure, isolation); warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, closure, isolation);
} }
@@ -6296,7 +6296,7 @@ InferredActorIsolation ActorIsolationRequest::evaluate(Evaluator &evaluator,
auto &ctx = value->getASTContext(); auto &ctx = value->getASTContext();
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault) if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
.isEnabledForAdoption()) { .isEnabledForMigration()) {
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, value, warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, value,
inferredIsolation.isolation); inferredIsolation.isolation);
} }

View File

@@ -4252,7 +4252,7 @@ NeverNullType TypeResolver::resolveASTFunctionType(
isolation = FunctionTypeIsolation::forNonIsolated(); isolation = FunctionTypeIsolation::forNonIsolated();
} else { } else {
if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault) if (ctx.LangOpts.getFeatureState(Feature::NonisolatedNonsendingByDefault)
.isEnabledForAdoption()) { .isEnabledForMigration()) {
// Diagnose only in the interface stage, which is run once. // Diagnose only in the interface stage, which is run once.
if (inStage(TypeResolutionStage::Interface)) { if (inStage(TypeResolutionStage::Interface)) {
warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, repr, isolation); warnAboutNewNonisolatedAsyncExecutionBehavior(ctx, repr, isolation);
@@ -6578,7 +6578,7 @@ private:
// A missing `any` or `some` is always diagnosed if this feature not // A missing `any` or `some` is always diagnosed if this feature not
// disabled. // disabled.
auto featureState = ctx.LangOpts.getFeatureState(Feature::ExistentialAny); auto featureState = ctx.LangOpts.getFeatureState(Feature::ExistentialAny);
if (featureState.isEnabled() || featureState.isEnabledForAdoption()) { if (featureState.isEnabled() || featureState.isEnabledForMigration()) {
return true; return true;
} }
@@ -6671,10 +6671,10 @@ private:
/*isAlias=*/isa<TypeAliasDecl>(decl))); /*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. // Otherwise, warn until the feature's coming-of-age language mode.
const auto feature = Feature::ExistentialAny; const auto feature = Feature::ExistentialAny;
if (Ctx.LangOpts.getFeatureState(feature).isEnabledForAdoption()) { if (Ctx.LangOpts.getFeatureState(feature).isEnabledForMigration()) {
diag->limitBehavior(DiagnosticBehavior::Warning); diag->limitBehavior(DiagnosticBehavior::Warning);
} else { } else {
diag->warnUntilSwiftVersion(feature.getLanguageVersion().value()); diag->warnUntilSwiftVersion(feature.getLanguageVersion().value());

View File

@@ -51,8 +51,8 @@ void swift::PrintTo(const LangOptions::FeatureState::Kind &value,
case LangOptions::FeatureState::Kind::Off: case LangOptions::FeatureState::Kind::Off:
*os << "Off"; *os << "Off";
break; break;
case LangOptions::FeatureState::Kind::EnabledForAdoption: case LangOptions::FeatureState::Kind::EnabledForMigration:
*os << "EnabledForAdoption"; *os << "EnabledForMigration";
break; break;
case LangOptions::FeatureState::Kind::Enabled: case LangOptions::FeatureState::Kind::Enabled:
*os << "Enabled"; *os << "Enabled";

View File

@@ -38,27 +38,27 @@ TEST_F(IsFeatureEnabledTest, VerifyTestedFeatures) {
{ {
ASSERT_FALSE(Feature::getUpcomingFeature(feature.name)); ASSERT_FALSE(Feature::getUpcomingFeature(feature.name));
ASSERT_FALSE(Feature::getExperimentalFeature(feature.name)); ASSERT_FALSE(Feature::getExperimentalFeature(feature.name));
ASSERT_FALSE(feature.id.isAdoptable()); ASSERT_FALSE(feature.id.isMigratable());
} }
feature = upcomingF; feature = upcomingF;
{ {
ASSERT_TRUE(Feature::getUpcomingFeature(feature.name)); ASSERT_TRUE(Feature::getUpcomingFeature(feature.name));
ASSERT_FALSE(feature.id.isAdoptable()); ASSERT_FALSE(feature.id.isMigratable());
ASSERT_LT(defaultLangMode, feature.langMode); ASSERT_LT(defaultLangMode, feature.langMode);
} }
feature = adoptableUpcomingF; feature = adoptableUpcomingF;
{ {
ASSERT_TRUE(Feature::getUpcomingFeature(feature.name)); ASSERT_TRUE(Feature::getUpcomingFeature(feature.name));
ASSERT_TRUE(feature.id.isAdoptable()); ASSERT_TRUE(feature.id.isMigratable());
ASSERT_LT(defaultLangMode, feature.langMode); ASSERT_LT(defaultLangMode, feature.langMode);
} }
feature = strictConcurrencyF; feature = strictConcurrencyF;
{ {
ASSERT_TRUE(Feature::getUpcomingFeature(feature.name)); ASSERT_TRUE(Feature::getUpcomingFeature(feature.name));
ASSERT_FALSE(feature.id.isAdoptable()); ASSERT_FALSE(feature.id.isMigratable());
ASSERT_LT(defaultLangMode, feature.langMode); ASSERT_LT(defaultLangMode, feature.langMode);
} }
@@ -68,7 +68,7 @@ TEST_F(IsFeatureEnabledTest, VerifyTestedFeatures) {
// it for another experimental feature one that is available in production. // it for another experimental feature one that is available in production.
ASSERT_TRUE(feature.id.isAvailableInProduction()); ASSERT_TRUE(feature.id.isAvailableInProduction());
ASSERT_TRUE(Feature::getExperimentalFeature(feature.name)); 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}}), {{adoptableUpcomingF, FeatureState::Off}}),
IsFeatureEnabledTestCase( IsFeatureEnabledTestCase(
{"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption"}, {"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption"},
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}), {{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
// Swift 7 is asserts-only. // Swift 7 is asserts-only.
#ifndef NDEBUG #ifndef NDEBUG
// Requesting adoption mode in target language mode has no effect. // Requesting adoption mode in target language mode has no effect.
@@ -176,7 +176,7 @@ static const IsFeatureEnabledTestCase singleEnableTestCases[] = {
{{adoptableUpcomingF, FeatureState::Off}}), {{adoptableUpcomingF, FeatureState::Off}}),
IsFeatureEnabledTestCase( IsFeatureEnabledTestCase(
{"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption"}, {"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption"},
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}), {{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
// Swift 7 is asserts-only. // Swift 7 is asserts-only.
#ifndef NDEBUG #ifndef NDEBUG
// Requesting adoption mode in target language mode has no effect. // 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,
"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption", "-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption",
}, },
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}), {{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
IsFeatureEnabledTestCase({ IsFeatureEnabledTestCase({
"-enable-upcoming-feature", adoptableUpcomingF.name + ":undef", "-enable-upcoming-feature", adoptableUpcomingF.name + ":undef",
"-enable-experimental-feature", adoptableUpcomingF.name, "-enable-experimental-feature", adoptableUpcomingF.name,
@@ -416,7 +416,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
"-enable-upcoming-feature", adoptableUpcomingF.name, "-enable-upcoming-feature", adoptableUpcomingF.name,
"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption", "-enable-experimental-feature", adoptableUpcomingF.name + ":adoption",
}, },
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}), {{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
IsFeatureEnabledTestCase({ IsFeatureEnabledTestCase({
"-enable-experimental-feature", adoptableUpcomingF.name + ":undef", "-enable-experimental-feature", adoptableUpcomingF.name + ":undef",
"-enable-upcoming-feature", adoptableUpcomingF.name, "-enable-upcoming-feature", adoptableUpcomingF.name,
@@ -436,7 +436,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
"-enable-experimental-feature", adoptableUpcomingF.name, "-enable-experimental-feature", adoptableUpcomingF.name,
"-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption", "-enable-upcoming-feature", adoptableUpcomingF.name + ":adoption",
}, },
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}), {{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
IsFeatureEnabledTestCase({ IsFeatureEnabledTestCase({
"-enable-experimental-feature", adoptableUpcomingF.name + ":undef", "-enable-experimental-feature", adoptableUpcomingF.name + ":undef",
"-enable-experimental-feature", adoptableUpcomingF.name, "-enable-experimental-feature", adoptableUpcomingF.name,
@@ -456,7 +456,7 @@ static const IsFeatureEnabledTestCase doubleEnableTestCases[] = {
"-enable-experimental-feature", adoptableUpcomingF.name, "-enable-experimental-feature", adoptableUpcomingF.name,
"-enable-experimental-feature", adoptableUpcomingF.name + ":adoption", "-enable-experimental-feature", adoptableUpcomingF.name + ":adoption",
}, },
{{adoptableUpcomingF, FeatureState::EnabledForAdoption}}), {{adoptableUpcomingF, FeatureState::EnabledForMigration}}),
// MARK: Experimental // MARK: Experimental