Skip to content

Commit 63ff9d3

Browse files
committed
Use RawSyntax address as the 'rootId' of SyntaxIdentifier
We don't need to guarantee the uniqueness throughout the process lifetime. but only need to guarantee the uniqueness while the object is alive. This removes `_CSwiftSyntax` dependency from `SwiftSyntax` module.
1 parent 8c76dc3 commit 63ff9d3

File tree

8 files changed

+12
-42
lines changed

8 files changed

+12
-42
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let package = Package(
6464
),
6565
.target(
6666
name: "SwiftSyntax",
67-
dependencies: ["_CSwiftSyntax"],
67+
dependencies: [],
6868
exclude: [
6969
"Misc.swift.gyb",
7070
"Raw/RawSyntaxNodes.swift.gyb",
@@ -96,7 +96,7 @@ let package = Package(
9696
),
9797
.target(
9898
name: "SwiftSyntaxParser",
99-
dependencies: ["SwiftSyntax"],
99+
dependencies: ["SwiftSyntax", "_CSwiftSyntax"],
100100
exclude: [
101101
"NodeDeclarationHash.swift.gyb",
102102
"Serialization.swift.gyb",

Sources/SwiftSyntax/AtomicCounter.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/SwiftSyntax/SyntaxChildren.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public struct SyntaxChildrenIndex: Comparable, ExpressibleByNilLiteral {
9191

9292
fileprivate extension AbsoluteSyntaxInfo {
9393
/// Construct `AbsoluteSyntaxInfo` from the given index data and a `rootId`.
94-
init(index: SyntaxChildrenIndexData, rootId: UInt32) {
94+
init(index: SyntaxChildrenIndexData, rootId: UInt) {
9595
let position = AbsoluteSyntaxPosition(offset: index.offset,
9696
indexInParent: index.indexInParent)
9797
let identifier = SyntaxIdentifier(rootId: rootId,
@@ -137,7 +137,7 @@ struct RawSyntaxChildren: BidirectionalCollection {
137137
}
138138

139139
/// The rootId of the tree the child nodes belong to
140-
private let rootId: UInt32
140+
private let rootId: UInt
141141
/// The number of childer in `parent`. Cached to avoid reaching into `parent` for every index
142142
/// advancement
143143
// FIXME: Do we need this cached?

Sources/SwiftSyntax/SyntaxData.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct AbsoluteSyntaxInfo {
6464
return .init(position: newPosition, nodeId: newNodeId)
6565
}
6666

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))
6969
}
7070
}
7171

@@ -104,7 +104,7 @@ struct SyntaxIndexInTree: Hashable {
104104
/// Provides a stable and unique identity for `Syntax` nodes.
105105
public struct SyntaxIdentifier: Hashable {
106106
/// Unique value for each root node created.
107-
let rootId: UInt32
107+
let rootId: UInt
108108
/// Unique value for a node within its own tree.
109109
let indexInTree: SyntaxIndexInTree
110110

@@ -123,8 +123,8 @@ public struct SyntaxIdentifier: Hashable {
123123
return .init(rootId: self.rootId, indexInTree: newIndexInTree)
124124
}
125125

126-
static func newRoot() -> SyntaxIdentifier {
127-
return .init(rootId: UInt32(truncatingIfNeeded: AtomicCounter.next()),
126+
static func forRoot(_ raw: RawSyntax) -> SyntaxIdentifier {
127+
return .init(rootId: UInt(bitPattern: raw.pointer),
128128
indexInTree: .zero)
129129
}
130130
}
@@ -168,14 +168,14 @@ struct AbsoluteRawSyntax {
168168
return nil
169169
}
170170

171-
func replacingSelf(_ newRaw: RawSyntax, newRootId: UInt32) -> AbsoluteRawSyntax {
171+
func replacingSelf(_ newRaw: RawSyntax, newRootId: UInt) -> AbsoluteRawSyntax {
172172
let nodeId = SyntaxIdentifier(rootId: newRootId, indexInTree: info.nodeId.indexInTree)
173173
let newInfo = AbsoluteSyntaxInfo(position: info.position, nodeId: nodeId)
174174
return .init(raw: newRaw, info: newInfo)
175175
}
176176

177177
static func forRoot(_ raw: RawSyntax) -> AbsoluteRawSyntax {
178-
return .init(raw: raw, info: .forRoot)
178+
return .init(raw: raw, info: .forRoot(raw))
179179
}
180180
}
181181

Sources/_CSwiftSyntax/include/atomic-counter.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

Sources/_CSwiftSyntax/src/atomic-counter.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

Sources/_CSwiftSyntax/src/dummy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

utils/group.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
],
5454
"Internal": [
5555
"SyntaxArena.swift",
56-
"AtomicCounter.swift",
5756
"SyntaxVerifier.swift",
5857
"BumpPtrAllocator.swift",
5958
]

0 commit comments

Comments
 (0)