Skip to content

Rust: preserve ordering in rust generated code #19071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2025

Conversation

redsun82
Copy link
Contributor

This is a small devex improvement to the rust code generator.

Usage of sorted in rustgen.py was causing the generated code to be completely reshuffled on renames, which made diffs hard to follow. As an example see this generated file diff.

This will make the order deterministically based on the order of definitions in the schema file. This means that renames will find the same place in the generated file, and the place in the generated file will generally be more predictable with respect to the schema.

However, that does mean this change is heavily reshuffling the generated code.

This is a small devex improvement to the rust code generator.

Usage of `sorted` in `rustgen.py` was causing the generated code to be
completely reshuffled on renames, which made diffs hard to follow. As an
example see [this generated file diff](https://github.com/github/codeql/pull/19059/files#diff-c938ba77a3398dd4c633ada5702a03477705c24740a2f7d1e40d4b270d8c3f86).

This will make the order deterministically based on the order of
definitions in the schema file. This means that renames will find the
same place in the generated file, and the place in the generated file
will generally be more predictable with respect to the schema.

However, that does mean this change is heavily reshuffling the generated
code.
@Copilot Copilot AI review requested due to automatic review settings March 20, 2025 11:13
@redsun82 redsun82 requested a review from a team as a code owner March 20, 2025 11:13
@redsun82 redsun82 force-pushed the redsun82/codegen-rust-ancestor-order branch from 9697503 to 4110636 Compare March 20, 2025 11:13
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 20, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request improves the deterministic ordering of generated Rust code by preserving the order of definitions from the schema file. The change replaces a sorted set with a dictionary comprehension to remove duplicates while maintaining the insertion order.

  • Change the generation of ancestor names from using sorted(set(...)) to using a dictionary comprehension for order preservation.

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

@redsun82 redsun82 merged commit cd15fb3 into main Mar 20, 2025
21 checks passed
@redsun82 redsun82 deleted the redsun82/codegen-rust-ancestor-order branch March 20, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants