Skip to content

Commit 20d083d

Browse files
authored
Merge pull request swiftlang#635 from rintaro/nodeid-rawsyntaxaddr
Use RawSyntax address as the 'rootId' of SyntaxIdentifier
2 parents b04d774 + 63ff9d3 commit 20d083d

File tree

8 files changed

+12
-42
lines changed

8 files changed

+12
-42
lines changed

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ let package = Package(
6868
),
6969
.target(
7070
name: "SwiftSyntax",
71-
dependencies: ["_CSwiftSyntax"],
71+
dependencies: [],
7272
exclude: [
7373
"CMakeLists.txt",
7474
"Misc.swift.gyb",
@@ -101,7 +101,7 @@ let package = Package(
101101
),
102102
.target(
103103
name: "SwiftSyntaxParser",
104-
dependencies: ["SwiftSyntax"],
104+
dependencies: ["SwiftSyntax", "_CSwiftSyntax"],
105105
exclude: [
106106
"NodeDeclarationHash.swift.gyb",
107107
"Serialization.swift.gyb",

Sources/SwiftSyntax/AtomicCounter.swift

-21
This file was deleted.

Sources/SwiftSyntax/SyntaxChildren.swift

+2-2
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

+7-7
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

-3
This file was deleted.

Sources/_CSwiftSyntax/src/atomic-counter.c

-6
This file was deleted.

Sources/_CSwiftSyntax/src/dummy.c

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

utils/group.json

-1
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)