Skip to content

Use RawSyntax address as the 'rootId' of SyntaxIdentifier #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let package = Package(
),
.target(
name: "SwiftSyntax",
dependencies: ["_CSwiftSyntax"],
dependencies: [],
exclude: [
"Misc.swift.gyb",
"Raw/RawSyntaxNodes.swift.gyb",
Expand Down Expand Up @@ -96,7 +96,7 @@ let package = Package(
),
.target(
name: "SwiftSyntaxParser",
dependencies: ["SwiftSyntax"],
dependencies: ["SwiftSyntax", "_CSwiftSyntax"],
exclude: [
"NodeDeclarationHash.swift.gyb",
"Serialization.swift.gyb",
Expand Down
21 changes: 0 additions & 21 deletions Sources/SwiftSyntax/AtomicCounter.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/SyntaxChildren.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public struct SyntaxChildrenIndex: Comparable, ExpressibleByNilLiteral {

fileprivate extension AbsoluteSyntaxInfo {
/// Construct `AbsoluteSyntaxInfo` from the given index data and a `rootId`.
init(index: SyntaxChildrenIndexData, rootId: UInt32) {
init(index: SyntaxChildrenIndexData, rootId: UInt) {
let position = AbsoluteSyntaxPosition(offset: index.offset,
indexInParent: index.indexInParent)
let identifier = SyntaxIdentifier(rootId: rootId,
Expand Down Expand Up @@ -137,7 +137,7 @@ struct RawSyntaxChildren: BidirectionalCollection {
}

/// The rootId of the tree the child nodes belong to
private let rootId: UInt32
private let rootId: UInt
/// The number of childer in `parent`. Cached to avoid reaching into `parent` for every index
/// advancement
// FIXME: Do we need this cached?
Expand Down
14 changes: 7 additions & 7 deletions Sources/SwiftSyntax/SyntaxData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ struct AbsoluteSyntaxInfo {
return .init(position: newPosition, nodeId: newNodeId)
}

static var forRoot: AbsoluteSyntaxInfo {
return .init(position: .forRoot, nodeId: .newRoot())
static func forRoot(_ raw: RawSyntax) -> AbsoluteSyntaxInfo {
return .init(position: .forRoot, nodeId: .forRoot(raw))
}
}

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

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

static func newRoot() -> SyntaxIdentifier {
return .init(rootId: UInt32(truncatingIfNeeded: AtomicCounter.next()),
static func forRoot(_ raw: RawSyntax) -> SyntaxIdentifier {
return .init(rootId: UInt(bitPattern: raw.pointer),
indexInTree: .zero)
}
}
Expand Down Expand Up @@ -168,14 +168,14 @@ struct AbsoluteRawSyntax {
return nil
}

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

static func forRoot(_ raw: RawSyntax) -> AbsoluteRawSyntax {
return .init(raw: raw, info: .forRoot)
return .init(raw: raw, info: .forRoot(raw))
}
}

Expand Down
3 changes: 0 additions & 3 deletions Sources/_CSwiftSyntax/include/atomic-counter.h

This file was deleted.

6 changes: 0 additions & 6 deletions Sources/_CSwiftSyntax/src/atomic-counter.c

This file was deleted.

1 change: 1 addition & 0 deletions Sources/_CSwiftSyntax/src/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion utils/group.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
],
"Internal": [
"SyntaxArena.swift",
"AtomicCounter.swift",
"SyntaxVerifier.swift",
"BumpPtrAllocator.swift",
]
Expand Down