Skip to content

perf(ast_tools): use structs and structs_and_enums iterators where possible#21686

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible
Apr 23, 2026
Merged

perf(ast_tools): use structs and structs_and_enums iterators where possible#21686
graphite-app[bot] merged 1 commit intomainfrom
om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 23, 2026

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.

Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 23, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@overlookmotel overlookmotel self-assigned this Apr 23, 2026
@overlookmotel overlookmotel added A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance labels Apr 23, 2026 — with Graphite App
@overlookmotel overlookmotel marked this pull request as ready for review April 23, 2026 14:15
Copilot AI review requested due to automatic review settings April 23, 2026 14:15
Copy link
Copy Markdown
Contributor

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 PR optimizes ast_tools generators by using Schema::structs() and Schema::structs_and_enums() iterators in places that only need structs or structs+enums, avoiding unnecessary iteration over non-AST type defs (containers/primitives) while keeping generated output unchanged.

Changes:

  • Switch generator loops from schema.types.iter() to schema.structs_and_enums() where only structs/enums are relevant.
  • Switch get_id generation from iterating all types to iterating only schema.structs().
  • Update helper function signatures/pattern matches to use StructOrEnum (and direct StructDef where appropriate).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tasks/ast_tools/src/generators/scopes_collector.rs Use structs_and_enums() and StructOrEnum for visitor-method generation.
tasks/ast_tools/src/generators/get_id.rs Iterate only schema.structs() and simplify generation to accept &StructDef.
tasks/ast_tools/src/generators/formatter/format.rs Use structs_and_enums() + StructOrEnum in formatter Format impl generation.
tasks/ast_tools/src/generators/formatter/ast_nodes.rs Use structs_and_enums() + StructOrEnum in AstNode/AstNodes impl generation.
tasks/ast_tools/src/generators/ast_builder.rs Use structs_and_enums() + StructOrEnum for builder method generation selection.

@overlookmotel overlookmotel force-pushed the om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible branch from 5c60335 to 960f23d Compare April 23, 2026 14:24
@overlookmotel overlookmotel force-pushed the om/02-14-refactor_ast_tools_simplify_astkind_generator branch from 7dad5a9 to 8b1e928 Compare April 23, 2026 14:24
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Apr 23, 2026

Merge activity

@graphite-app graphite-app Bot force-pushed the om/02-14-refactor_ast_tools_simplify_astkind_generator branch from 8b1e928 to bcd1161 Compare April 23, 2026 15:40
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…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.
@graphite-app graphite-app Bot force-pushed the om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible branch from 960f23d to 55546a1 Compare April 23, 2026 15:41
@graphite-app graphite-app Bot force-pushed the om/02-14-refactor_ast_tools_simplify_astkind_generator branch from bcd1161 to 6b1d7f2 Compare April 23, 2026 15:51
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…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.
@graphite-app graphite-app Bot force-pushed the om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible branch from 55546a1 to b69654b Compare April 23, 2026 15:51
@graphite-app graphite-app Bot force-pushed the om/02-14-refactor_ast_tools_simplify_astkind_generator branch from 6b1d7f2 to d0f8e10 Compare April 23, 2026 17:24
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…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.
@graphite-app graphite-app Bot force-pushed the om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible branch from b69654b to 022562c Compare April 23, 2026 17:25
…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.
@graphite-app graphite-app Bot force-pushed the om/02-14-refactor_ast_tools_simplify_astkind_generator branch from d0f8e10 to 8e421a3 Compare April 23, 2026 17:33
@graphite-app graphite-app Bot force-pushed the om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible branch from 022562c to b18a0cf Compare April 23, 2026 17:33
Base automatically changed from om/02-14-refactor_ast_tools_simplify_astkind_generator to main April 23, 2026 18:49
@graphite-app graphite-app Bot merged commit b18a0cf into main Apr 23, 2026
26 checks passed
@graphite-app graphite-app Bot deleted the om/04-23-perf_ast_tools_use_structs_and_structs_and_enums_iterators_where_possible branch April 23, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants