gh-106581: Fix two bugs in the code generator's copy optimization #108380
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.
When replacing matched pairs of push/pop (poke/peek), I was matching up the last poke in the previous "manager" with the wrong peek in the new one, causing some copying opportunities to be missed.
Fixing this revealed a more serious bug where we could end up skipping the copy of an 'unused' poke to a used peek, leaving the variable uninitialized. The fix for this required me to keep track of the original StackItems in the CopyEffect object, and use that to reconstruct the source when copying from 'unused'.
The net result so far is that this found two redundant initializations.