Repository navigation
Conversation
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.
I am opening this PR to fix two small boundary errors: losing a handler's return value when cleanup is followed by padding, and losing a comprehension's accumulator when an unpacked target consumes its modeled iterator.
For the handler case, the return must remain inside its exception clause even when the bytecode contains NOPs between
POP_EXCEPTandRETURN_VALUE:NOP/NOT_TAKEN/CACHE between
POP_EXCEPTand a return do not end the handler's return trailer. The current scan stops at that padding, which can leave a bare return whereFalseis already loaded. Continuing through the padding keeps the carried value in its handler and leaves the success return outside it. The padded bytecode examples preserve jump targets and exception-table boundaries.For the comprehension case, multiple unpacked generators must retain their iterator slots until cleanup:
Assembling an unpacked inline-comprehension target currently consumes the modeled iterator, even though the VM retains a distinct iterator until loop cleanup. Restoring that iterator prevents
END_FOR/POP cleanup from discarding the result accumulator. The repair preserves cleanup for simple targets as well as mixed simple/unpacked generators. Variations include six unpacked names across three generators and list, set and dictionary results:The iterator repair addresses comprehensions inlined since Python 3.12. The return-trailer repair also applies to the Python 3.11 exception-table layout; it does not depend on comprehension inlining.