Skip to content

Commit 3ee9d14

Browse files
committed
Make underlying data structures of SyntaxData.Info classes insted of structs
This will allow us to add more data to `SyntaxData.Info.Root` without increasing the size of `SyntaxData`. It shouldn’t have a big performance impact at the moment since `Root.arena` is never accessed and only exists to keep `arena` a live.
1 parent 9902575 commit 3ee9d14

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Sources/SwiftSyntax/SyntaxData.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,28 @@ struct AbsoluteRawSyntax {
189189
struct SyntaxData {
190190
fileprivate enum Info {
191191
case root(Root)
192-
indirect case nonRoot(NonRoot)
192+
case nonRoot(NonRoot)
193193

194194
// For root node.
195-
struct Root {
195+
class Root {
196196
var arena: SyntaxArena
197+
198+
init(arena: SyntaxArena) {
199+
self.arena = arena
200+
}
197201
}
198202

199203
// For non-root nodes.
200-
struct NonRoot {
204+
class NonRoot {
201205
var parent: SyntaxData
202206
var absoluteInfo: AbsoluteSyntaxInfo
207+
unowned(unsafe) var rootInfo: Root
208+
209+
init(parent: SyntaxData, absoluteInfo: AbsoluteSyntaxInfo, rootInfo: __shared Root) {
210+
self.parent = parent
211+
self.absoluteInfo = absoluteInfo
212+
self.rootInfo = rootInfo
213+
}
203214
}
204215
}
205216

@@ -209,7 +220,7 @@ struct SyntaxData {
209220
private var rootInfo: Info.Root {
210221
switch info {
211222
case .root(let info): return info
212-
case .nonRoot(let info): return info.parent.rootInfo
223+
case .nonRoot(let info): return info.rootInfo
213224
}
214225
}
215226

@@ -274,7 +285,7 @@ struct SyntaxData {
274285
}
275286

276287
init(_ raw: RawSyntax, parent: SyntaxData, absoluteInfo: AbsoluteSyntaxInfo) {
277-
self.init(raw, info: .nonRoot(.init(parent: parent, absoluteInfo: absoluteInfo)))
288+
self.init(raw, info: .nonRoot(.init(parent: parent, absoluteInfo: absoluteInfo, rootInfo: parent.rootInfo)))
278289
}
279290

280291
/// Creates a `SyntaxData` with the provided raw syntax and parent.

0 commit comments

Comments
 (0)