AST/Sema: Make MemberImportVisibility a migratable feature.

The migration to `MemberImportVisibility` can be performed mechanically by
adding missing import declarations, so offer automatic migration for the
feature.

Resolves rdar://151931597.
This commit is contained in:
Allan Shortlidge
2025-05-23 11:39:18 -07:00
parent 0d6a8c8c43
commit c99b19e450
15 changed files with 310 additions and 30 deletions

View File

@@ -49,6 +49,7 @@ GROUP(ErrorInFutureSwiftVersion, "error-in-future-swift-version")
GROUP(ExistentialAny, "existential-any")
GROUP(ExistentialMemberAccess, "existential-member-access-limitations")
GROUP(IsolatedConformances, "isolated-conformances")
GROUP(MemberImportVisibility, "member-import-visibility")
GROUP(MultipleInheritance, "multiple-inheritance")
GROUP(MutableGlobalVariable, "mutable-global-variable")
GROUP(NominalTypes, "nominal-types")

View File

@@ -165,16 +165,21 @@ ERROR(init_candidate_inaccessible,none,
"'%select{private|fileprivate|internal|package|@_spi|@_spi}1' protection level",
(Type, AccessLevel))
ERROR(candidate_from_missing_import,none,
GROUPED_ERROR(member_from_missing_import,MemberImportVisibility,none,
"%kind0 is not available due to missing import of defining module %1",
(const ValueDecl *, const ModuleDecl *))
ERROR(candidate_from_missing_imports_2_or_more,none,
GROUPED_ERROR(member_from_missing_imports_2_or_more,MemberImportVisibility,none,
"%kind0 is not available due to missing imports of defining modules "
"%2%select{ and|, }1 %3%select{|, and others}1",
(const ValueDecl *, bool, const ModuleDecl *, const ModuleDecl *))
NOTE(candidate_add_import,none,
"add import of module %0", (const ModuleDecl *))
GROUPED_WARNING(add_required_import_for_member,MemberImportVisibility,none,
"import of module %0 is required", (const ModuleDecl *))
NOTE(decl_from_module_used_here,none,
"%kind0 from %1 used here", (const ValueDecl *, const ModuleDecl *))
ERROR(cannot_pass_rvalue_mutating_subelement,none,
"cannot use mutating member on immutable value: %0",
(StringRef))

View File

@@ -287,7 +287,7 @@ UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
// Swift 7
MIGRATABLE_UPCOMING_FEATURE(ExistentialAny, 335, 7)
UPCOMING_FEATURE(InternalImportsByDefault, 409, 7)
UPCOMING_FEATURE(MemberImportVisibility, 444, 7)
MIGRATABLE_UPCOMING_FEATURE(MemberImportVisibility, 444, 7)
MIGRATABLE_UPCOMING_FEATURE(InferIsolatedConformances, 470, 7)
MIGRATABLE_UPCOMING_FEATURE(NonisolatedNonsendingByDefault, 461, 7)

View File

@@ -873,13 +873,17 @@ namespace swift {
/// Returns whether the given feature is enabled.
///
/// If allowMigration is set, also returns true when the feature has been enabled for migration.
/// If allowMigration is set, also returns true when the feature has been
/// enabled for migration.
bool hasFeature(Feature feature, bool allowMigration = false) const;
/// Returns whether a feature with the given name is enabled. Returns
/// `false` if a feature by this name is not known.
bool hasFeature(llvm::StringRef featureName) const;
/// Returns whether the given feature is enabled for migration.
bool isMigratingToFeature(Feature feature) const;
/// Enables the given feature (enables in migration mode if `forMigration`
/// is `true`).
void enableFeature(Feature feature, bool forMigration = false);