-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix canImport submodule checking in loaders not supporting submodules #40777
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
Fix canImport submodule checking in loaders not supporting submodules #40777
Conversation
@swift-ci please smoke test |
@CodaFi would you mind taking a look at this when you have time? |
@swift-ci please smoke test |
@swift-ci test |
Seems that the tests have passed and this is still mergeable. Let me know if there are additional changes needed. |
For loaders that don't support loading submodules, canImportModule should report false instead of checking if can import top module.
c6487de
to
cde0ce7
Compare
Rebased on top of main (old history in https://github.com/ApolloZhu/swift/tree/fix-canImport-submodule-checking-backup), tested locally and everything still works, hopefully now Windows platform CI check won't fail |
@swift-ci test |
CI status update: all existing checks have passed |
cc @beccadax as the last person to work on some of these files, in case there's other, more appropriate reviewers. |
Created #42179 for potential inclusion in the Swift 5.7 release. |
@swift-ci please smoke test and merge |
The change looks good to me. Kicking off another CI round to merge it in, thank you! |
Changes all module loaders that cannot load submodules to return false when checking if it canImport a submodule.
CompilerInstance::setUpModuleLoaders
inFrontend.cpp
mentions that there are 6 types of loaders, and they are all fixed with changes in this PR (or don't need to be fixed):SourceLoader
(already working, but changed to usehasSubmodule()
for consistency)MemoryBufferSerializedModuleLoader
ExplicitSwiftModuleLoader
ModuleInterfaceLoader
ImplicitSerializedModuleLoader
(handled inSerializedModuleLoaderBase
)ClangImporter
(already working, no change)Why?
As implemented in #34094, when checking
canImport(CoreImage.Anything)
, becauseCoreImage
is a serialized framework, SerializedModuleLoader checked if it can import CoreImage (ignoring submodule path) and incorrectly return true. I discovered this issue after trying out the latest toolchain, thus this fix + a test involving a submodule in a mixed framework (where multiple module loaders can import the top module).I ran the new test using the unfixed implementation, and indeed it doesn't pass: