Skip to content

Commit 91001f0

Browse files
committed
[Sema] Consider modules imported from more paths as private
Consider both frameworks and free floating modules imported from more private path as SPI. This will make the compiler raise errors on public imports of more private modules. rdar://91904154
1 parent 6cc2399 commit 91001f0

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

lib/AST/Module.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,16 +2646,18 @@ ModuleLibraryLevelRequest::evaluate(Evaluator &evaluator,
26462646
auto fromPrivateFrameworks = [&](StringRef modulePath) -> bool {
26472647
if (!ctx.LangOpts.Target.isOSDarwin()) return false;
26482648

2649-
return hasSDKPrefix(modulePath, "System", "Library", "PrivateFrameworks");
2649+
return hasSDKPrefix(modulePath, "AppleInternal", "Library", "Frameworks") ||
2650+
hasSDKPrefix(modulePath, "System", "Library", "PrivateFrameworks") ||
2651+
hasSDKPrefix(modulePath, "System", "iOSSupport", "System", "Library", "PrivateFrameworks") ||
2652+
hasSDKPrefix(modulePath, "usr", "local", "include");
26502653
};
26512654

26522655
if (module->isNonSwiftModule()) {
26532656
if (auto *underlying = module->findUnderlyingClangModule()) {
26542657
// Imported clangmodules are SPI if they are defined by a private
26552658
// modulemap or from the PrivateFrameworks folder in the SDK.
26562659
bool moduleIsSPI = underlying->ModuleMapIsPrivate ||
2657-
(underlying->isPartOfFramework() &&
2658-
fromPrivateFrameworks(underlying->PresumedModuleMapFile));
2660+
fromPrivateFrameworks(underlying->PresumedModuleMapFile);
26592661
return moduleIsSPI ? LibraryLevel::SPI : LibraryLevel::API;
26602662
}
26612663
return LibraryLevel::Other;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module LocalClang [system] {
2+
header "LocalClang.h"
3+
export *
4+
}

test/Sema/implementation-only-import-suggestion.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import PrivateSwift // expected-error{{private module 'PrivateSwift' is imported
4040
import PublicClang
4141
import PublicClang_Private // expected-error{{private module 'PublicClang_Private' is imported publicly from the public module 'MainLib'}}
4242
import FullyPrivateClang // expected-error{{private module 'FullyPrivateClang' is imported publicly from the public module 'MainLib'}}
43+
import LocalClang // expected-error{{private module 'LocalClang' is imported publicly from the public module 'MainLib'}}
4344
@_exported import MainLib // expected-warning{{private module 'MainLib' is imported publicly from the public module 'MainLib'}}
4445

4546
/// Expect no errors with implementation-only imports.
@@ -51,6 +52,7 @@ import FullyPrivateClang // expected-error{{private module 'FullyPrivateClang' i
5152
@_implementationOnly import PrivateSwift
5253
@_implementationOnly import PublicClang_Private
5354
@_implementationOnly import FullyPrivateClang
55+
@_implementationOnly import LocalClang
5456

5557
#endif
5658

0 commit comments

Comments
 (0)