Skip to content

unified: Add Swift node type schema generator - #22459

Open
tausbn wants to merge 2 commits into
mainfrom
tausbn/unified-add-swift-node-type-generator
Open

unified: Add Swift node type schema generator#22459
tausbn wants to merge 2 commits into
mainfrom
tausbn/unified-add-swift-node-type-generator

Conversation

@tausbn

@tausbn tausbn commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Adds tooling for automatically updating swift_node_types.yml when new versions of swift-syntax are released.

NB: I have not tested this process on macOS, but I have confirmed that it works well on Codespaces.

Adds the SwiftSyntax-based schemagen tool and a manual wrapper for
regenerating swift_node_types.yml after dependency updates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Aug 28, 2026
@tausbn
tausbn marked this pull request as ready for review August 28, 2026 13:22
@tausbn
tausbn requested review from a team as code owners August 28, 2026 13:22
Copilot AI balanced review requested due to automatic review settings August 28, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 1 Medium severity · 3 Low severity

New issues introduced by this change (4)
Severity Finding
Medium severity unified/​swift-syntax-rs/​schemagen/​Sources/​schemagen/​main.swift — This hard-coded snapshot means regeneration will silently miss any new variable-text token kind…
Low severity unified/​swift-syntax-rs/​schemagen/​Sources/​schemagen/​main.swift — This list is incomplete: swift-syntax also generates an unexpectedAfterX slot after the final…
Low severity unified/​swift-syntax-rs/​schemagen/​README.md — The documented filter omits unexpectedAfterX, which swift-syntax generates after the final child.…
Low severity unified/​swift-syntax-rs/​schemagen/​Sources/​schemagen/​main.swift — Add the missing “that” so this sentence is grammatical.
What changed in this PR

Adds tooling to regenerate Swift extractor node types from pinned swift-syntax definitions.

Changes:

  • Adds the Swift schema generator package and regeneration script.
  • Marks the schema as generated and documents the workflow.
  • Updates extractor and contributor documentation.
File Description
unified/​swift-syntax-rs/​schemagen/​Sources/​schemagen/​main.swift Generates the node schema.
unified/​swift-syntax-rs/​schemagen/​README.md Documents generator design and usage.
unified/​swift-syntax-rs/​schemagen/​Package.swift Defines the generator package.
unified/​swift-syntax-rs/​schemagen/​.gitignore Ignores generated dependencies and builds.
unified/​swift-syntax-rs/​README.md Documents regeneration workflow.
unified/​scripts/​regenerate-node-types.sh Resolves sources and runs generation.
unified/​extractor/​swift_node_types.yml Adds generated-file headers.
unified/​extractor/​src/​languages/​swift/​adapter.rs Documents the schema’s generator.
unified/​AGENTS.md Updates contributor guidance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +4 to +12
// Named-leaf ("varying") token kinds, mirroring the extractor adapter's
// VARYING_TOKEN_KINDS. Fixed tokens are anonymous (keyed by text) and are not
// matched by any rule, so they are not emitted here.
let varyingTokens = [
"identifier", "integerLiteral", "floatLiteral", "stringSegment",
"binaryOperator", "prefixOperator", "postfixOperator", "dollarIdentifier",
"regexLiteralPattern", "rawStringPoundDelimiter", "regexPoundDelimiter",
"shebang", "unknown",
]
Comment on lines +71 to +72
// swift-syntax error-recovery slots (`unexpectedBeforeX` and
// `unexpectedBetweenXAndY`) are never matched by rules.
Comment on lines +57 to +58
- `unexpectedBeforeX` and `unexpectedBetweenXAndY` error-recovery children are
dropped; no rule matches them. This filters on the child name:
"shebang", "unknown",
]

// The yeast type references a child maps to. A collection wrapper is elided by
fi
mv "$tmp" "$output"
chmod 644 "$output"
echo "Regenerated $output" >&2

@jketema jketema Aug 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having yet another script, could we maybe do this through Bazel? For Swift we e.g. have bazel run //swift/codegen, so I don't see why something similar shouldn't be possible here (and yes, I saw the Bazel remark in unified/swift-syntax-rs/schemagen/README.md).

Comment on lines +19 to +25
dependencies: [
// Deliberately a path dependency on the checkout the neighbouring FFI
// package resolved, rather than a second URL/exact pin: the schema has
// to describe the very swift-syntax that the parser links, and a
// single pin cannot drift from itself.
.package(name: "swift-syntax", path: "../swift/.build/checkouts/swift-syntax"),
],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to guarantee something that it doesn't really guarantee: This clearly will get violated when the FFI package was built with Bazel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants