Skip to content

Conversation

@xymus
Copy link
Contributor

@xymus xymus commented Oct 28, 2025

While @_implementationOnly (and family) is properly type-checking in library-evolution mode we did not have an equivalent in non-library-evolution mode. In this case more internal details are exposed to the client, so the library-evolution checks aren’t sufficient. This PR aims at bridging that gap and take a step in the right direction to properly support @_implementationOnly imports and more widely hiding dependencies in non-library-evolution mode.

This PR introduces an opt-in check via the experimental feature CheckImplementationOnly. Adopting it is recommended but will likely require source changes as it’s aligned with the new support of @_implementationOnly on structs.

In this mode we ensure that memory layouts of structs visible to clients are sound. This mostly means that public structs don’t rely on types hidden from the clients via an @_implementationOnly import, in a local member or transitively through a non-public struct.

A struct is by default considered exposable to clients and will reject a reference to an @_implementationOnly dependency unless marked @_implementationOnly. Similarly, a public or non-@_implementationOnly struct cannot refer to an @_implementationOnly struct in its layout. If a public or non-@_implementationOnly struct needs to hold a hidden type it should abstract it away behind a protocol or similar.

This check is designed for structs, it remains too permissive for enums and may be too strict for classes.

xymus added 4 commits October 28, 2025 09:34
Gate it behind CheckImplementationOnly.
…onOnly

In non-library-evolution mode, gated behind the CheckImplementationOnly
feature flag, consider structs to be a fragile use site by default,
unless marked `@_implementationOnly`. This prevents them to refer to
restricted imports like implementation-only.
In non-library-evolution mode, gated behind the CheckImplementationOnly
feature flag, report references to structs marked with
`@_implementationOnly` from a fragile context. Preventing references
from inlinable functions and structs not marked `@_implementationOnly`.
@xymus
Copy link
Contributor Author

xymus commented Oct 28, 2025

@swift-ci Please smoke test

1 similar comment
@xymus
Copy link
Contributor Author

xymus commented Oct 28, 2025

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Oct 28, 2025

@swift-ci Please smoke test macOS

@nkcsgexi
Copy link
Contributor

🎉

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