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
[SR-11910] @_implementationOnly types not allowed as private properties on public types #54328
Comments
@swift-ci create |
It is by design, but the error message could be more clear about why it is an issue. The type Base is rejected here because the clients of this module (main.swift) need to know the actual layout of the struct to allocate it and access its stored properties directly. The implementation-only import completely hides `Base` from the clients, and also from the compiler compiling the clients. Making the property private protects it at the semantic level but the compiler would still need to know of its presence and type when compiling the clients. Depending on your use case, a solution could be to compile this module with resilience by using `-enable-library-evolution`. This setting will enable compiling the module for clients to use indirections when initializing or accessing non-frozen structs. With indirections instead of direct accesses the clients may be less optimizable but they don’t need the full knowledge of the struct layout so the compiler can hide the private stored property from the clients. This private property should then be accepted. |
Thanks for the context! |
Just also found https://bugs.swift.org/browse/SR-11613 |
@xymus what if everything here were classes instead? Could that case be allowed? It seems like currently this fails with the same error, but I assume it shouldn't have the same struct layout issues |
For historians it seems like the class issue is unexpected https://forums.swift.org/t/swift-implementationonly-not-working-correctly-with-private-members/39002/3?u=keith |
"Unexpected" is a little strong. It's absolutely expected today, just possible to change in the future if we're willing to compromise on cross-module inlining in some ways. |
Attachment: Download
Additional Detail from JIRA
md5: 43f6fcffed6a4ec0ba4c89fbdaa1aa13
Issue Description:
If I import a target with `@_implementationOnly import base` that defines a type `Base` and create a `public` type `Foo` that has `private let base: Base` it fails to build with:
I would expect this to build since the property should not be viewable by dependees even though the enclosing type is public. This might be by design though? See the attached sample project and run `swift build` for an example.
The text was updated successfully, but these errors were encountered: