Repository navigation
[SwiftSyntax] Keep one 32-bit size accessor per raw node - #3462
Merged
Merged
Conversation
A raw node's byte length and node count had two accessors each: an `Int` one and a `UInt32` one, each switching over the node's shape on its own. Keep only the `UInt32` ones, as `byteLength` and `totalNodes`, which is the width a layout node stores and sums them in, and widen where an `Int` is wanted: a `SourceLength`, an array's capacity, slab sizing, `RawTokenSyntax.byteLength` and the syntax classifier. The public lengths and positions of the `Syntax` layer stay `Int`. `AbsoluteSyntaxInfo.advancedBySibling`, which runs for every child of every node a tree walk reaches, adds them as they are rather than widening each one to `Int` to narrow it again. Its `&+` cannot overflow because `makeLayout` builds both sums with checked additions in the same width, so the root's two preconditions, which could no longer fail, are removed. A layout node stores its node count with itself included, as `nodeCount`, rather than its descendant count, so `totalNodes` is a load rather than an addition on every child of a walk.
rintaro
requested review from
hamishknight,
hborla and
nkcsgexi
as code owners
October 5, 2026 17:46
Member
Author
|
@swift-ci Please test |
hamishknight
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remove
Intversion ofRawSyntax.byteLengthandRawSyntax.totalNodesand keep onlyUInt32ones.Since nothing was using
Layout.decendantCountas-is, it now stores its node count with itself included, asnodeCountso walking the tree don't need+1arthemic anymore.Perf neutral, within +-0.15% for parsing and reading.