diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 4672bbfbd1112..e723ad8368716 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -2900,17 +2900,14 @@ ERROR(decl_from_hidden_module,none, "in an extension with conditional conformances}2; " "%select{%3 has been imported as implementation-only|" "it is an SPI imported from %3|" - "it is SPI|" - "%3 was not imported by this file}4", + "it is SPI}4", (DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned)) WARNING(decl_from_hidden_module_warn,none, - "cannot use %0 %1 %select{here|as property wrapper here|" - "as result builder here|" + "cannot use %0 %1 %select{in SPI|as property wrapper in SPI|" + "as result builder in SPI|" "in an extension with public or '@usableFromInline' members|" "in an extension with conditional conformances}2; " - "%select{%3 has been imported as implementation-only|" - "<>|<>|" - "%3 was not imported by this file}4", + "%select{%3 has been imported as implementation-only}4", (DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned)) ERROR(conformance_from_implementation_only_module,none, "cannot use conformance of %0 to %1 %select{here|as property wrapper here|" @@ -5785,15 +5782,7 @@ ERROR(inlinable_decl_ref_from_hidden_module, none, "%0 %1 cannot be used in " FRAGILE_FUNC_KIND "2 " "because %select{%3 was imported implementation-only|" "it is an SPI imported from %3|" - "it is SPI|" - "%3 was not imported by this file}4", - (DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned)) - -WARNING(inlinable_decl_ref_from_hidden_module_warn, - none, "%0 %1 cannot be used in " FRAGILE_FUNC_KIND "2 " - "because %select{<>|<>|<>|" - "%3 was not imported by this file}4" - "; this is an error in Swift 6", + "it is SPI}4", (DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned)) ERROR(availability_macro_in_inlinable, none, diff --git a/include/swift/AST/SourceFile.h b/include/swift/AST/SourceFile.h index 3133f3dde7d60..9e73ca4a65b5a 100644 --- a/include/swift/AST/SourceFile.h +++ b/include/swift/AST/SourceFile.h @@ -31,7 +31,6 @@ class PersistentParserState; /// \sa getRestrictedImportKind enum class RestrictedImportKind { ImplementationOnly, - Implicit, None // No restriction, i.e. the module is imported publicly. }; diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 46f2ee3ed6bc5..5b2b0563a2ee5 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -2442,18 +2442,14 @@ bool SourceFile::hasTestableOrPrivateImport( RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *module) const { auto &imports = getASTContext().getImportCache(); - RestrictedImportKind importKind = RestrictedImportKind::Implicit; // Look at the imports of this source file. for (auto &desc : *Imports) { // Ignore implementation-only imports. - if (desc.options.contains(ImportFlags::ImplementationOnly)) { - if (imports.isImportedBy(module, desc.module.importedModule)) - importKind = RestrictedImportKind::ImplementationOnly; + if (desc.options.contains(ImportFlags::ImplementationOnly)) continue; - } - // If the module is imported publicly, it's not imported + // If the module is imported this way, it's not imported // implementation-only. if (imports.isImportedBy(module, desc.module.importedModule)) return RestrictedImportKind::None; @@ -2463,7 +2459,7 @@ RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *modul if (imports.isImportedBy(module, getParentModule())) return RestrictedImportKind::None; - return importKind; + return RestrictedImportKind::ImplementationOnly; } bool ModuleDecl::isImportedImplementationOnly(const ModuleDecl *module) const { diff --git a/lib/Sema/ResilienceDiagnostics.cpp b/lib/Sema/ResilienceDiagnostics.cpp index 48fae1829aba6..80dbe4fc63ddc 100644 --- a/lib/Sema/ResilienceDiagnostics.cpp +++ b/lib/Sema/ResilienceDiagnostics.cpp @@ -146,16 +146,7 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc, D->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type); } else { - // Only implicitly imported decls should be reported as a warning, - // and only for language versions below Swift 6. - assert(downgradeToWarning == DowngradeToWarning::No || - originKind == DisallowedOriginKind::ImplicitlyImported && - "Only implicitly imported decls should be reported as a warning."); - auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes? - diag::inlinable_decl_ref_from_hidden_module_warn: - diag::inlinable_decl_ref_from_hidden_module; - - ctx.Diags.diagnose(loc, errorOrWarning, + ctx.Diags.diagnose(loc, diag::inlinable_decl_ref_from_hidden_module, D->getDescriptiveKind(), D->getName(), fragileKind.getSelector(), definingModule->getName(), static_cast(originKind)); diff --git a/lib/Sema/TypeCheckAccess.cpp b/lib/Sema/TypeCheckAccess.cpp index f3595e5822764..cf072d1fa328f 100644 --- a/lib/Sema/TypeCheckAccess.cpp +++ b/lib/Sema/TypeCheckAccess.cpp @@ -1511,15 +1511,6 @@ swift::getDisallowedOriginKind(const Decl *decl, if (where.isSPI()) downgradeToWarning = DowngradeToWarning::Yes; - // Before Swift 6, implicit imports were not reported unless an - // implementation-only import was also present. Downgrade to a warning - // just in this case. - if (howImported == RestrictedImportKind::Implicit && - !SF->getASTContext().isSwiftVersionAtLeast(6) && - !SF->hasImplementationOnlyImports()) { - downgradeToWarning = DowngradeToWarning::Yes; - } - // Even if the current module is @_implementationOnly, Swift should // not report an error in the cases where the decl is also exported from // a non @_implementationOnly module. Thus, we check to see if there is @@ -1540,12 +1531,9 @@ swift::getDisallowedOriginKind(const Decl *decl, continue; } } - auto owningModule = redecl->getOwningModule(); - if (!owningModule) - continue; auto moduleWrapper = decl->getASTContext().getClangModuleLoader()->getWrapperForModule( - owningModule); + redecl->getOwningModule()); auto visibleAccessPath = find_if(sfImportedModules, [&moduleWrapper](auto importedModule) { return importedModule.importedModule == moduleWrapper || @@ -1557,10 +1545,7 @@ swift::getDisallowedOriginKind(const Decl *decl, } } } - - // Restrictively imported, cannot be reexported. - if (howImported == RestrictedImportKind::Implicit) - return DisallowedOriginKind::ImplicitlyImported; + // Implementation-only imported, cannot be reexported. return DisallowedOriginKind::ImplementationOnly; } else if ((decl->isSPI() || decl->isAvailableAsSPI()) && !where.isSPI()) { if (decl->isAvailableAsSPI() && !decl->isSPI()) { diff --git a/lib/Sema/TypeCheckAccess.h b/lib/Sema/TypeCheckAccess.h index a18d15d1db88d..d5ff2e97d7e62 100644 --- a/lib/Sema/TypeCheckAccess.h +++ b/lib/Sema/TypeCheckAccess.h @@ -35,14 +35,12 @@ void checkAccessControl(Decl *D); // Problematic origin of an exported type. // // This enum must be kept in sync with -// diag::inlinable_decl_ref_from_hidden_module, // diag::decl_from_hidden_module and // diag::conformance_from_implementation_only_module. enum class DisallowedOriginKind : uint8_t { ImplementationOnly, SPIImported, SPILocal, - ImplicitlyImported, None }; diff --git a/stdlib/public/Cxx/std/std.swift b/stdlib/public/Cxx/std/std.swift index 76031ff9451d5..ceb0dda952c29 100644 --- a/stdlib/public/Cxx/std/std.swift +++ b/stdlib/public/Cxx/std/std.swift @@ -12,3 +12,5 @@ @_exported import std // Clang module @_exported import Cxx // Swift module + +public var dummy: Int = 1 diff --git a/test/SPI/implementation_only_spi_import_exposability.swift b/test/SPI/implementation_only_spi_import_exposability.swift index fbdeab72aa3ff..c9e37b82d3a87 100644 --- a/test/SPI/implementation_only_spi_import_exposability.swift +++ b/test/SPI/implementation_only_spi_import_exposability.swift @@ -26,8 +26,8 @@ public protocol IOIProtocol {} @_spi(A) @_implementationOnly import Lib -@_spi(B) public func leakSPIStruct(_ a: SPIStruct) -> SPIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'SPIStruct' here; 'Lib' has been imported as implementation-only}} -@_spi(B) public func leakIOIStruct(_ a: IOIStruct) -> IOIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'IOIStruct' here; 'Lib' has been imported as implementation-only}} +@_spi(B) public func leakSPIStruct(_ a: SPIStruct) -> SPIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'SPIStruct' in SPI; 'Lib' has been imported as implementation-only}} +@_spi(B) public func leakIOIStruct(_ a: IOIStruct) -> IOIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'IOIStruct' in SPI; 'Lib' has been imported as implementation-only}} public struct PublicStruct : IOIProtocol, SPIProtocol { // expected-error {{cannot use protocol 'IOIProtocol' here; 'Lib' has been imported as implementation-only}} // expected-error @-1 {{cannot use protocol 'SPIProtocol' here; 'Lib' has been imported as implementation-only}} @@ -46,8 +46,8 @@ public struct PublicStruct : IOIProtocol, SPIProtocol { // expected-error {{cann } @_spi(B) -public struct LocalSPIStruct : IOIProtocol, SPIProtocol { // expected-warning {{cannot use protocol 'IOIProtocol' here; 'Lib' has been imported as implementation-only}} -// expected-warning @-1 {{cannot use protocol 'SPIProtocol' here; 'Lib' has been imported as implementation-only}} +public struct LocalSPIStruct : IOIProtocol, SPIProtocol { // expected-warning {{cannot use protocol 'IOIProtocol' in SPI; 'Lib' has been imported as implementation-only}} +// expected-warning @-1 {{cannot use protocol 'SPIProtocol' in SPI; 'Lib' has been imported as implementation-only}} } #endif diff --git a/test/Sema/implicit-import-in-inlinable-code.swift b/test/Sema/implicit-import-in-inlinable-code.swift deleted file mode 100644 index 68ef40c0a6e9e..0000000000000 --- a/test/Sema/implicit-import-in-inlinable-code.swift +++ /dev/null @@ -1,76 +0,0 @@ -/// Report the use in API of indirectly or implicitly imported decls. - -// RUN: %empty-directory(%t) -// RUN: %{python} %utils/split_file.py -o %t %s - -// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name empty -o %t/empty.swiftmodule -// RUN: %target-swift-frontend -emit-module %t/libA.swift -module-name libA -o %t/libA.swiftmodule -// RUN: %target-swift-frontend -emit-module %t/libB.swift -module-name libB -o %t/libB.swiftmodule -I %t - -/// In pre-Swift 6, this is a warning where there's no implementation-only import present. -// RUN: %target-swift-frontend -emit-module %t/clientFileA-Swift5.swift %t/clientFileB.swift -module-name client -o %t/client.swiftmodule -I %t -verify - -/// In pre-Swift 6, this remains an error when there's an implementation-only import present. -// RUN: %target-swift-frontend -emit-module %t/clientFileA-OldCheck.swift %t/clientFileB.swift -module-name client -o %t/client.swiftmodule -I %t -verify - -/// In Swift 6, it's an error. -// RUN: %target-swift-frontend -emit-module %t/clientFileA-Swift6.swift %t/clientFileB.swift -module-name client -o %t/client.swiftmodule -I %t -verify -swift-version 6 - -// REQUIRES: asserts - -// BEGIN empty.swift - -// BEGIN libA.swift -public struct ImportedType { - public init() {} -} - -// BEGIN libB.swift -import libA - -extension ImportedType { - public func implicitlyImportedMethod() {} -} - -/// Client module -// BEGIN clientFileA-Swift5.swift -import libA - -@inlinable public func bar() { - let a = ImportedType() - a.implicitlyImportedMethod() // expected-warning {{instance method 'implicitlyImportedMethod()' cannot be used in an '@inlinable' function because 'libB' was not imported by this file; this is an error in Swift 6}} - - // Expected implicit imports are still fine - a.localModuleMethod() -} - -// BEGIN clientFileA-OldCheck.swift -import libA -@_implementationOnly import empty - -@inlinable public func bar() { - let a = ImportedType() - a.implicitlyImportedMethod() // expected-error {{instance method 'implicitlyImportedMethod()' cannot be used in an '@inlinable' function because 'libB' was not imported by this file}} - - // Expected implicit imports are still fine - a.localModuleMethod() -} - -// BEGIN clientFileA-Swift6.swift -import libA - -@inlinable public func bar() { - let a = ImportedType() - a.implicitlyImportedMethod() // expected-error {{instance method 'implicitlyImportedMethod()' cannot be used in an '@inlinable' function because 'libB' was not imported by this file}} - - // Expected implicit imports are still fine - a.localModuleMethod() -} - -// BEGIN clientFileB.swift -@_implementationOnly import libB -import libA -extension ImportedType { - public func localModuleMethod() {} -} -