How to track module imports

When building an Xcode project, the file doesn't have any import clause at the top, yet it implicitly imports some modules - I know it because I can use it and it compiles. Now, If I'd like to debug what is actually happening with the imports here, what are the possibilities? I'd like to learn about import tree or something that is used by this file when being compiled.

The thing is that the import A from another file, that seems unrelated to the file I examine, decide whether the module is available or not.

Appreciate any tips.

3 Likes

Specifically I wasn't aware that Objective-C categories that happen to be in "PrivateHeaders" and part of _Private modules, are available for the Swift module without explicit import Foo_Private for the file where it's used. Is this by design? If so, can you please drop some links to read more about this (and why it is so)?

My setup:

  • Ocoo.framework <- Objective-C framework with public and private clang module. Private headers go to PrivateHeaders and uses module.private.modulemap named Ocoo_Private
  • Ocoo.framework is linked with Swift application

What I see:

  • Regular symbols (eg. class) are not implicitly available to the Swift application without explicit import Ocoo_Private for each file. This is OK.
  • Categories (UIKit category in my case) from Ocoo_Private module are available everywhere in the module, once any file do import Ocoo_Private - this is unexpected to me, as it propagates everywhere unintionally. I wonder if there is a way to stop propagating symbols like that? I guess it's something to do with ClangImporter

What you're seeing is SR-3908, which is both difficult and not source compatible to fix. We probably still should fix it at some point, though, even if we have to guard it on -swift-version.

2 Likes