Skip to content

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

Merged
merged 2 commits into from
Jul 1, 2022

Conversation

ApolloZhu
Copy link
Contributor

@ApolloZhu ApolloZhu commented Jan 9, 2022

Changes all module loaders that cannot load submodules to return false when checking if it canImport a submodule. CompilerInstance::setUpModuleLoaders in Frontend.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 use hasSubmodule() for consistency)
  • MemoryBufferSerializedModuleLoader
  • ExplicitSwiftModuleLoader
  • ModuleInterfaceLoader
  • ImplicitSerializedModuleLoader (handled in SerializedModuleLoaderBase)
  • ClangImporter (already working, no change)

Why?

As implemented in #34094, when checking canImport(CoreImage.Anything), because CoreImage 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:

$ swift --version
Apple Swift version 5.6-dev (LLVM 031406b6cea8006, Swift 9f7d3fccad66d76)
Target: x86_64-apple-macosx12.0
$ swift-frontend -typecheck -verify -disable-objc-attr-requires-foundation-module can_import_submodule_in_framework.swift -F .
can_import_submodule_in_framework.swift:23:8: error: expected error not produced
    // expected-error@-1 {{cannot find 'fromSubmodule' in scope}}
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zsh: exit 1     swift-frontend -typecheck -verify  can_import_submodule_in_framework.swift -F

@ApolloZhu ApolloZhu changed the title Fix canImport submodule checking in loaders other than ClangImporter Fix canImport submodule checking in loaders not supporting submodules Jan 9, 2022
@WowbaggersLiquidLunch
Copy link
Contributor

@swift-ci please smoke test

@ApolloZhu
Copy link
Contributor Author

@CodaFi would you mind taking a look at this when you have time?

@CodaFi
Copy link
Contributor

CodaFi commented Feb 15, 2022

@swift-ci please smoke test

@CodaFi
Copy link
Contributor

CodaFi commented Feb 22, 2022

@swift-ci test

@ApolloZhu
Copy link
Contributor Author

Seems that the tests have passed and this is still mergeable. Let me know if there are additional changes needed.

@ApolloZhu
Copy link
Contributor Author

@CodaFi do you think it's possible for us to merge this before the Swift 5.7 cut-off date (April 4th), so we can ship a less buggy version in that release?

For loaders that don't support loading submodules, canImportModule should report false instead of checking if can import top module.
@ApolloZhu ApolloZhu force-pushed the fix-canImport-submodule-checking branch from c6487de to cde0ce7 Compare April 1, 2022 21:45
@ApolloZhu
Copy link
Contributor Author

ApolloZhu commented Apr 1, 2022

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

@xwu
Copy link
Collaborator

xwu commented Apr 2, 2022

@swift-ci test

@ApolloZhu
Copy link
Contributor Author

CI status update: all existing checks have passed

@xwu xwu requested a review from CodaFi April 3, 2022 16:10
@xwu
Copy link
Collaborator

xwu commented Apr 3, 2022

cc @beccadax as the last person to work on some of these files, in case there's other, more appropriate reviewers.

@ApolloZhu
Copy link
Contributor Author

Created #42179 for potential inclusion in the Swift 5.7 release.

@DougGregor
Copy link
Member

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member

The change looks good to me. Kicking off another CI round to merge it in, thank you!

@swift-ci swift-ci merged commit 8364d5b into swiftlang:main Jul 1, 2022
@ApolloZhu ApolloZhu deleted the fix-canImport-submodule-checking branch July 8, 2022 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants