Repository navigation
Conversation
rintaro
force-pushed
the
syntaxlayout
branch
2 times, most recently
from
September 10, 2024 13:46
a8678db to
0ae17dc
Compare
Member
Author
|
@swift-ci Please test |
rintaro
marked this pull request as ready for review
September 10, 2024 14:38
rintaro
force-pushed
the
syntaxlayout
branch
from
September 10, 2024 16:44
0ae17dc to
3251c22
Compare
Member
Author
|
@swift-ci Please test |
rintaro
force-pushed
the
syntaxlayout
branch
7 times, most recently
from
January 21, 2025 17:20
341f740 to
bcf256e
Compare
This replaces most use case of `keyPathInParent` and `SyntaxNodeStructure.layout`. Since getting and comparing `KeyPath` is not trivial, `keyPathInParent` were suffered from performance issue, Newly introduced `SyntaxProtocol.propertyInParent` is trivial, and comparing it with a SyntaxLayoutProperty is also trivial.
'debugInitCall' handles collections by opening 'any SyntaxCollection', which yields elements typed as the collection's 'Element' and so no longer needs the element metatype from '.collection'. For layout nodes it walks the children and identifies each slot with 'propertyInParent'. Only a child declared as a 'SyntaxChildChoices' type has to be wrapped in that type to be passed to the parent's initializer; a child declared as a base type is taken as 'some XSyntaxProtocol' and is now emitted unwrapped. The generated 'childChoicesTypeName' names the types that do need wrapping. 'swift-parser-cli' enumerated the parseable node types by walking the '.choices' of 'Syntax.structure'. It now uses 'syntaxParseableTypes', which additionally covers the base types and the parseable collections.
…ition Building with '-DSWIFTSYNTAX_NO_STRUCTURE_REFLECTION' drops 'SyntaxProtocol.structure', 'SyntaxProtocol.keyPathInParent' and 'SyntaxNodeStructure'. Clients that don't reflect over the static shape of a node no longer pay for the key path literals and the metatype arrays that back them: SwiftSyntax's object code shrinks by 1.87 MB (9.5%) and a binary linking SwiftSyntax, SwiftParser, SwiftBasicFormat, SwiftIDEUtils and SwiftParserDiagnostics loses 311 KB of '__TEXT' (6.8%).
'Syntax.parent' builds a 'Syntax', which retains and releases the arena. '-O' pairs that up and removes it, but '-Onone' does not: reading 'dataRef.pointee.parent' instead takes the getter from 172 instructions and 5 'swift_release' calls down to 101 and 3, and leaves the '-O' code byte-identical. Reading through 'dataRef' also avoids the 'Syntax.data' accessor, whose 'mark_dependence' on a copy of 'Syntax' fails SIL verification in 'OSSACompleteLifetime' at '-O'. The one remaining 'swift_release' per call is the arena reference that the '_syntaxNode' witness returns owned, on each of the two exit paths.
… ARC '_syntaxNode' is a property requirement returning 'Syntax', so its witness hands back an owned value and every caller balances a retain with a release. The new requirement returns 'SyntaxDataRef', which is trivial and therefore has no ownership convention at all, so no witness can imply ARC. Each node type satisfies it by borrowing the trivial reference out of its stored '_syntaxNode'. 'propertyInParent' reads it instead of building a 'Syntax': 33 instructions and one 'swift_release' per call become 28 and none. Conforming types must now be able to see 'SyntaxDataRef', so a module that conforms to 'SyntaxProtocol' has to import SwiftSyntax with '@_spi(RawSyntax)'. The default implementation covers conformances that don't provide the property themselves, but only once that import is in place.
rintaro
requested review from
hamishknight,
hborla,
nkcsgexi and
xedin
as code owners
October 23, 2026 13:34
rintaro
marked this pull request as draft
October 23, 2026 13:34
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.
Types:
SyntaxLayout<T>: represents the layout of theTsyntax layout typeSyntaxLayoutProperty: represents an element in SyntaxLayout. likeAnyKeyPathConcreteSyntaxProperty<Base, Value>: represent a typed property. likeKeyPath<Root, Value>API:
_LeafSyntaxNodeProtocol.syntaxKindto get the syntax kind from the meta type._LayoutSyntaxNodeProtocolprotocol for non-collection leaf syntax nodes_LayoutSyntaxNodeProtocol.layoutto get the layout (SyntaxLayout<Self>)Usage:
This is faster than
keyPathInParentand comparingKeyPath. Combined with #2842,BasicFormatperforms 30% faster