New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove LOAD_CLOSURE
#105775
Comments
I'd like to work on this issue |
Are you sure? This is more complicated than it looks as it involves some awkward compiler internals. |
Oh, I thought it would be just deleting some statements |
It should be. But the compiler handles local variables in a somewhat convoluted way |
Ok, then someone else can pick the issue up. |
I've been working through this -- I'll update if I have questions or get stuck |
@markshannon My plan is to add a member to the For this unit of work, do we want to preserve the current performance characteristics to reduce risk? For instance, I see that replacing Let me know your thoughts on this -- I'm pretty new to the cpython source code so still piecing together the local variable lifecycle. Thanks! |
Rather than add special cases to There is no reason to treat |
If you don't want to tackle a full refactoring of how local variable and cell offsets are handled in this PR, a simpler incremental approach would be to make The refactor of cell index handling could still be done as a follow-up PR, allowing removal of the |
(From your post to core-mentorship:)
The instructions may well be out of date. (A PR to update them would be welcome of course!) As of 3.12, the cases in the switch are generated by tooling in Tool/cases_generator (check out the README.md there). This reads Python/bytecodes.c and writes Python/generated_cases.c.h, which in If you are still stuck, can you push your work to a branch in your GitHub fork of the cpython repo and link it here, and post the errors you are getting (and from which command)? |
Thank you all for the tips, this helped a lot. I'll proceed with the approach you all suggested, will report back soon with progress |
This change demotes LOAD_CLOSURE from an instruction to a pseudo-instruction. This enables superinstruction formation, removal of checks for uninitialized variables, and frees up an instruction.
As far as automated tests go, would adding a test for |
Usually when messing around with the interpreter, once you get it to build it's pretty solid, and if you get it to pass the test suite, it's golden. It seems you've already reached that stage. :-) Platinum would be to pass the buildbots, esp. the refleak subset. IIUC only triagers and core devs can trigger a buildbot run (by setting a magic label on the PR), and will do so as part of the PR review. I can do that for you. Whether a test for |
|
Thanks @iritkatriel -- just to make sure before I proceed, are you suggesting that I expose |
I wouldn't do that. I'd just add a test to Lib/test/test_compiler_assemble.py that creates a code object from an instruction sequence that contains the pseudo ops, and then checks that the code works as expected. If the pseudo ops are not replaced the code object can't possibly work. |
This change adds a unit test for assembly of code objects containing the LOAD_CLOSURE pseud-instruction We also correct the documentation and NEWS descriptions to more accurately reflect the effects of converting LOAD_CLOSURE to a pseudo-op and the reason for its existence in the first place
- Describe the LOAD_CLOSURE change using more neutral language - Add back in deleted whitespace - Add an assertion to IsolatedAssembleTests.test_expression_with_pseudo_instruction_load_closure - Regenerate generated files
As I wrote in the I'll also keep an eye on the PR which converts |
This enables super-instruction formation, removal of checks for uninitialized variables, and frees up an instruction.
I'm still working through this -- I spent the last week writing simple examples and stepping through their evaluation in gdb to understand how the Something that confused me previously is that In terms of possible approaches, @carljm commented that we could either refactor the cell/local offsets logic so that we can remove |
I would say that the former is the ideal forward-looking approach, but may be high difficulty/complexity; it should be possible, but I haven't looked at it in detail. The latter is more of a short-term approach if for performance reasons we urgently want |
I don't think this is urgent. We plan (vaguely) to change the compiler to use names, rather than indices for load instructions. |
LOAD_CLOSURE
is identical toLOAD_FAST_CHECK
in every way except its name and number.The justification for its existence is that "We keep LOAD_CLOSURE so that the bytecode stays more readable.".
Which is insufficient justification to keep it given that it:
Linked PRs
The text was updated successfully, but these errors were encountered: