Skip to content

Commit cd54cc1

Browse files
committed
[Macros] Use SwiftCompilerPluginMessageHandling JSON encoder/decoder
Replacing swiftLLVMSJON with SwiftCompilerPluginMessageHandling.JSON
1 parent 03786da commit cd54cc1

File tree

7 files changed

+15
-904
lines changed

7 files changed

+15
-904
lines changed

lib/ASTGen/CMakeLists.txt

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
add_pure_swift_host_library(swiftLLVMJSON STATIC EMIT_MODULE
2-
Sources/LLVMJSON/LLVMJSON.swift
3-
4-
DEPENDENCIES
5-
swiftBasic
6-
)
7-
81
set(ASTGen_Swift_dependencies)
92

103
# If requested, build the regular expression parser into the compiler itself.
@@ -61,7 +54,6 @@ add_pure_swift_host_library(swiftASTGen STATIC
6154
SwiftSyntaxBuilder
6255
SwiftSyntaxMacros
6356
SwiftSyntaxMacroExpansion
64-
swiftLLVMJSON
6557
${ASTGen_Swift_dependencies}
6658
)
6759

@@ -116,7 +108,7 @@ else()
116108
endif()
117109

118110
if(SWIFT_BUILD_SWIFT_SYNTAX)
119-
foreach(target swiftASTGen swiftLLVMJSON swiftIDEUtilsBridging)
111+
foreach(target swiftASTGen swiftIDEUtilsBridging)
120112
target_compile_options(${target} PRIVATE ${compile_options})
121113
endforeach()
122114
endif()

lib/ASTGen/Package.swift

-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ let package = Package(
4949
],
5050
products: [
5151
.library(name: "swiftASTGen", targets: ["swiftASTGen"]),
52-
.library(name: "swiftLLVMJSON", targets: ["swiftLLVMJSON"]),
5352
],
5453
dependencies: [
5554
.package(path: "../../../swift-syntax")
@@ -68,7 +67,6 @@ let package = Package(
6867
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
6968
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
7069
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
71-
"swiftLLVMJSON",
7270
"_CompilerRegexParser",
7371
],
7472
path: "Sources/ASTGen",
@@ -84,12 +82,6 @@ let package = Package(
8482
path: "Sources/SwiftIDEUtilsBridging",
8583
swiftSettings: swiftSetttings
8684
),
87-
.target(
88-
name: "swiftLLVMJSON",
89-
dependencies: [],
90-
path: "Sources/LLVMJSON",
91-
swiftSettings: swiftSetttings
92-
),
9385
.target(
9486
name: "_CompilerRegexParser",
9587
dependencies: [],

lib/ASTGen/Sources/ASTGen/PluginHost.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import ASTBridging
1414
import BasicBridging
1515
@_spi(PluginMessage) import SwiftCompilerPluginMessageHandling
1616
import SwiftSyntax
17-
import swiftLLVMJSON
1817

1918
enum PluginError: String, Error, CustomStringConvertible {
2019
case stalePlugin = "plugin is stale"
@@ -117,7 +116,7 @@ struct CompilerPlugin {
117116
}
118117

119118
private func sendMessage(_ message: HostToPluginMessage) throws {
120-
let hadError = try LLVMJSON.encoding(message) { (data) -> Bool in
119+
let hadError = try JSON.encode(message).withUnsafeBufferPointer { (data) -> Bool in
121120
return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, count: data.count))
122121
}
123122
if hadError {
@@ -133,7 +132,9 @@ struct CompilerPlugin {
133132
throw PluginError.failedToReceiveMessage
134133
}
135134
let data = UnsafeBufferPointer(start: result.baseAddress, count: result.count)
136-
return try LLVMJSON.decode(PluginToHostMessage.self, from: data)
135+
return try data.withMemoryRebound(to: UInt8.self) { buffer in
136+
try JSON.decode(PluginToHostMessage.self, from: buffer)
137+
}
137138
}
138139

139140
func sendMessageAndWaitWithoutLock(_ message: HostToPluginMessage) throws -> PluginToHostMessage {

0 commit comments

Comments
 (0)