Skip to content

[5.9][Serialization] Load non-public transitive dependencies on @testable imports #64794

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 7 commits into from
Mar 31, 2023

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Mar 30, 2023

A @testable import allows a client to call internal decls which may refer to non-public dependencies. To support such a use case, load non-public transitive dependencies of a module when it's imported @testable from the main module.

We apply this behavior only to @testable imports from the main module being built, not transitively trough @testable imports of a library. It should support the vast majority of @testable uses and provide a reasonable behavior without surprises.

This replaces the previous behavior where we loaded those dependencies for any modules built for testing. This would load more modules for any debug build, opening the door to a different behavior between debug and release builds. In contrast, applying this logic to @testable clients will only change the behavior of test targets.

rdar://107329303


Cherry-pick of the feature from #64693, plus as support: #64516 and #64522.

This affects only the new kind of imports using access level, as it's still behind a flag it should be low risk and not affect existing projects.

xymus added 7 commits March 30, 2023 16:14
The new diagnoseSerializedASTLoadFailureTransitive diagnose problems for
transitive dependencies only: missing dependency, missing underlying
module, or circular dependency.
…imports

A @testable import allows a client to call internal decls which may
refer to non-public dependencies. To support such a use case, load
non-public transitive dependencies of a module when it's imported
@testable from the main module.

This replaces the previous behavior where we loaded those dependencies
for any modules built for testing. This was risky as we would load more
module for any debug build, opening the door to a different behavior
between debug and release builds. In contrast, applying this logic to
@testable clients will only change the behavior of test targets.

rdar://107329303
…dependencies

When using the -testable-import-module argument to insert a testable
import, there's no ImportDecl on which to show the diagnostics when
loading transitive dependencies. Clean up the logic to still load
dependencies in such a case.
…ependencies

* A multi-file scenario where one file has a normal import and the other
  a testable import. In this case we still load the extra dependencies
  and show diagnostics only of the testable import.

* A scenario where module A @testable imports module B, which @_exported
  imports module C. In this case, non-public imports of B are loaded,
  but not those of C. This is a limitation of the current implementation
  and could be improved upon in the future.
@xymus xymus requested a review from a team as a code owner March 30, 2023 23:21
@xymus
Copy link
Contributor Author

xymus commented Mar 30, 2023

@swift-ci Please test

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only affect desktop users.

@xymus xymus merged commit 3425206 into swiftlang:release/5.9 Mar 31, 2023
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants