Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Code Review: Simplifications, Improvements, and Potential Bugfixes1. Significant Code Duplication in lexer.rsLocation: The Suggestion: Refactor to have pub fn next_token(&mut self) -> Result<Token, LexError> {
loop {
self.skip_whitespace();
match self.peek() {
None => return Ok(Token::Eof),
Some(&'/') => { /* ... skip comments ... */ continue; }
Some(&'%') => { self.skip_preprocessor(); continue; }
_ => break,
}
}
self.next_token_content()
}2. Dead/Unused Fields in LexerLocation: The
Suggestion: Either remove these fields or add them to 3. Potential Bug:
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Remove duplicate RawToken enum by using tuple variant for IntLiteral. Lexer reduced from 373 to 283 lines.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new XDR-to-Rust code generator written in Rust to replace the existing Ruby generator. The Rust generator uses Askama templates to separate code generation logic from templates, improving maintainability and performance. The new generator is designed to produce identical output to the Ruby generator during a transition period, with both generators running in parallel for validation.
Changes:
- Added new Rust-based XDR generator in
xdr-generator-rust/with lexer, parser, AST, type resolution, and code generation modules - Created Askama templates for generating Rust code (structs, enums, unions, typedefs, constants, and type enums)
- Updated Makefile to run both generators and verify their outputs match
Reviewed changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| xdr-generator-rust/Cargo.toml | Defines the new Rust generator package and dependencies |
| xdr-generator-rust/Cargo.lock | Dependency lock file for the new generator |
| xdr-generator-rust/src/main.rs | CLI entry point that parses arguments and orchestrates generation |
| xdr-generator-rust/src/lib.rs | Module exports for the library |
| xdr-generator-rust/src/lexer.rs | Tokenizer for XDR source using Logos |
| xdr-generator-rust/src/parser.rs | Recursive descent parser for XDR definitions |
| xdr-generator-rust/src/ast.rs | AST data structures for XDR definitions |
| xdr-generator-rust/src/types.rs | Type resolution, reference computation, and naming utilities |
| xdr-generator-rust/src/generator.rs | Code generation logic that prepares data for templates |
| xdr-generator-rust/templates/*.jinja | Askama templates for generating Rust code |
| Makefile | Added rules to run Rust generator and compare outputs |
| CONTRIBUTING.md | Documented the dual generator setup |
| .gitignore | Added generated-rust.rs to ignore list |
Comments suppressed due to low confidence (1)
Makefile:73
- The dependency rules for src/next/generated.rs and src/curr/generated.rs appear to be swapped. Line 69 shows that src/next/generated.rs depends on xdr/curr/.x files, but it should depend on xdr/next/.x files. Similarly, line 72 shows that src/curr/generated.rs depends on xdr/next/.x files, but it should depend on xdr/curr/.x files.
src/next/generated.rs: $(sort $(wildcard xdr/curr/*.x))
> $@
src/curr/generated.rs: $(sort $(wildcard xdr/next/*.x))
> $@
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
What
Add a new XDR-to-Rust code generator written in Rust (
xdr-generator-rust/) that produces identical output to the existing Ruby generator (xdr-generator/).Uses Askama templates separating code templates fromlogic and preparation of the data.
Plan
This change includes a test that for now requires both generators to continue to output identical. The plan is to migrate to the Rust generator once it has had time to bake through changes, then deprecate the Ruby generator.
There are many things we can probably do to simplify the generator and/or make it better. But those things will only come after migrating to the Rust generator.
Why
Based off passing comments over years, devs avoid contributing to xdrgen or the generators because they are written in Ruby. The ruby generator is brittle and easy to break, and messy with logic and templates all mixed up together.
I have a long list of things I want to do to improve the Rust code generation and the Ruby generator is at the point where it is a struggle to continue adding things:
Also, the ruby generator is so slow that iterating on it is painful, especially when every second build and generate is to just find a ruby syntax error. The Rust generator in this PR builds and runs much faster than the ruby one does.
Known limitations
Most of this code was generated by Claude Code, and I am still going through the process of reviewing it myself. I'll mark it as ready for review after I've completed my own review, and figured out a larger test story.