Skip to content

Commit 99fd29c

Browse files
committed
Sema: Refactor @_implementationOnly deprecation warning suppression.
1 parent ba3cd79 commit 99fd29c

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,23 @@ void UnboundImport::validateInterfaceWithPackageName(ModuleDecl *topLevelModule,
790790
}
791791
}
792792

793+
/// Returns true if the importer and importee tuple are on an allow list for
794+
/// use of `@_implementationOnly import`, which is deprecated. Some existing
795+
/// uses of `@_implementationOnly import` cannot be safely replaced by
796+
/// `internal import` because the existence of the imported module must always
797+
/// be hidden from clients.
798+
static bool shouldSuppressNonResilientImplementationOnlyImportDiagnostic(
799+
StringRef targetName, StringRef importerName) {
800+
if (targetName == "CCryptoBoringSSL" || targetName == "CCryptoBoringSSLShims")
801+
return importerName == "Crypto" || importerName == "_CryptoExtras" ||
802+
importerName == "CryptoBoringWrapper";
803+
804+
if (targetName == "CNIOBoringSSL" || targetName == "CNIOBoringSSLShims")
805+
return importerName != "NIOSSL";
806+
807+
return false;
808+
}
809+
793810
void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
794811
SourceFile &SF) {
795812
if (!topLevelModule)
@@ -825,14 +842,8 @@ void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
825842
inFlight.fixItReplace(import.implementationOnlyRange, "internal");
826843
}
827844
} else if ( // Non-resilient client
828-
!(((targetName.str() == "CCryptoBoringSSL" ||
829-
targetName.str() == "CCryptoBoringSSLShims") &&
830-
(importerName.str() == "Crypto" ||
831-
importerName.str() == "_CryptoExtras" ||
832-
importerName.str() == "CryptoBoringWrapper")) ||
833-
((targetName.str() == "CNIOBoringSSL" ||
834-
targetName.str() == "CNIOBoringSSLShims") &&
835-
importerName.str() == "NIOSSL"))) {
845+
!shouldSuppressNonResilientImplementationOnlyImportDiagnostic(
846+
targetName.str(), importerName.str())) {
836847
ctx.Diags.diagnose(import.importLoc,
837848
diag::implementation_only_requires_library_evolution,
838849
importerName);

0 commit comments

Comments
 (0)