-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use '@_implementationOnly' when importing 'Foundation.Bundle' in generated resource bundle accessor #5728
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
Conversation
…rated resource bundle accessor
@swift-ci test |
@swift-ci please smoke test |
Thanks for your PR! I think a good way for testing would be to look at the existing tests in We could have an example which looks like this:
The expectation would be that the build fails because Foundation is no longer re-exported from the library with resources. |
@xwu Can you add a test here so that we can merge this PR? Thanks! |
Thanks for the reminder. I'll try to take a look this weekend. |
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Ugh, I always seem to have trouble with the CI bot in this repository. |
@swift-ci smoke test |
0fe9746
to
4934aad
Compare
@swift-ci smoke test |
Groovy, the Linux self-hosted testing seems to suggest that it all works... I was pessimistic. |
4934aad
to
407c762
Compare
407c762
to
027033e
Compare
@swift-ci smoke test |
All righty, I think this PR is ready modulo a policy decision: What is the proper tools version gating for this change, if any? It is technically possible to emit While I am firmly in agreement with the overarching project's policy not to break source absent a new language version, this issue is unique because it comes down to tooling, and applying the same policy to tools version comes with a significant drawback here: The problem at issue is inadvertently bringing in Foundation for the end user, but whether this fix is applied would be down to third-party dependencies upgrading to the latest tools version. That is to say, shipping this gated on the tools version would effectively put the fix out of the reach of impacted users for an indefinite amount of time. If it were my code involved, I'd prefer the first scenario (a technically source-breaking error that tells me to write I'll await your guidance as to how to proceed; if you think the language workgroup should weigh in too, let me know and I will bring it to them. |
Thanks again for your PR! To me it's pretty clear that this has to be guarded by the tools-version, because
On top of that, I don't think this will on its own eliminate the Foundation dependency in practice? The generated code will still be present and therefore Foundation will be linked to any clients, wouldn't it? BTW, I think we need to switch to |
@neonichu This situation is unique (I think) because the source-breaking effect of this PR (and the bug that prompted it) is not on the package in which the tools version is defined, but of the end user who uses the package as a dependency and writes invalid code. It is very difficult to reason about even when one explains it! If this PR is gated on the tools version, then the tools version of the dependency will determine if the user who uses that dependency experiences this bug. It is actually this scenario that is impossible to address: it is a coming together of a suboptimal thing that an old tools version does to a dependency and an invalid thing inadvertently done by the end user of the dependency. By contrast, if this PR is not gated on any tools version, there is actually no breakage that can't be addressed, since there is no effect on the package itself, and the end user's code that relies on the package as a dependency is by construction in the hands of the end user. However, since it is all a fairly niche proposition, we can certainly guard on What would be the right |
… of 'Foundation.Bundle'.
@swift-ci smoke test |
I don't think we know where the breakage will occur since clients can be library packages as well. I would agree with you if this was limited to "top-level" clients that no one else could depend on. |
@neonichu Good point, I guess Foundation may be currently pulled in transitively through multiple layers of dependencies, oof… |
I think this surfaced a warning for the case where a Swift package with resources does import Foundation without using |
This was a change that landed in #5728 but it has the unintended consequence of generating unfixable warnings for packages which do import Foundation. We can probably solve that with import scanning to decide between the two import types, but given where we are in the 5.8 schedule, this seems to be something better done for a future manifest version.
This was a change that landed in #5728 but it has the unintended consequence of generating unfixable warnings for packages which do import Foundation. We can probably solve that with import scanning to decide between the two import types, but given where we are in the 5.8 schedule, this seems to be something better done for a future manifest version.
…5997) This was a change that landed in #5728 but it has the unintended consequence of generating unfixable warnings for packages which do import Foundation. We can probably solve that with import scanning to decide between the two import types, but given where we are in the 5.8 schedule, this seems to be something better done for a future manifest version.
…5997) This was a change that landed in #5728 but it has the unintended consequence of generating unfixable warnings for packages which do import Foundation. We can probably solve that with import scanning to decide between the two import types, but given where we are in the 5.8 schedule, this seems to be something better done for a future manifest version. (cherry picked from commit cb9d03b)
…5997) (#6055) This was a change that landed in #5728 but it has the unintended consequence of generating unfixable warnings for packages which do import Foundation. We can probably solve that with import scanning to decide between the two import types, but given where we are in the 5.8 schedule, this seems to be something better done for a future manifest version. (cherry picked from commit cb9d03b)
Motivation:
As per discussion in a Swift Forums thread, use of
Foundation.Bundle
causes Foundation APIs to be implicitly imported into the code of downstream users of the package.This is counterintuitive and can cause unexpected code size increases when those APIs extend standard library types and are inadvertently used, without any indication in searchable source where the Foundation dependency is coming from.
Modifications:
We mark the import of
Foundation.Bundle
in the generated resource bundle accessor as@_implementationOnly
; the extension is implicitly internal, so hopefully this will do the trick. In this draft, it's gated on the tools version, but arguably shouldn't be.Result: