[SwiftParser] Move typed raw syntax nodes into SwiftParser#3381
Open
rintaro wants to merge 1 commit into
Open
Conversation
5805256 to
ee80394
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. 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.
ee80394 to
22efb50
Compare
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 now validates against the public syntax types through a newSyntaxProtocol.isKindOf(_ kind: SyntaxKind)requirement, matching each child'sRawSyntax.kindagainst the kinds allowed for the corresponding type.