gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 #111368
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.
gen_closeneeds to know whether aRESUMEfollows aYIELD_VALUEwhich is at except-depth 1, for an important optimization. Currently the compiler stores this information in the oparg ofYIELD_VALUE, which requiresgen_closeto peek into the bytecode (which is unsafe in the debugger). This PR puts this information in the oparg of theRESUME, and removes the oparg ofYIELD_VALUE. The result is simpler and safer code in gen_close.It also removes an anomaly in the bytecode definitions, where we needed to add a meaningless assertion to make the code generator understand that YIELD_VALUE has an oparg even though it doesn't use it.
📚 Documentation preview 📚: https://cpython-previews--111368.org.readthedocs.build/