Skip to content

Commit e028933

Browse files
committed
[Macros] Use SwiftCompilerPluginMessageHandling JSON encoder/decoder
Replacing swiftLLVMSJON with SwiftCompilerPluginMessageHandling.JSON
1 parent bdb32c9 commit e028933

File tree

7 files changed

+17
-906
lines changed

7 files changed

+17
-906
lines changed

lib/ASTGen/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
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

@@ -117,7 +109,7 @@ set(compile_options
117109
)
118110

119111
if(SWIFT_BUILD_SWIFT_SYNTAX)
120-
foreach(target swiftASTGen swiftLLVMJSON swiftIDEUtilsBridging)
112+
foreach(target swiftASTGen swiftIDEUtilsBridging)
121113
target_compile_options(${target} PRIVATE ${compile_options})
122114
endforeach()
123115
endif()

lib/ASTGen/Package.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ let package = Package(
4444
],
4545
products: [
4646
.library(name: "swiftASTGen", targets: ["swiftASTGen"]),
47-
.library(name: "swiftLLVMJSON", targets: ["swiftLLVMJSON"]),
4847
],
4948
dependencies: [
5049
.package(path: "../../../swift-syntax")
@@ -63,7 +62,6 @@ let package = Package(
6362
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
6463
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
6564
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
66-
"swiftLLVMJSON",
6765
"_CompilerRegexParser",
6866
],
6967
path: "Sources/ASTGen",
@@ -79,12 +77,6 @@ let package = Package(
7977
path: "Sources/SwiftIDEUtilsBridging",
8078
swiftSettings: swiftSetttings
8179
),
82-
.target(
83-
name: "swiftLLVMJSON",
84-
dependencies: [],
85-
path: "Sources/LLVMJSON",
86-
swiftSettings: swiftSetttings
87-
),
8880
.target(
8981
name: "_CompilerRegexParser",
9082
dependencies: [],

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
import ASTBridging
1414
import BasicBridging
15-
import SwiftCompilerPluginMessageHandling
15+
@_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)