swiftlang/swift-syntax

Getting warnings about `@_implementationOnly` when building a package dependent on SwiftSyntax

Closed this issue · 5 comments

Description

When building swift-testing, I get a bunch of warnings along these lines while SwiftSyntax builds:

/Volumes/Dev/Source/swift-testing/.build/checkouts/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift:15:22: warning: using '@_implementationOnly' without enabling library evolution for 'SwiftSyntax' may lead to instability during execution
@_implementationOnly import Darwin
                     ^
/Volumes/Dev/Source/swift-testing/.build/checkouts/swift-syntax/Sources/SwiftCompilerPlugin/CompilerPlugin.swift:16:22: warning: using '@_implementationOnly' without enabling library evolution for 'SwiftCompilerPlugin' may lead to instability during execution
@_implementationOnly import SwiftCompilerPluginMessageHandling
                     ^

This then pollutes the output of the downstream package (swift-testing) that's using SwiftSyntax. :(

Steps to Reproduce

Using toolchain swift-DEVELOPMENT-SNAPSHOT-2023-09-20-a and SwiftSyntax 509.0.0.

To repro:

  1. Check out https://github.com/apple/swift-testing
  2. export TOOLCHAINS=swift (if needed)
  3. swift test

Tracked in Apple’s issue tracker as rdar://115910675

We need to replace @_implementaitonOnly by the following when https://github.com/apple/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md is accepted.

#if compiler(>= 5.10)
private import XXX
#else
@_implementationOnly import XXX
#endif

It looks like there’s a gap between the deprecation of @_implementationOnly and the introduction of scoped imports. I believe that means we need to add a conditional compilation flag that gets set when we build with library evolution from CMake but not when building using SwiftPM and conditionally enables @_implementationOnly.

keith commented

@ahoppen do you know if there a ticket tracking that difference? We're experiencing the same with other libraries that haven't made a similar change like this

AFAICT it’s expected behavior that Swift 5.10 will warn about @_implementationOnly imports in non-library-evolution-enabled modules and scoped imports will only be introduced in Swift 5.11. I don’t know the exact specifics but apparently @_implementationOnly was never intended to work without library evolution and had some quirks when library evolution wasn’t enabled, so the warning is expected.