Skip to content

Add ASSIGN_NOPUSH to eliminate redundant assignment pushes#494

Merged
bertysentry merged 3 commits into
mainfrom
446-optimize-variable-assignement
Jun 2, 2026
Merged

Add ASSIGN_NOPUSH to eliminate redundant assignment pushes#494
bertysentry merged 3 commits into
mainfrom
446-optimize-variable-assignement

Conversation

@bertysentry
Copy link
Copy Markdown
Contributor

Summary

  • Add a dedicated ASSIGN_NOPUSH opcode for scalar assignments whose result is immediately discarded
  • Update tuple peephole optimization to rewrite ASSIGN + POP into ASSIGN_NOPUSH
  • Teach the AVM to handle both assignment opcodes and skip the stack push for the nopush form
  • Add optimizer coverage for statement assignments and assignment expressions

Testing

  • mvn formatter:format test -Dtest=AwkTupleOptimizationTest
  • mvn test
  • mvn verify

@bertysentry bertysentry linked an issue Jun 2, 2026 that may be closed by this pull request
@bertysentry bertysentry requested a review from Copilot June 2, 2026 12:22
Copy link
Copy Markdown
Contributor

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 introduces a new scalar-assignment opcode (ASSIGN_NOPUSH) to avoid redundant operand-stack pushes when an assignment’s result is immediately discarded, and updates the peephole optimizer, opcode definitions, AVM execution, and optimizer tests accordingly.

Changes:

  • Add ASSIGN_NOPUSH opcode and document distinct stack semantics vs ASSIGN.
  • Extend the peephole optimizer to rewrite ASSIGN followed by POP into ASSIGN_NOPUSH.
  • Update the AVM assignment execution path to optionally skip pushing the assigned value; add tests asserting the optimizer behavior for statement vs expression assignments.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/test/java/io/jawk/AwkTupleOptimizationTest.java Adds optimizer tests and opcode-scanning helpers to validate folding behavior.
src/main/java/io/jawk/intermediate/Opcode.java Introduces ASSIGN_NOPUSH and clarifies ASSIGN stack behavior in docs.
src/main/java/io/jawk/intermediate/AwkTuples.java Adds peephole rewrite for ASSIGN + POP -> ASSIGN_NOPUSH and tuple construction helper.
src/main/java/io/jawk/backend/AVM.java Executes ASSIGN_NOPUSH by assigning without re-pushing; removes redundant push/pop in a couple of internal assignment sites.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/io/jawk/intermediate/AwkTuples.java Outdated
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/test/java/io/jawk/AwkTupleOptimizationTest.java
Comment thread src/main/java/io/jawk/intermediate/AwkTuples.java Outdated
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@bertysentry bertysentry merged commit 904592a into main Jun 2, 2026
6 checks passed
@bertysentry bertysentry deleted the 446-optimize-variable-assignement branch June 2, 2026 16:26
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.

Optimize variable assignement

2 participants