[SwiftParser] Move typed raw syntax nodes into SwiftParser - #3381
Open
rintaro wants to merge 1 commit into
Open
Conversation
rintaro
force-pushed
the
productize-raw-x-syntax
branch
4 times, most recently
from
July 18, 2026 18:01
fef7c63 to
d14adae
Compare
Member
Author
|
@swift-ci Please test |
rintaro
force-pushed
the
productize-raw-x-syntax
branch
from
July 18, 2026 22:05
d14adae to
f48659f
Compare
The typed `RawXXXSyntax` nodes and `RawSyntaxNodeProtocol` are only used while parsing, so move them from SwiftSyntax into SwiftParser as internal types. SwiftSyntax keeps only the untyped `RawSyntax`, exposing the handful of members the parser needs through the `@_spi(RawSyntax)` boundary. Making the raw nodes internal narrows SwiftSyntax's public surface and reduces compiled code size: the optimizer can drop the type metadata and protocol witness tables that public conformances must emit, and eliminate or specialize the raw node code that is no longer reachable across the module boundary. `validateLayout(layout:as:)` stays in SwiftSyntax and is still called from `RawSyntax.layout()`, but it no longer depends on the typed raw nodes. It matches each child's `RawSyntax.kind` against the kinds allowed for the expected syntax type by calling that type's `isKindOf(_ kind: SyntaxKind)`, an internal static method generated on every syntax node, base node, collection, and child-choice enum. The validator is handed the concrete type's `isKindOf`, so it is neither a `SyntaxProtocol` requirement nor part of the public API.
rintaro
force-pushed
the
productize-raw-x-syntax
branch
from
July 28, 2026 18:31
f48659f to
ff4b8f4
Compare
Member
Author
|
@swift-ci Please test |
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.
The typed
RawXXXSyntaxnodes andRawSyntaxNodeProtocolare only used while parsing, so move them from SwiftSyntax into SwiftParser as internal types. SwiftSyntax keeps only the untypedRawSyntax, exposing what the parser needs via the existing@_spi(RawSyntax)boundary. Making the raw nodes internal narrows SwiftSyntax's public API and reduces compiled size, since the optimizer can drop the metadata and witness tables that public conformances emit and eliminate code no longer reachable across the module boundary.validateLayout(layout:as:)has to stay in SwiftSyntax (it runs whenever a raw layout node is created), so instead of relying on the moved raw nodes it validates against the public syntax types: each type has an internalisKindOf(_ kind: SyntaxKind)static method (generated on every syntax node, base node, collection, and child-choice enum), and validation matches each child'sRawSyntax.kindagainst the kinds allowed for the expected type. The validator is handed the concrete type'sisKindOf, so this needs neither aSyntaxProtocolrequirement nor any public/SPI surface forisKindOf.Measured on a release build (
swift build -c release), SwiftSyntax's object code shrinks from 5.53 MB to 4.53 MB (−978 KB, −18%) — including ~205 KB less__DATA, which holds protocol witness tables and type metadata. SwiftParser grows from 1.28 MB to 1.53 MB (+243 KB) as it absorbs the internal raw nodes, for a net −735 KB (−11.1%) across the two modules.