@_implementationOnly behavior in autolinking

Hello, everyone. I have a question about @_implementationOnly.

Currently, Foundation in apple/swift-corelibs-foundation uses @_implementationOnly to import CoreFoundation. At the same time, RunLoop.swift is still importing CoreFoundation without the attribute.

The import in RunLoop.swift causes warnings that say 'CoreFoundation' inconsistently imported as implementation-only. But if the warnings are resolved by adding @_implementationOnly for all imports, there will be a problem with the static auto-linking mechanism, I think.

AFAIU, if Foundation imports CoreFoundation without @_implementationOnly, a client of Foundation doesn't need to import CoreFoundation and also doesn't need to link libCoreFoundation explicitly, thanks to the auto-linking mechanism.

But if Foundation imports CoreFoundation with @_implementationOnly, CoreFoundation wouldn't be linked to the client automatically. So when a client code uses a Foundation API, that depends on CoreFoundation implementation, linking will be failed with undefined symbol: _CFXXXX as long as the client doesn't import CoreFoundation explicitly.

So I want to confirm that the explicit import is the expected behavior of @_implementationOnly or not.

CC: @jrose

Related posts

4 Likes

I believe the C++ interop work has run in to similar issues with inconsistent use of _implementationOnly in Foundation. See, for example: Add a failing test for SR-13785 by scentini · Pull Request #34462 · apple/swift · GitHub

And here: https://github.com/apple/swift/pull/32404#issuecomment-706624323