mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Warn on all non-resilient uses of @_implementationOnly, even for clang targets
The warnings about `using '@_implementationOnly' without enabling library evolution for 'client' may lead to instability during execution` and `@_implementationOnly' is deprecated, use 'internal import' instead` were wrongly restricted to only Swift import targets. Make sure they are raised for clang module targets as well. rdar://135233043
This commit is contained in:
@@ -792,11 +792,7 @@ void UnboundImport::validateInterfaceWithPackageName(ModuleDecl *topLevelModule,
|
||||
|
||||
void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
|
||||
SourceFile &SF) {
|
||||
ASTContext &ctx = SF.getASTContext();
|
||||
|
||||
// Per getTopLevelModule(), we'll only get nullptr here for non-Swift modules,
|
||||
// so these two really mean the same thing.
|
||||
if (!topLevelModule || topLevelModule.get()->isNonSwiftModule())
|
||||
if (!topLevelModule)
|
||||
return;
|
||||
|
||||
// If the module we're validating is the builtin one, then just return because
|
||||
@@ -804,6 +800,7 @@ void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
|
||||
// itself with resiliency. This can occur when one has passed
|
||||
// '-enable-builtin-module' and is explicitly importing the Builtin module in
|
||||
// their sources.
|
||||
ASTContext &ctx = SF.getASTContext();
|
||||
if (topLevelModule.get() == ctx.TheBuiltinModule)
|
||||
return;
|
||||
|
||||
@@ -841,7 +838,8 @@ void UnboundImport::validateResilience(NullablePtr<ModuleDecl> topLevelModule,
|
||||
}
|
||||
|
||||
// Report public imports of non-resilient modules from a resilient module.
|
||||
if (import.options.contains(ImportFlags::ImplementationOnly) ||
|
||||
if (topLevelModule.get()->isNonSwiftModule() ||
|
||||
import.options.contains(ImportFlags::ImplementationOnly) ||
|
||||
import.accessLevel < AccessLevel::Public)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: split-file %s %t
|
||||
// RUN: split-file %s %t --leading-lines
|
||||
|
||||
/// Build 2 libs.
|
||||
// RUN: %target-swift-frontend -emit-module %t/empty.swift -o %t/A.swiftmodule \
|
||||
// RUN: %target-swift-frontend -emit-module %t/empty.swift -o %t/SwiftModuleA.swiftmodule \
|
||||
// RUN: -enable-library-evolution -swift-version 5
|
||||
// RUN: %target-swift-frontend -emit-module %t/empty.swift -o %t/B.swiftmodule \
|
||||
// RUN: %target-swift-frontend -emit-module %t/empty.swift -o %t/SwiftModuleB.swiftmodule \
|
||||
// RUN: -enable-library-evolution -swift-version 5
|
||||
|
||||
/// Build a client with and without library-evolution.
|
||||
@@ -19,18 +19,47 @@
|
||||
// RUN: %target-swift-frontend -typecheck %t/Crypto.swift -I %t -verify \
|
||||
// RUN: -module-name Crypto
|
||||
|
||||
//--- module.modulemap
|
||||
module ClangModuleA {
|
||||
header "ClangModuleA.h"
|
||||
|
||||
module Submodule {
|
||||
header "ClangSubmodule.h"
|
||||
}
|
||||
}
|
||||
|
||||
module ClangModuleB {
|
||||
header "ClangModuleB.h"
|
||||
}
|
||||
|
||||
//--- ClangModuleA.h
|
||||
//--- ClangSubmodule.h
|
||||
//--- ClangModuleB.h
|
||||
|
||||
//--- empty.swift
|
||||
|
||||
//--- client-non-resilient.swift
|
||||
@_implementationOnly import A // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
|
||||
import B
|
||||
@_implementationOnly import SwiftModuleA // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
|
||||
@_implementationOnly import SwiftModuleA // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
|
||||
import SwiftModuleB
|
||||
|
||||
@_implementationOnly import ClangModuleA // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
|
||||
@_implementationOnly import ClangModuleA.Submodule // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
|
||||
import ClangModuleB
|
||||
|
||||
//--- client-resilient.swift
|
||||
@_implementationOnly import A
|
||||
@_implementationOnly import SwiftModuleA
|
||||
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
|
||||
import B
|
||||
import SwiftModuleB
|
||||
|
||||
@_implementationOnly import ClangModuleA
|
||||
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
|
||||
@_implementationOnly import ClangModuleA.Submodule
|
||||
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
|
||||
import ClangModuleB
|
||||
|
||||
//--- Crypto.swift
|
||||
@_implementationOnly import A // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'Crypto' may lead to instability during execution}}
|
||||
import B
|
||||
@_implementationOnly import SwiftModuleA // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'Crypto' may lead to instability during execution}}
|
||||
import SwiftModuleB
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
import ClangModuleB
|
||||
|
||||
Reference in New Issue
Block a user