@@ -64,8 +64,8 @@ struct AbsoluteSyntaxInfo {
64
64
return . init( position: newPosition, nodeId: newNodeId)
65
65
}
66
66
67
- static var forRoot : AbsoluteSyntaxInfo {
68
- return . init( position: . forRoot, nodeId: . newRoot ( ) )
67
+ static func forRoot( _ raw : RawSyntax ) -> AbsoluteSyntaxInfo {
68
+ return . init( position: . forRoot, nodeId: . forRoot ( raw ) )
69
69
}
70
70
}
71
71
@@ -103,8 +103,13 @@ struct SyntaxIndexInTree: Hashable {
103
103
104
104
/// Provides a stable and unique identity for `Syntax` nodes.
105
105
public struct SyntaxIdentifier : Hashable {
106
- /// Unique value for each root node created.
107
- let rootId : UInt32
106
+ /// Unique value for the root node.
107
+ ///
108
+ /// Multiple trees may have the same 'rootId' if their root RawSyntax is the
109
+ /// same instance. This guarantees that the trees with the same 'rootId' have
110
+ /// exact the same structure. But, two trees with exactly the same structure
111
+ /// might still have different 'rootId's.
112
+ let rootId : UInt
108
113
/// Unique value for a node within its own tree.
109
114
let indexInTree : SyntaxIndexInTree
110
115
@@ -123,8 +128,8 @@ public struct SyntaxIdentifier: Hashable {
123
128
return . init( rootId: self . rootId, indexInTree: newIndexInTree)
124
129
}
125
130
126
- static func newRoot ( ) -> SyntaxIdentifier {
127
- return . init( rootId: UInt32 ( truncatingIfNeeded : AtomicCounter . next ( ) ) ,
131
+ static func forRoot ( _ raw : RawSyntax ) -> SyntaxIdentifier {
132
+ return . init( rootId: UInt ( bitPattern : raw . pointer ) ,
128
133
indexInTree: . zero)
129
134
}
130
135
}
@@ -168,14 +173,14 @@ struct AbsoluteRawSyntax {
168
173
return nil
169
174
}
170
175
171
- func replacingSelf( _ newRaw: RawSyntax , newRootId: UInt32 ) -> AbsoluteRawSyntax {
176
+ func replacingSelf( _ newRaw: RawSyntax , newRootId: UInt ) -> AbsoluteRawSyntax {
172
177
let nodeId = SyntaxIdentifier ( rootId: newRootId, indexInTree: info. nodeId. indexInTree)
173
178
let newInfo = AbsoluteSyntaxInfo ( position: info. position, nodeId: nodeId)
174
179
return . init( raw: newRaw, info: newInfo)
175
180
}
176
181
177
182
static func forRoot( _ raw: RawSyntax ) -> AbsoluteRawSyntax {
178
- return . init( raw: raw, info: . forRoot)
183
+ return . init( raw: raw, info: . forRoot( raw ) )
179
184
}
180
185
}
181
186
0 commit comments