Skip to content

Commit

Permalink
Make underlying data structures of SyntaxData.Info classes insted o…
Browse files Browse the repository at this point in the history
…f 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.
  • Loading branch information
ahoppen committed Aug 29, 2023
1 parent 9902575 commit 3ee9d14
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Sources/SwiftSyntax/SyntaxData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,28 @@ struct AbsoluteRawSyntax {
struct SyntaxData {
fileprivate enum Info {
case root(Root)
indirect case nonRoot(NonRoot)
case nonRoot(NonRoot)

// For root node.
struct Root {
class Root {
var arena: SyntaxArena

init(arena: SyntaxArena) {
self.arena = arena
}
}

// For non-root nodes.
struct NonRoot {
class NonRoot {
var parent: SyntaxData
var absoluteInfo: AbsoluteSyntaxInfo
unowned(unsafe) var rootInfo: Root

init(parent: SyntaxData, absoluteInfo: AbsoluteSyntaxInfo, rootInfo: __shared Root) {
self.parent = parent
self.absoluteInfo = absoluteInfo
self.rootInfo = rootInfo
}
}
}

Expand All @@ -209,7 +220,7 @@ struct SyntaxData {
private var rootInfo: Info.Root {
switch info {
case .root(let info): return info
case .nonRoot(let info): return info.parent.rootInfo
case .nonRoot(let info): return info.rootInfo
}
}

Expand Down Expand Up @@ -274,7 +285,7 @@ struct SyntaxData {
}

init(_ raw: RawSyntax, parent: SyntaxData, absoluteInfo: AbsoluteSyntaxInfo) {
self.init(raw, info: .nonRoot(.init(parent: parent, absoluteInfo: absoluteInfo)))
self.init(raw, info: .nonRoot(.init(parent: parent, absoluteInfo: absoluteInfo, rootInfo: parent.rootInfo)))
}

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

0 comments on commit 3ee9d14

Please sign in to comment.