From 0e66a033484192d53b2a1b8ab930fb5807a818e5 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Fri, 9 Feb 2024 11:23:02 -0800 Subject: [PATCH 1/2] Mark all MacroExpansion/PluginMessageHandling symbols SPI SwiftCompilerPluginMessageHandling are only intended to be used from internal modules like SwiftCompilerPlugin, or ASTGen and swift-plugin-server in swift repository. Make all the public symbols SPI so other third party modules don't accidentally use them. --- Sources/SwiftCompilerPlugin/CompilerPlugin.swift | 4 ++-- .../CompilerPluginMessageHandler.swift | 4 ++++ Sources/SwiftCompilerPluginMessageHandling/Macros.swift | 2 +- .../PluginMessageCompatibility.swift | 3 ++- .../SwiftCompilerPluginMessageHandling/PluginMessages.swift | 3 +++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftCompilerPlugin/CompilerPlugin.swift b/Sources/SwiftCompilerPlugin/CompilerPlugin.swift index 9c8d7f9a58e..d5dd1a92b5b 100644 --- a/Sources/SwiftCompilerPlugin/CompilerPlugin.swift +++ b/Sources/SwiftCompilerPlugin/CompilerPlugin.swift @@ -15,11 +15,11 @@ #if swift(>=6.0) public import SwiftSyntaxMacros private import Foundation -private import SwiftCompilerPluginMessageHandling +@_spi(PluginMessage) private import SwiftCompilerPluginMessageHandling #else import SwiftSyntaxMacros import Foundation -import SwiftCompilerPluginMessageHandling +@_spi(PluginMessage) import SwiftCompilerPluginMessageHandling #endif #if os(Windows) diff --git a/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift b/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift index 1f8cd43a178..ca971d5364b 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift @@ -17,11 +17,13 @@ import SwiftSyntaxMacros #endif /// Optional features. +@_spi(PluginMessage) public enum PluginFeature: String { case loadPluginLibrary = "load-plugin-library" } /// A type that provides the actual plugin functions. +@_spi(PluginMessage) public protocol PluginProvider { /// Resolve macro type by the module name and the type name. func resolveMacro(moduleName: String, typeName: String) throws -> Macro.Type @@ -37,6 +39,7 @@ public protocol PluginProvider { /// Low level message connection to the plugin host. /// This encapsulates the connection and the message serialization. +@_spi(PluginMessage) public protocol MessageConnection { /// Send a message to the peer. func sendMessage(_ message: TX) throws @@ -66,6 +69,7 @@ struct HostCapability { /// the response. /// /// The low level connection and the provider is injected by the client. +@_spi(PluginMessage) public class CompilerPluginMessageHandler { /// Message channel for bidirectional communication with the plugin host. let connection: Connection diff --git a/Sources/SwiftCompilerPluginMessageHandling/Macros.swift b/Sources/SwiftCompilerPluginMessageHandling/Macros.swift index 4687cbb00ed..7f07fe1278c 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/Macros.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/Macros.swift @@ -14,7 +14,7 @@ import SwiftBasicFormat import SwiftDiagnostics import SwiftOperators import SwiftSyntax -@_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacroExpansion +@_spi(MacroExpansion) @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacroExpansion @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros extension CompilerPluginMessageHandler { diff --git a/Sources/SwiftCompilerPluginMessageHandling/PluginMessageCompatibility.swift b/Sources/SwiftCompilerPluginMessageHandling/PluginMessageCompatibility.swift index f3a264e2647..b231c758bb4 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/PluginMessageCompatibility.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/PluginMessageCompatibility.swift @@ -11,7 +11,8 @@ //===----------------------------------------------------------------------===// /// Old compiler might send '.declaration' as "freeStandingDeclaration". -@_spi(PluginMessage) public extension PluginMessage.MacroRole { +@_spi(PluginMessage) +public extension PluginMessage.MacroRole { init(from decoder: Decoder) throws { let stringValue = try decoder.singleValueContainer().decode(String.self) if let role = Self(rawValue: stringValue) { diff --git a/Sources/SwiftCompilerPluginMessageHandling/PluginMessages.swift b/Sources/SwiftCompilerPluginMessageHandling/PluginMessages.swift index da006ec77b2..aeb8e9bd9ae 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/PluginMessages.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/PluginMessages.swift @@ -12,6 +12,7 @@ // NOTE: Types in this file should be self-contained and should not depend on any non-stdlib types. +@_spi(PluginMessage) public enum HostToPluginMessage: Codable { /// Send capability of the host, and get capability of the plugin. case getCapability( @@ -49,6 +50,7 @@ public enum HostToPluginMessage: Codable { ) } +@_spi(PluginMessage) public enum PluginToHostMessage: Codable { case getCapabilityResult( capability: PluginMessage.PluginCapability @@ -78,6 +80,7 @@ public enum PluginToHostMessage: Codable { ) } +@_spi(PluginMessage) public enum PluginMessage { public static var PROTOCOL_VERSION_NUMBER: Int { 7 } // Pass extension protocol list From 31ea4211caefd649eebbe6cbd5d5454b2741228c Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Fri, 9 Feb 2024 11:42:58 -0800 Subject: [PATCH 2/2] Release notes for SPI MacroExpansion/PluginMessageHandling --- Release Notes/600.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Release Notes/600.md b/Release Notes/600.md index eb9fc8fe80a..073ed29d314 100644 --- a/Release Notes/600.md +++ b/Release Notes/600.md @@ -156,6 +156,11 @@ - Pull request: https://github.com/apple/swift-syntax/pull/2531 - Migration steps: Use `if case .backslash = triviaPiece` instead +- All symbols in `SwiftCompilerPluginMessageHandling` are now SPI + - Description: This module is only intended to be used from some internal components. Any other modules should not use them directly. + - Pull request: https://github.com/apple/swift-syntax/pull/2489 + - Migration steps: Stop using this module. + ## Template - *Affected API or two word description*