perf(ast_tools): use StructsAndEnums iterator where possible#20944
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR improves ast_tools generator performance by switching several generator loops from iterating over all Schema::types to using the existing Schema::structs_and_enums() iterator, which stops once non-struct/enum types begin (avoiding needless iteration over container/primitive defs).
Changes:
- Add
TypeDef::as_struct_or_enum()to convert aTypeDefreference into aStructOrEnum(when applicable). - Update TypeScript and traverse-related generators to iterate via
schema.structs_and_enums()and acceptStructOrEnumwhere appropriate. - Narrow traversal “is AST type with visitor” checks to operate on
StructOrEnum, updating call sites accordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/ast_tools/src/schema/defs/type.rs | Adds as_struct_or_enum() helper to bridge &TypeDef → StructOrEnum when needed. |
| tasks/ast_tools/src/generators/typescript.rs | Uses schema.structs_and_enums() and updates TS type-def generation to take StructOrEnum. |
| tasks/ast_tools/src/generators/traverse/walk.rs | Iterates only structs/enums for walk generation; matches on StructOrEnum. |
| tasks/ast_tools/src/generators/traverse/mod.rs | Iterates only structs/enums for trait method generation; matches on StructOrEnum. |
| tasks/ast_tools/src/generators/traverse/ancestor.rs | Narrows is_ast_type_with_visitor to StructOrEnum and adapts field visitation logic via as_struct_or_enum(). |
| tasks/ast_tools/src/generators/assert_layouts.rs | Iterates only structs/enums for layout assertion generation; signature updated to StructOrEnum. |
Merge activity
|
Similar to #20944. In loops where a generator is only interested in structs and enums, use the `StructsAndEnums` iterator which exits early, rather than pointlessly continuing iterating over all types.
aa93f79 to
91098c4
Compare
12570cf to
3656b5c
Compare
…e possible (#21686) Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types. Does not alter generated code, only the means by which it's generated.
…e possible (#21686) Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types. Does not alter generated code, only the means by which it's generated.
…e possible (#21686) Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types. Does not alter generated code, only the means by which it's generated.
…e possible (#21686) Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types. Does not alter generated code, only the means by which it's generated.

Similar to #20944. In loops where a generator is only interested in structs and enums, use the
StructsAndEnumsiterator which exits early, rather than pointlessly continuing iterating over all types.