fix issues with the java bytecode frontend#742
Merged
swissiety merged 14 commits intosoot-oss:developfrom Nov 8, 2023
Merged
Conversation
5 tasks
Certain assign statement would produce in no result. Because the visitor is stateful, this would result in an old result being used later.
Moved the logic for assigning the values of operands to stack locals out of `OperandStack` and into `Operand`. That means that the assignments are created when the operands are used as a local/immediate with the `toLocal` and `toImmediate` methods instead of when they are popped of the stack with `popLocal` and `popImmediate`. This fixes some issues where the wrong `pop` method was used which caused unnecessary stack local variables to get created. This also results in improved type-safety and gets rid of a bunch of casts, because `toLocal` and `toImmediate` actually return the `Local` and `Immediate` types instead of a generic `Operand`. Significantly simplified merging logic in `StackFrame`. Factored a bunch of duplicated code into the new `changeStackLocal` in `Operand`. The old version actually incorrectly merged operands at times (See `SwitchExprWithYieldTest`). I will add a test for this in a later commit. Fixed updating usages of the `value`/`stackLocal` in `Operand`. This is now part of the `changeStackLocal` method. Simplified duplication instructions (Thanks to `Operand.DWORD_DUMMY`). Removed some commented out code.
This removes the duplicated logic that was present in *every* convert method with any inputs/outputs.
557d2b3 to
8aa2a08
Compare
The class had nothing to do with stack frames
4 tasks
…merging Instead, rely on the fact that all `convert` methods override their respective statements. That means just changing the incoming operands will automatically correctly update the statement. Also added a test case to make sure this works with the special case of using a normal local as a stack local.
When converting the instructions for a branch, there might not be a line number node after the branch target. This would result in incorrect line numbers being used until the next line number node. The fix is to simply store the line number for branches and restore the current line number when handling that branch.
10740b2 to
e7e565e
Compare
swissiety
approved these changes
Nov 8, 2023
Collaborator
swissiety
left a comment
There was a problem hiding this comment.
looks excellent - thx for cleaning that up ❤️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorry for the big PR. The bytecode fronted has a lot of shared state that makes it difficult to change in small steps.
Moved the logic for assigning the values of operands to stack locals out of
OperandStackand intoOperand.That means that the assignments are created when the operands are used as a local/immediate with the
toLocalandtoImmediatemethods instead of when they are popped of the stack withpopLocalandpopImmediate.This fixes some issues where the wrong
popmethod was used which caused unnecessary stack local variables to get created.This also results in improved type-safety and gets rid of a bunch of casts, because
toLocalandtoImmediateactually return theLocalandImmediatetypes instead of a genericOperand.Significantly simplified merging logic in
StackFrame.All
convertmethods had a code path for the first time they were called and for merging subsequent calls.These two code paths have been combined now.
Factored a bunch of duplicated code into the new
changeStackLocalinOperand.The old version actually incorrectly merged operands at times (See
SwitchExprWithYieldTest).This code
would previously produce
but now produces
This adds the missing assignment and doesn't produce so many stack local variables.
Fixed updating usages of the
value/stackLocalinOperand. This is now part of thechangeStackLocalmethod.Simplified duplication instructions (Thanks to
Operand.DWORD_DUMMY).Removed some commented out code.
Fixed an issue in the
ReplaceUseStmtVisitorthat would produce stale results.Fixes #698
Fixes #631
TODO:
StackFrame(it has nothing to do with stack frames)addReadOperandAssignments_internaldoesand maybe remove it