-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Define library levels to detect public import of private modules and more #36608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci Please smoke test |
I forgot to commit a test. @swift-ci Please smoke test |
I may have to wait before I can land the last commit for The flag -library-level spi should affect type-checking, it allows the use of SPI decls in API as the whole module is considered SPI. (rdar://75335462) as this one requires to print the flag in the swift interface which will may lead to condfails. |
@swift-ci Please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice approach! Any reason we don't emit -library-level
into the interface so we don't need to infer the level from search paths?
SPI, | ||
|
||
/// The library has some other undefined distribution. | ||
Other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need Other
here? can we use API
for default to simplify the logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using API as the default would mean that all projects get warnings on imports of private modules until they manually set the flag -library-level spi
or we get a build system to set it automatically. I'm really tempted by that to get results faster but the rollout will be smoother if we wait for the build system to infer the library level.
Also, Other
is now relevant to IPI/build time modules. We don't see much of those in Swift but we do import IPI clangmodules.
lib/AST/Module.cpp
Outdated
auto fromPrivateFrameworks = [&](StringRef path) -> bool { | ||
auto sep = llvm::sys::path::get_separator(); | ||
auto privateFrameworksPath = ctx.SearchPathOpts.SDKPath + | ||
sep + "System" + sep + "Library" + sep + "PrivateFrameworks" + sep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: start with llvm::Twine(ctx.SearchPathOpts.SDKPath)
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While applying this I came across llvm::sys::path::append
which simplifies greatly this piece of code.
@nkcsgexi It's on my todo list but we should wait a bit to print |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense. Thank you for the explanation!
Intro the concept of library access or distribution level to identify layers of libraries and report public imports of private libraries from public ones. rdar://62934005
@swift-ci Please smoke test |
@swift-ci Please smoke test macOS |
1 similar comment
@swift-ci Please smoke test macOS |
Intro the concept of library access/distribution level that indicates if it will be distributed widely (
api
) or reserved for use inside the organization (spi
).In practice, setting the flag
-library-level api
will warn on public imports of SPI modules and suggests using@_implementationOnly
. The imported module SPI-ness is determined from the location it was loaded from and from whether it belongs to a private clang modulemap.( rdar://62934005)Future work:
-library-level spi
should affect type-checking, it allows the use of SPI decls in API as the whole module is considered SPI. (rdar://75335462)ipi
level for project-internal modules?