Skip to content

Commit 4110636

Browse files
author
Paolo Tranquilli
committed
Rust: preserve ordering in rust 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.
1 parent b096696 commit 4110636

File tree

3 files changed

+1151
-1149
lines changed

3 files changed

+1151
-1149
lines changed

misc/codegen/generators/rustgen.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def _get_class(self, name: str) -> rust.Class:
9696
name=name,
9797
fields=fields,
9898
detached_fields=detached_fields,
99-
ancestors=sorted(set(a.name for a in _get_ancestors(cls, self._classmap))),
99+
# remove duplicates but preserve ordering
100+
# (`dict` preserves insertion order while `set` doesn't)
101+
ancestors=[*{a.name: None for a in _get_ancestors(cls, self._classmap)}],
100102
entry_table=inflection.tableize(cls.name) if not cls.derived else None,
101103
)
102104

rust/extractor/src/generated/.generated.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)