Implement canImport test for submodule - #34094
Conversation
There was a problem hiding this comment.
Now emits diagnostics at the module name instead canImport
#if canImport(NotExist)
- ^
+ ^
CodaFi
left a comment
There was a problem hiding this comment.
One comment about the implementation and a request: please give this a rebase.
Thank you for tackling this.
|
Thanks for pointing that out! Fixed |
CodaFi
left a comment
There was a problem hiding this comment.
The implementation looks great.
|
Please go to swift-evolution and ask if this is a feature or a bug fix. I have confidence that they'll greenlight this, but it's always good to get the community's stamp. |
|
Will ask in the forum. Thanks for all the suggestions |
|
Thanks for calling out the impact on the reference and grammar of "The Swift Programming Language". I'll follow this PR so I can update the documentation as needed. The grammar allows operators in an import is probably for the form that allows you to specify a specific declaration to import. (Git history shows me that grammar rule dates back to the original Swift 1 version of the book.) For example, something like |
|
So far the community response agrees this is a simple bug fix and no further changes need to be made. What shall we do next? |
|
I know the community is busy discussing new concurrency proposals, but should I submit/pitch a simple Swift Evolution proposal for this change as well? |
|
Please rebase this when you can and tag me here and we'll get this merged. |
d08b713 to
ac56a4e
Compare
|
I updated from Since our last review of this PR, @nkcsgexi introduced a version check in canImport. Based on their current implementation and a few #if canImport(A.B.C, _version: 3)
#if canImport(A.B.C, _underlyingVersion: 4)Two solutions:
|
|
@ApolloZhu thanks for adding the support for submodules! Though we usually don't have submodule-specific module versions, can we use the top-level module version in the case of sub-modules? |
|
I'm pretty sure https://github.com/apple/swift/pull/34094/files#diff-0062ad3fe872d09412bd3e7c72610b5ad0bd39667ebc00695351ef93c7c6815f already does this. Please let me know if that's not the case and I'd appreciated some help getting starting on fixing that. |
|
@ApolloZhu You are right. Thanks for clarifying! |
|
I see this PR is expecting some tests to pass. Who (and when) can initiate those tests? |
|
@swift-ci test |
ac56a4e to
683d469
Compare
|
|
Pinging @CodaFi as they requested. Tag removed. |
|
@swift-ci smoke test |
|
Brilliant - still LGTM. Will merge once the bots come back blue. |
|
@swift-ci smoke test |
|
Great, all checks have passed |
|
⛵ |
This PR extends
canImportto check for submodule availability.Forums Thread: https://forums.swift.org/t/41196
Motivation
Currently,
canImportonly supports checking for top-level module availability while many have submodules with different availability. For example, whileCIFilterwas introduced in iOS 5,CIFilterBuiltinsis only available on iOS 13+. Therefore, one might want to write code like this:Changes needed for The Swift Programming Language Reference
This PR would mean:
For housekeeping, because
import OpenGL.(GL3, GL3.Ext)is (likely) never implemented, unless we're planning to have a separate PR extending import to support operators (e.g.import func SomeModule.+++) as mentioned in #34094 (comment), we should update:Alternatives Considered
While the initial concern could be addressed by introducing
#if availablesimiliar to how@available/#availableworks but at the top level, clang modules may specify other requirements, therefore allowingcanImportto check for submodule availability directly should be a more well-rounded and direct approach.Questions/Concerns
#if canImport(module-name)tests for module support by name." Are submodule names module names?FIXMEs in other module loaders mentioning submodule support is not in place yet. Does this change have to wait for those to be implemented?