Skip to content

[Dependency Scanning] Post-process imports that fail to resolve against the cache entries added by other resolved imports #68849

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

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Sep 28, 2023

It is possible that import resolution failed because we are attempting to resolve a module which can only be brought in via a .modulemap of a different Clang module dependency which is not otherwise on the current search paths. For example, suppose we are scanning a .swiftinterface for module Foo, which contains:

@_exported import Foo
import Bar
...

Where Foo is the underlying Framework clang module whose .modulemap defines an auxiliary module Bar. Because Foo is a framework, its .modulemap is under <some_framework_search_path>/Foo.framework/Modules/module.modulemap. Which means that lookup of Bar alone from Swift will not be able to locate the module in it. However, the lookup of Foo will itself bring in the auxiliary module because the Clang scanner instance scanning for clang module Foo will be able to find it in the corresponding framework module's .modulemap and register it as a dependency which means it will be registered with the scanner's cache. To handle such cases, we first add all successfully-resolved modules and (for Clang modules) their transitive dependencies to the cache, and then attempt to re-query imports for which resolution originally failed from the cache. If this fails, then the scanner genuinely failed to resolve this dependency.

@artemcm
Copy link
Contributor Author

artemcm commented Sep 28, 2023

@_exported import Foo
import Bar
...

Notably, if the order of imports here is reversed then an implicit module build too will fail. Any such cases that happen to build today do so out of luck of getting the import statement ordering right.

@artemcm artemcm force-pushed the ReQueryFromCacheImportResolutionFailure branch from b423505 to af5bc15 Compare September 29, 2023 17:49
@artemcm
Copy link
Contributor Author

artemcm commented Sep 29, 2023

@swift-ci smoke test

…st the cache entries added by other resolved imports

It is possible that import resolution failed because we are attempting to resolve a module which can only be brought in via a modulemap of a different Clang module dependency which is not otherwise on the current search paths. For example, suppose we are scanning a '.swiftinterface' for module 'Foo', which contains:
'''
@_exported import Foo
import Bar
...
Where 'Foo' is the underlying Framework clang module whose '.modulemap' defines an auxiliary module 'Bar'. Because 'Foo' is a framework, its modulemap is under '<some_framework_search_path>/Foo.framework/Modules/module.modulemap'. Which means that lookup of `Bar` alone from Swift will not be able to locate the module in it. However, the lookup of Foo will itself bring in the auxiliary module becuase the Clang scanner instance scanning for clang module Foo will be able to find it in the corresponding framework module's modulemap and register it as a dependency which means it will be registered with the scanner's cache in the step above. To handle such cases, we first add all successfully-resolved modules and (for Clang modules) their transitive dependencies to the cache, and then attempt to re-query imports for which resolution originally failed from the cache. If this fails, then the scanner genuinely failed to resolve this dependency.
@artemcm artemcm force-pushed the ReQueryFromCacheImportResolutionFailure branch from af5bc15 to 64b18f5 Compare September 29, 2023 20:06
@artemcm
Copy link
Contributor Author

artemcm commented Sep 29, 2023

@swift-ci smoke test

@artemcm artemcm merged commit 1c8f295 into swiftlang:main Oct 2, 2023
@artemcm artemcm deleted the ReQueryFromCacheImportResolutionFailure branch October 2, 2023 16:30
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.

2 participants