-
-
Notifications
You must be signed in to change notification settings - Fork 0
Optimization for unused DataStack tags #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
|
/gemini review |
There was a problem hiding this 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.
|
/gemini review |
There was a problem hiding this 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.
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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(); | |
| } | |
| } |
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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(); | |
| } | |
| } |
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
No description provided.