Skip to content

Commit fc47c7b

Browse files
committed
Mark static properties in JSONReference as nonisolated(unsafe)
1 parent 99433ce commit fc47c7b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/SwiftCompilerPluginMessageHandling/JSON/JSONEncoding.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func encodeToJSON(value: some Encodable) throws -> [UInt8] {
1717
}
1818

1919
/// Intermediate representation for serializing JSON structure.
20-
private class JSONReference {
20+
private final class JSONReference {
2121
enum Backing {
2222
case null
2323
case trueKeyword
@@ -60,9 +60,17 @@ private class JSONReference {
6060
backing = .array(arr)
6161
}
6262

63+
#if swift(>=6)
64+
// nonisolated(unsafe) is fine for these properties because they represent primitives
65+
// that are never modified.
66+
nonisolated(unsafe) static let null: JSONReference = .init(backing: .null)
67+
nonisolated(unsafe) static let trueKeyword: JSONReference = .init(backing: .trueKeyword)
68+
nonisolated(unsafe) static let falseKeyword: JSONReference = .init(backing: .falseKeyword)
69+
#else
6370
static let null: JSONReference = .init(backing: .null)
6471
static let trueKeyword: JSONReference = .init(backing: .trueKeyword)
6572
static let falseKeyword: JSONReference = .init(backing: .falseKeyword)
73+
#endif
6674

6775
@inline(__always)
6876
static func newArray() -> JSONReference {

0 commit comments

Comments
 (0)