Skip to content

[SwiftParser] Move typed raw syntax nodes into SwiftParser#3381

Open
rintaro wants to merge 1 commit into
swiftlang:mainfrom
rintaro:productize-raw-x-syntax
Open

[SwiftParser] Move typed raw syntax nodes into SwiftParser#3381
rintaro wants to merge 1 commit into
swiftlang:mainfrom
rintaro:productize-raw-x-syntax

Conversation

@rintaro

@rintaro rintaro commented Jul 13, 2026

Copy link
Copy Markdown
Member

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 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 now validates against the public syntax types through a new SyntaxProtocol.isKindOf(_ kind: SyntaxKind) requirement, matching each child's RawSyntax.kind against the kinds allowed for the corresponding type.

@rintaro rintaro force-pushed the productize-raw-x-syntax branch from 5805256 to ee80394 Compare July 13, 2026 21:54
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. Validation is expressed against the public syntax types via a
new `SyntaxProtocol.isKindOf(_ kind: SyntaxKind)` requirement, so it
matches each child's `RawSyntax.kind` against the kinds allowed for
the corresponding syntax type. Every generated syntax node, base
node, collection, and child-choice enum implements `isKindOf`, and the
two synthetic conformers in SwiftLexicalLookup implement it to mirror
their `init?`.

The code generator emits the raw node files into SwiftParser, and the
`RawSyntaxNodesFile` template produces internal declarations.
@rintaro rintaro force-pushed the productize-raw-x-syntax branch from ee80394 to 22efb50 Compare July 13, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant