Sema: Opt-in check for structs references to hidden dependencies in non-library-evolution mode #85179
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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@_implementationOnlyimports 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@_implementationOnlyon 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
@_implementationOnlyimport, 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
@_implementationOnlydependency unless marked@_implementationOnly. Similarly, a public or non-@_implementationOnlystruct cannot refer to an@_implementationOnlystruct in its layout. If a public or non-@_implementationOnlystruct 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.