Skip to content

Conversation

ehwan
Copy link
Owner

@ehwan ehwan commented Sep 12, 2025

No description provided.

@ehwan ehwan requested a review from Copilot September 12, 2025 15:33
Copy link
Contributor

@Copilot 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 implements an optimization to detect when custom reduce actions can be treated as identity operations (returning a single token unchanged). The main changes enhance the parser generator to analyze custom reduce actions and convert simple cases like { A } to more efficient identity operations.

  • Introduces intelligent detection of identity reduce actions in custom code
  • Refactors ReduceAction::Custom to use a new CustomReduceAction wrapper that tracks identifier usage
  • Optimizes generated parser code by simplifying identity operations and removing unused function parameters

Reviewed Changes

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

Show a summary per file
File Description
rusty_lr_parser/src/nonterminal_info.rs Adds CustomReduceAction struct to track identifier usage in custom reduce actions
rusty_lr_parser/src/grammar.rs Implements logic to detect when custom reduce actions are equivalent to identity operations
rusty_lr_parser/src/emit.rs Updates code generation to use the new CustomReduceAction interface and optimizes parameter usage
rusty_lr_parser/src/pattern.rs Updates all ReduceAction::Custom constructors to use new_custom method
scripts/diff/calculator.rs Shows generated code changes with optimized reduce function signatures

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

//
// ================================User Codes Begin================================
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy)]a
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

There's an extra 'a' character at the end of the derive attribute line that appears to be a typo.

Suggested change
#[derive(Debug, Clone, Copy)]a
#[derive(Debug, Clone, Copy)]

Copilot uses AI. Check for mistakes.

Comment on lines +8 to +11
pub struct CustomReduceAction {
pub body: TokenStream,
idents_used: BTreeSet<Ident>,
}
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The idents_used field should be public or provide a getter method since it's used for optimization decisions. Currently it's private but accessed through contains_ident method, which is good design.

Copilot uses AI. Check for mistakes.

Some(ReduceAction::Custom(new_reduce_action))

// check if this reduce action can be identity action; i.e., { $1 }
fn tokenstream_contains_unique_ident(ts: TokenStream) -> Option<Ident> {
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

[nitpick] This nested function should be extracted as a module-level function or method to improve readability and testability of this complex logic.

Copilot uses AI. Check for mistakes.

@ehwan ehwan merged commit bbce331 into main Sep 12, 2025
1 check passed
@ehwan ehwan deleted the reduce_action branch September 12, 2025 15:38
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.

1 participant