Skip to content

Remove @_implementationOnly annotations #2429

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

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Sources/SwiftCompilerPlugin/CompilerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
// NOTE: This basic plugin mechanism is mostly copied from
// https://github.com/apple/swift-package-manager/blob/main/Sources/PackagePlugin/Plugin.swift

@_implementationOnly import Foundation
@_implementationOnly import SwiftCompilerPluginMessageHandling
import SwiftSyntaxMacros

#if swift(>=5.11)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Suggested change
#if swift(>=5.11)
#if hasFeature(AccessLevelOnImport)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turned out hasFeature(AccessLevelOnImport) doesn't work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline that AccessLevelOnImport is an experimental feature that’s always enabled, thus the hasFeature check doesn’t work. So we just check for Swift 5.11.

private import Foundation
private import SwiftCompilerPluginMessageHandling
#else
import Foundation
import SwiftCompilerPluginMessageHandling
#endif

#if os(Windows)
@_implementationOnly import ucrt
#if swift(>=5.11)
private import ucrt
#else
import ucrt
#endif
#endif

//
Expand Down Expand Up @@ -167,8 +177,8 @@ extension CompilerPlugin {
}

internal struct PluginHostConnection: MessageConnection {
let inputStream: FileHandle
let outputStream: FileHandle
fileprivate let inputStream: FileHandle
fileprivate let outputStream: FileHandle

func sendMessage<TX: Encodable>(_ message: TX) throws {
// Encode the message as JSON.
Expand Down
16 changes: 13 additions & 3 deletions Sources/SwiftSyntax/SyntaxText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=5.11)
#if canImport(Darwin)
@_implementationOnly import Darwin
private import Darwin
#elseif canImport(Glibc)
@_implementationOnly import Glibc
private import Glibc
#elseif canImport(Musl)
@_implementationOnly import Musl
private import Musl
#endif
#else
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif
#endif

/// Represent a string.
Expand Down
7 changes: 6 additions & 1 deletion Sources/SwiftSyntaxMacrosTestSupport/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import SwiftParserDiagnostics
import SwiftSyntax
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros
import XCTest
import _SwiftSyntaxTestSupport

#if swift(>=5.11)
private import XCTest
#else
import XCTest
#endif

// MARK: - Note

/// Describes a diagnostic note that tests expect to be created by a macro expansion.
Expand Down