@@ -93,6 +93,18 @@ public struct SyntaxIndexInTree: Comparable, Hashable {
93
93
}
94
94
}
95
95
96
+ /// Uniquely identifies a syntax tree.
97
+ struct RootID : Hashable {
98
+ /// The pointer value of the root.
99
+ ///
100
+ /// Since the root ID might outlive the tree, it is not unsafe to access this.
101
+ private var id : UInt
102
+
103
+ fileprivate init ( _ pointer: UnsafeRawPointer ) {
104
+ self . id = UInt ( bitPattern: pointer)
105
+ }
106
+ }
107
+
96
108
/// Provides a stable and unique identity for ``Syntax`` nodes.
97
109
///
98
110
/// Note that two nodes might have the same contents even if their IDs are
@@ -111,7 +123,7 @@ public struct SyntaxIdentifier: Hashable {
111
123
/// same instance. This guarantees that the trees with the same 'rootId' have
112
124
/// exact the same structure. But, two trees with exactly the same structure
113
125
/// might still have different 'rootId's.
114
- let rootId : UInt
126
+ let rootId : RootID
115
127
/// Unique value for a node within its own tree.
116
128
@_spi ( RawSyntax)
117
129
public let indexInTree : SyntaxIndexInTree
@@ -128,7 +140,7 @@ public struct SyntaxIdentifier: Hashable {
128
140
129
141
static func forRoot( _ raw: RawSyntax ) -> SyntaxIdentifier {
130
142
return . init(
131
- rootId: UInt ( bitPattern : raw. pointer) ,
143
+ rootId: RootID ( raw. pointer) ,
132
144
indexInTree: . zero
133
145
)
134
146
}
@@ -163,7 +175,7 @@ struct AbsoluteRawSyntax {
163
175
return nil
164
176
}
165
177
166
- func replacingSelf( _ newRaw: RawSyntax , newRootId: UInt ) -> AbsoluteRawSyntax {
178
+ func replacingSelf( _ newRaw: RawSyntax , newRootId: RootID ) -> AbsoluteRawSyntax {
167
179
let nodeId = SyntaxIdentifier ( rootId: newRootId, indexInTree: info. nodeId. indexInTree)
168
180
let newInfo = AbsoluteSyntaxInfo ( position: info. position, nodeId: nodeId)
169
181
return . init( raw: newRaw, info: newInfo)
0 commit comments