Sema: Simplify warning about @_implementationOnly being deprecated

This commit is contained in:
Alexis Laferrière
2024-04-22 13:03:55 -07:00
parent 0a25248e4b
commit 3d611e2a85
17 changed files with 30 additions and 43 deletions

View File

@@ -1167,13 +1167,8 @@ WARNING(implementation_only_requires_library_evolution,none,
"using '@_implementationOnly' without enabling library evolution "
"for %0 may lead to instability during execution",
(Identifier))
WARNING(implementation_only_deprecated_explicit,none,
"'@_implementationOnly' is deprecated, use 'internal import' "
"and family instead",
())
WARNING(implementation_only_deprecated_implicit,none,
"'@_implementationOnly' is deprecated, use a bare import "
"as 'InternalImportsByDefault' is enabled",
WARNING(implementation_only_deprecated,none,
"'@_implementationOnly' is deprecated, use 'internal import' instead",
())
ERROR(module_allowable_client_violation,none,

View File

@@ -816,17 +816,10 @@ void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
import.implementationOnlyRange.isValid()) {
if (SF.getParentModule()->isResilient()) {
// Encourage replacing `@_implementationOnly` with `internal import`.
if (ctx.LangOpts.hasFeature(Feature::InternalImportsByDefault)) {
auto inFlight =
ctx.Diags.diagnose(import.importLoc,
diag::implementation_only_deprecated_implicit);
inFlight.fixItRemove(import.implementationOnlyRange);
} else {
auto inFlight =
ctx.Diags.diagnose(import.importLoc,
diag::implementation_only_deprecated_explicit);
inFlight.fixItReplace(import.implementationOnlyRange, "internal");
}
auto inFlight =
ctx.Diags.diagnose(import.importLoc,
diag::implementation_only_deprecated);
inFlight.fixItReplace(import.implementationOnlyRange, "internal");
} else if ( // Non-resilient
!(((targetName.str() == "CCryptoBoringSSL" ||
targetName.str() == "CCryptoBoringSSLShims") &&

View File

@@ -11,7 +11,7 @@
// REQUIRES: asserts
@_implementationOnly import ImplementationOnlyDefs
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
class D: C {
@_implementationOnly

View File

@@ -27,7 +27,7 @@ public protocol IOIProtocol {}
#elseif CLIENT
@_spi(A) @_implementationOnly import Lib
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@_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}}

View File

@@ -26,7 +26,7 @@ public struct IOIStruct {
//--- ClientSPIOnlyMode.swift
@_implementationOnly import Lib
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@_spi(X) public func spiClient(s: IOIStruct) -> IOIStruct { // expected-error 2 {{cannot use struct 'IOIStruct' here; 'Lib' has been imported as implementation-only}}
return IOIStruct()
@@ -40,7 +40,7 @@ public struct IOIStruct {
//--- ClientDefaultMode.swift
@_implementationOnly import Lib
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@_spi(X) public func spiClient(s: IOIStruct) -> IOIStruct { // expected-warning 2 {{cannot use struct 'IOIStruct' here; 'Lib' has been imported as implementation-only}}
return IOIStruct()

View File

@@ -60,7 +60,7 @@ import Lib // expected-error {{'Lib' inconsistently imported for SPI only}}
// expected-warning @-1 {{'Lib' inconsistently imported as implementation-only}}
@_implementationOnly import Lib // expected-error {{'Lib' inconsistently imported for SPI only}}
// expected-note @-1 {{imported as implementation-only here}}
// expected-warning @-2 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-2 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
/// Many confliciting imports lead to many diagnostics.
//--- SPIOnly_IOI_Exported_Default.swift
@@ -68,7 +68,7 @@ import Lib // expected-error {{'Lib' inconsistently imported for SPI only}}
// expected-warning @-1 {{'Lib' inconsistently imported as implementation-only}}
@_implementationOnly import Lib // expected-error {{'Lib' inconsistently imported for SPI only}}
// expected-note @-1 3 {{imported as implementation-only here}}
// expected-warning @-2 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-2 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@_exported import Lib // expected-error {{'Lib' inconsistently imported for SPI only}}
// expected-warning @-1 {{'Lib' inconsistently imported as implementation-only}}
import Lib // expected-error {{'Lib' inconsistently imported for SPI only}}
@@ -84,7 +84,7 @@ import Lib
/// Different IOI in different files of the same module are still rejected.
//--- IOI_Default_FileA.swift
@_implementationOnly import Lib // expected-note {{imported as implementation-only here}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
//--- IOI_Default_FileB.swift
import Lib // expected-warning {{'Lib' inconsistently imported as implementation-only}}

View File

@@ -6,18 +6,17 @@
// RUN: -emit-module-path %t/Lib.swiftmodule
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -verify -verify-additional-prefix swift-5-
// RUN: -verify
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-upcoming-feature InternalImportsByDefault \
// RUN: -verify -verify-additional-prefix default-to-internal-
// RUN: -verify
//--- Lib.swift
public struct SomeType {}
//--- Client.swift
@_implementationOnly import Lib
// expected-swift-5-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}} {{1-21=internal}}
// expected-default-to-internal-warning @-2 {{'@_implementationOnly' is deprecated, use a bare import as 'InternalImportsByDefault' is enabled}} {{1-22=}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}} {{1-21=internal}}
internal func foo(_: SomeType) {}

View File

@@ -27,7 +27,7 @@ import B
//--- client-resilient.swift
@_implementationOnly import A
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
import B
//--- Crypto.swift

View File

@@ -9,7 +9,7 @@
import NormalLibrary
@_implementationOnly import BADLibrary
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
public struct TestConformance: BadProto {} // expected-error {{cannot use protocol 'BadProto' here; 'BADLibrary' has been imported as implementation-only}}

View File

@@ -7,7 +7,7 @@
// RUN: %target-typecheck-verify-swift -I %t -enable-library-evolution -swift-version 5
@_implementationOnly import BADLibrary
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
import NormalLibrary
@available(*, unavailable)

View File

@@ -8,7 +8,7 @@
// RUN: -enable-library-evolution -swift-version 5
@_implementationOnly import directs
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
// Types

View File

@@ -8,7 +8,7 @@
// RUN: -enable-library-evolution -swift-version 5
@_implementationOnly import directs
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
// 'indirects' is imported for re-export in a secondary file
// Types

View File

@@ -8,7 +8,7 @@
// RUN: -enable-library-evolution -swift-version 5
@_implementationOnly import directs
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
import indirects
// Types

View File

@@ -5,7 +5,7 @@
// RUN: %target-typecheck-verify-swift -I %t -enable-library-evolution
@_implementationOnly import BADLibrary
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
public struct PublicStructStoredProperties {
public var publiclyBad: BadStruct? // expected-error {{cannot use struct 'BadStruct' here; 'BADLibrary' has been imported as implementation-only}}

View File

@@ -75,7 +75,7 @@ public import libA
// BEGIN clientFileA-OldCheck.swift
public import libA
@_implementationOnly import empty
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@inlinable public func bar() {
let a = ImportedType()
@@ -103,7 +103,7 @@ public import libA
// BEGIN clientFileB.swift
@_implementationOnly import libB
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
public import libA
extension ImportedType {
public func localModuleMethod() {}

View File

@@ -97,7 +97,7 @@ extension StructAlias {
import Aliases
@_implementationOnly import Original
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@inlinable public func inlinableFunc() {
// expected-warning@+1 {{'StructAlias' aliases 'Original.Struct' and cannot be used in an '@inlinable' function because 'Original' has been imported as implementation-only; this is an error in the Swift 6 language mode}}

View File

@@ -45,22 +45,22 @@ public struct LibAStruct {}
//--- TwoIOI.swift
@_implementationOnly import LibB
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@_implementationOnly import LibC
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
public func foo(a: LibAStruct) {} // expected-error {{cannot use struct 'LibAStruct' here; 'LibA' has been imported as implementation-only}}
//--- SPIOnlyAndIOI1.swift
@_spiOnly import LibB
@_implementationOnly import LibC
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
public func foo(a: LibAStruct) {} // expected-error {{cannot use struct 'LibAStruct' here; 'LibA' was imported for SPI only}}
//--- SPIOnlyAndIOI2.swift
@_implementationOnly import LibB
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' and family instead}}
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
@_spiOnly import LibC
public func foo(a: LibAStruct) {} // expected-error {{cannot use struct 'LibAStruct' here; 'LibA' was imported for SPI only}}