Skip to content

Single rule optimization can be applied with custom reduce action#32

Merged
ehwan merged 17 commits into
mainfrom
custom_reduceaction_optimize
Sep 13, 2025
Merged

Single rule optimization can be applied with custom reduce action#32
ehwan merged 17 commits into
mainfrom
custom_reduceaction_optimize

Conversation

@ehwan

@ehwan ehwan commented Sep 13, 2025

Copy link
Copy Markdown
Owner

No description provided.

@ehwan
ehwan requested a review from Copilot September 13, 2025 04:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment on lines +1266 to 1270
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;

Copilot AI Sep 13, 2025

Copy link

Choose a reason for hiding this comment

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

[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.

Copilot uses AI. Check for mistakes.
Comment thread rusty_lr_parser/src/grammar.rs Outdated
@ehwan
ehwan merged commit dff4c69 into main Sep 13, 2025
1 check passed
@ehwan
ehwan deleted the custom_reduceaction_optimize branch September 13, 2025 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants