Skip to content

Conversation

@ehwan
Copy link
Owner

@ehwan ehwan commented Oct 3, 2025

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ehwan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on optimizing the internal DataStack mechanism within the parser generator. It refines how internal markers like EOF are handled, preventing unnecessary pushes to the stack. The primary enhancement is a new conditional generation logic that detects if a grammar's data stack only ever uses a single type of tag. When this condition is met, the overhead of maintaining a separate tag vector is completely eliminated, resulting in more memory-efficient and performant generated parsers.

Highlights

  • DataStack EOF Tag Removal: The internal EOF tag is no longer pushed onto the DataStack in both deterministic and nondeterministic parser contexts, streamlining stack management.
  • Conditional DataStack Tag Generation: The parser generator now intelligently determines if multiple types of data tags are used. If only a single tag type (or no tags) is ever pushed, the entire tag tracking mechanism (the __tags vector and associated enum) is omitted from the generated DataStack implementation.
  • Optimized Generated Parser Code: Generated parser files now reflect these DataStack optimizations, leading to reduced memory usage and simpler code by removing unused tag-related structures and logic, and re-indexing data stacks where applicable.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant optimization by avoiding the generation of DataStack tags when they are not strictly necessary. This is achieved by detecting cases where only a single type of data (or no data) is present on the stack. The changes are consistently applied across both the deterministic and non-deterministic parser contexts, as well as the code generator. The updated generated parser files for various examples demonstrate the effectiveness of this optimization. I've found one critical issue in the code generator that could lead to non-compilable code under certain conditions, which I've detailed in a specific comment. Otherwise, the changes look solid and well-implemented.

@ehwan
Copy link
Owner Author

ehwan commented Oct 3, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant optimization to the DataStack implementation by avoiding the generation and use of tag stacks when they are not necessary. This is achieved by analyzing the grammar to determine if multiple data-carrying types are in use. The changes are primarily in the code generator (emit.rs), with consequential updates to the runtime contexts and generated parser files. The optimization is well-implemented, especially demonstrated by the simplification in the json.rs generated file. However, I've identified a logic flaw in emit.rs for determining when terminal tags are required, which could lead to incorrect code generation in some cases. My review includes a specific comment and suggestion to address this issue.

@ehwan
Copy link
Owner Author

ehwan commented Oct 3, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant optimization by avoiding the use of DataStack tags when they are not necessary. This is achieved by detecting if only a single type of data is used on the stack and conditionally compiling the tag-related logic. The changes also correctly handle the Eof symbol by not pushing it onto the data stack. The implementation looks solid and the effect is clearly visible in the updated generated parser files, especially for grammars without data like JSON. I've added a few suggestions to refactor some duplicated logic for better code clarity and maintainability.

Comment on lines 513 to 524
if next_state_id.push {
match term {
TerminalSymbol::Term(t) => self.data_stack.push_terminal(t),
TerminalSymbol::Error | TerminalSymbol::Eof => self.data_stack.push_empty(),
TerminalSymbol::Error => self.data_stack.push_empty(),
TerminalSymbol::Eof => {} // do not push anything for eof
}
} else {
self.data_stack.push_empty();
match term {
TerminalSymbol::Term(_) | TerminalSymbol::Error => self.data_stack.push_empty(),
TerminalSymbol::Eof => {} // do not push anything for eof
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for handling term can be simplified to reduce code duplication and improve readability. The current implementation has separate match statements for the if next_state_id.push and else branches, with similar handling for TerminalSymbol::Eof.

Suggested change
if next_state_id.push {
match term {
TerminalSymbol::Term(t) => self.data_stack.push_terminal(t),
TerminalSymbol::Error | TerminalSymbol::Eof => self.data_stack.push_empty(),
TerminalSymbol::Error => self.data_stack.push_empty(),
TerminalSymbol::Eof => {} // do not push anything for eof
}
} else {
self.data_stack.push_empty();
match term {
TerminalSymbol::Term(_) | TerminalSymbol::Error => self.data_stack.push_empty(),
TerminalSymbol::Eof => {} // do not push anything for eof
}
}
match term {
TerminalSymbol::Eof => {} // do not push anything for eof
TerminalSymbol::Term(t) => {
if next_state_id.push {
self.data_stack.push_terminal(t);
} else {
self.data_stack.push_empty();
}
}
TerminalSymbol::Error => {
self.data_stack.push_empty();
}
}

Comment on lines 1210 to 1227
TerminalSymbol::Term(term) => {
node_.data_stack.push_terminal(term);
}
TerminalSymbol::Eof | TerminalSymbol::Error => {
TerminalSymbol::Error => {
node_.data_stack.push_empty();
}
TerminalSymbol::Eof => {} // no push for eof
}
} else {
node_.data_stack.push_empty();
match term {
TerminalSymbol::Term(_) | TerminalSymbol::Error => {
node_.data_stack.push_empty();
}
TerminalSymbol::Eof => {} // no push for eof
}
}

self.next_nodes.push(node);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic for handling TerminalSymbol variants is repeated from an earlier part of the file and can be simplified to improve code clarity and reduce duplication.

Suggested change
TerminalSymbol::Term(term) => {
node_.data_stack.push_terminal(term);
}
TerminalSymbol::Eof | TerminalSymbol::Error => {
TerminalSymbol::Error => {
node_.data_stack.push_empty();
}
TerminalSymbol::Eof => {} // no push for eof
}
} else {
node_.data_stack.push_empty();
match term {
TerminalSymbol::Term(_) | TerminalSymbol::Error => {
node_.data_stack.push_empty();
}
TerminalSymbol::Eof => {} // no push for eof
}
}
self.next_nodes.push(node);
match term {
TerminalSymbol::Eof => {} // no push for eof
TerminalSymbol::Term(term) => {
if shift.push {
node_.data_stack.push_terminal(term);
} else {
node_.data_stack.push_empty();
}
}
TerminalSymbol::Error => {
node_.data_stack.push_empty();
}
}

@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@ehwan ehwan merged commit 4cad411 into main Oct 3, 2025
1 check passed
@ehwan ehwan deleted the tag_compact branch October 3, 2025 02:41
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