Skip to content

[Macros] Use SwiftCompilerPluginMessageHandling JSON encoder/decoder #72999

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 2 commits into from
Apr 29, 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
10 changes: 1 addition & 9 deletions lib/ASTGen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
add_pure_swift_host_library(swiftLLVMJSON STATIC EMIT_MODULE
Sources/LLVMJSON/LLVMJSON.swift

DEPENDENCIES
swiftBasic
)

set(ASTGen_Swift_dependencies)

# If requested, build the regular expression parser into the compiler itself.
Expand Down Expand Up @@ -61,7 +54,6 @@ add_pure_swift_host_library(swiftASTGen STATIC
SwiftSyntaxBuilder
SwiftSyntaxMacros
SwiftSyntaxMacroExpansion
swiftLLVMJSON
${ASTGen_Swift_dependencies}
)

Expand Down Expand Up @@ -116,7 +108,7 @@ else()
endif()

if(SWIFT_BUILD_SWIFT_SYNTAX)
foreach(target swiftASTGen swiftLLVMJSON swiftIDEUtilsBridging)
foreach(target swiftASTGen swiftIDEUtilsBridging)
target_compile_options(${target} PRIVATE ${compile_options})
endforeach()
endif()
8 changes: 0 additions & 8 deletions lib/ASTGen/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ let package = Package(
],
products: [
.library(name: "swiftASTGen", targets: ["swiftASTGen"]),
.library(name: "swiftLLVMJSON", targets: ["swiftLLVMJSON"]),
],
dependencies: [
.package(path: "../../../swift-syntax")
Expand All @@ -68,7 +67,6 @@ let package = Package(
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
"swiftLLVMJSON",
"_CompilerRegexParser",
],
path: "Sources/ASTGen",
Expand All @@ -84,12 +82,6 @@ let package = Package(
path: "Sources/SwiftIDEUtilsBridging",
swiftSettings: swiftSetttings
),
.target(
name: "swiftLLVMJSON",
dependencies: [],
path: "Sources/LLVMJSON",
swiftSettings: swiftSetttings
),
.target(
name: "_CompilerRegexParser",
dependencies: [],
Expand Down
7 changes: 4 additions & 3 deletions lib/ASTGen/Sources/ASTGen/PluginHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ASTBridging
import BasicBridging
@_spi(PluginMessage) import SwiftCompilerPluginMessageHandling
import SwiftSyntax
import swiftLLVMJSON

enum PluginError: String, Error, CustomStringConvertible {
case stalePlugin = "plugin is stale"
Expand Down Expand Up @@ -117,7 +116,7 @@ struct CompilerPlugin {
}

private func sendMessage(_ message: HostToPluginMessage) throws {
let hadError = try LLVMJSON.encoding(message) { (data) -> Bool in
let hadError = try JSON.encode(message).withUnsafeBufferPointer { (data) -> Bool in
return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, count: data.count))
}
if hadError {
Expand All @@ -133,7 +132,9 @@ struct CompilerPlugin {
throw PluginError.failedToReceiveMessage
}
let data = UnsafeBufferPointer(start: result.baseAddress, count: result.count)
return try LLVMJSON.decode(PluginToHostMessage.self, from: data)
return try data.withMemoryRebound(to: UInt8.self) { buffer in
try JSON.decode(PluginToHostMessage.self, from: buffer)
}
}

func sendMessageAndWaitWithoutLock(_ message: HostToPluginMessage) throws -> PluginToHostMessage {
Expand Down
Loading