Single rule optimization can be applied with custom reduce action#32
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements single rule optimization that can be applied with custom reduce actions in the RustyLR parser generator. The optimization allows rules with single productions (A -> B) to be inlined while preserving custom reduce actions as callable functions.
- Adds infrastructure to track and generate custom reduce action functions that can be chained during optimization
- Implements single-rule optimization that preserves custom reduce actions by converting them to function calls
- Reorders bootstrap test execution to run diff comparison tests before the main test suite
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/diff/calculator.rs | Generated parser code showing the optimization in action with custom reduce functions |
| scripts/bootstrap_test.sh | Reorders test execution to run diff comparisons before main tests |
| rusty_lr_parser/src/utils.rs | Adds utilities for location variable naming and lookahead parameter handling |
| rusty_lr_parser/src/token.rs | Adds reduce_action_chains field to TokenMapped for tracking optimization chains |
| rusty_lr_parser/src/pattern.rs | Updates all TokenMapped instantiations to include empty reduce_action_chains |
| rusty_lr_parser/src/nonterminal_info.rs | Makes CustomReduceAction cloneable for optimization processing |
| rusty_lr_parser/src/grammar.rs | Core optimization logic for single-rule optimization with custom reduce actions |
| rusty_lr_parser/src/emit.rs | Code generation for custom reduce action functions and their invocation |
| rusty_lr_buildscript/src/lib.rs | Increases optimization iteration limit from 10 to 25 |
| example/calculator/src/parser.rs | Example demonstrating the optimization with M_optim rule |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| for var_right in 0..maptos.len() { | ||
| if let Some(var_name) = maptos[var_right].as_ref().cloned() { | ||
| for var_left in 0..var_right { | ||
| for var_left in var_right + 1..maptos.len() { | ||
| if maptos[var_left].as_ref() == Some(&var_name) { | ||
| maptos[var_left] = None; |
There was a problem hiding this comment.
[nitpick] The variable names var_right and var_left are misleading since the loop direction has changed. With the comment indicating reverse order and the loops now going forward, these names create confusion about the actual iteration direction.
No description provided.