Skip to content

Commit 3883e3c

Browse files
committed
[Syntax] Let SyntaxIdentifier use RawSyntax.ID directly
There was no reason to convert it to UInt.
1 parent 37fa0c8 commit 3883e3c

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

Sources/SwiftSyntax/Raw/RawSyntax.swift

-7
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,6 @@ extension RawSyntax: Identifiable {
965965
}
966966
}
967967

968-
extension UInt {
969-
/// Convert `RawSymtax.ID` to `UInt`. Lossless.
970-
init(rawID: RawSyntax.ID) {
971-
self.init(bitPattern: rawID.pointer)
972-
}
973-
}
974-
975968
/// See `SyntaxMemoryLayout`.
976969
let RawSyntaxDataMemoryLayouts: [String: SyntaxMemoryLayout.Value] = [
977970
"RawSyntaxData": .init(RawSyntaxData.self),

Sources/SwiftSyntax/Syntax.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
7676
// This var is a workaround for a potential compiler bug (rdar://141977987)
7777
let rootDataRef = arena.root
7878
return SyntaxIdentifier(
79-
rootId: UInt(rawID: rootDataRef.pointee.raw.id),
79+
rootId: rootDataRef.pointee.raw.id,
8080
indexInTree: SyntaxIdentifier.SyntaxIndexInTree(indexInTree: absoluteInfo.indexInTree)
8181
)
8282
}

Sources/SwiftSyntax/SyntaxIdentifier.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public struct SyntaxIdentifier: Comparable, Hashable, Sendable {
5555
/// same instance. This guarantees that the trees with the same 'rootId' have
5656
/// exact the same structure. But, two trees with exactly the same structure
5757
/// might still have different 'rootId's.
58-
let rootId: UInt
58+
let rootId: RawSyntax.ID
5959

6060
/// Unique value for a node within its own tree.
6161
public let indexInTree: SyntaxIndexInTree
@@ -81,7 +81,7 @@ public struct SyntaxIdentifier: Comparable, Hashable, Sendable {
8181
return nil
8282
}
8383

84-
return SyntaxIdentifier(rootId: UInt(rawID: root.raw.id), indexInTree: indexInTree)
84+
return SyntaxIdentifier(rootId: root.raw.id, indexInTree: indexInTree)
8585
}
8686

8787
/// A ``SyntaxIdentifier`` compares less than another ``SyntaxIdentifier`` if the node at that identifier occurs first

Sources/SwiftSyntax/SyntaxProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ extension SyntaxProtocol {
364364
/// ``SyntaxIdentifier``) or if no node with the given identifier is a child of this syntax node, returns `nil`.
365365
public func node(at syntaxIdentifier: SyntaxIdentifier) -> Syntax? {
366366
let syntax = Syntax(self)
367-
guard UInt(rawID: syntax.raw.id) == syntaxIdentifier.rootId else {
367+
guard syntax.raw.id == syntaxIdentifier.rootId else {
368368
return nil
369369
}
370370

0 commit comments

Comments
 (0)