-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
gh-105775: Convert LOAD_CLOSURE to a pseudo-op #106059
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
Changes from 4 commits
21d086e
6921930
b111d10
bbdbb99
93b3138
32c1a70
4103b9a
269933e
a069593
988189d
968601d
46fa9d5
2b677b6
ab8ce45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1291,18 +1291,6 @@ iterations of the loop. | |||||
| .. versionadded:: 3.11 | ||||||
|
|
||||||
|
|
||||||
| .. opcode:: LOAD_CLOSURE (i) | ||||||
|
|
||||||
| Pushes a reference to the cell contained in slot ``i`` of the "fast locals" | ||||||
| storage. The name of the variable is ``co_fastlocalnames[i]``. | ||||||
|
|
||||||
| Note that ``LOAD_CLOSURE`` is effectively an alias for ``LOAD_FAST``. | ||||||
| It exists to keep bytecode a little more readable. | ||||||
|
|
||||||
| .. versionchanged:: 3.11 | ||||||
| ``i`` is no longer offset by the length of ``co_varnames``. | ||||||
|
|
||||||
|
|
||||||
| .. opcode:: LOAD_DEREF (i) | ||||||
|
|
||||||
| Loads the cell contained in slot ``i`` of the "fast locals" storage. | ||||||
|
|
@@ -1725,6 +1713,18 @@ but are replaced by real opcodes or removed before bytecode is generated. | |||||
| Undirected relative jump instructions which are replaced by their | ||||||
| directed (forward/backward) counterparts by the assembler. | ||||||
|
|
||||||
| .. opcode:: LOAD_CLOSURE (i) | ||||||
|
|
||||||
| Pushes a reference to the cell contained in slot ``i`` of the "fast locals" | ||||||
| storage. | ||||||
|
|
||||||
| Note that ``LOAD_CLOSURE`` is replaced with ``LOAD_FAST`` in the assembler. | ||||||
| It exists to keep bytecode a little more readable. | ||||||
|
|
||||||
| .. versionchanged:: 3.13 | ||||||
| This opcode was demoted from full opcode to pseudo-instruction | ||||||
|
||||||
| This opcode was demoted from full opcode to pseudo-instruction | |
| This opcode is now a pseudo-instruction. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Remove the LOAD_CLOSURE opcode and make it a pseudo-op instead. This enables | ||
|
|
||
| * Superinstruction formation | ||
| * Removal of checks for uninitialized variables | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,6 @@ dummy_func( | |
| // BEGIN BYTECODES // | ||
| inst(NOP, (--)) { | ||
| } | ||
|
|
||
polynomialherder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| inst(RESUME, (--)) { | ||
| assert(tstate->cframe == &cframe); | ||
| assert(frame == cframe.current_frame); | ||
|
|
@@ -177,12 +176,9 @@ dummy_func( | |
| } | ||
| } | ||
|
|
||
| inst(LOAD_CLOSURE, (-- value)) { | ||
| /* We keep LOAD_CLOSURE so that the bytecode stays more readable. */ | ||
| value = GETLOCAL(oparg); | ||
| ERROR_IF(value == NULL, unbound_local_error); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I note that we are implicitly eliminating this NULL check by converting
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @markshannon What do you think? We could replace it with LOAD_CLOSURE_CHECK instead to preserve this. There might be a way for a debugger to delete the variable.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't believe there is, unless the debugger is doing something unsupported and poking directly at the fastlocals array on a |
||
| Py_INCREF(value); | ||
| } | ||
| pseudo(LOAD_CLOSURE) = { | ||
| LOAD_FAST, | ||
| }; | ||
|
|
||
| inst(LOAD_FAST_CHECK, (-- value)) { | ||
| value = GETLOCAL(oparg); | ||
|
|
@@ -201,7 +197,6 @@ dummy_func( | |
| // do not use SETLOCAL here, it decrefs the old value | ||
| GETLOCAL(oparg) = NULL; | ||
| } | ||
|
|
||
polynomialherder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| inst(LOAD_FAST_LOAD_FAST, ( -- value1, value2)) { | ||
| uint32_t oparg1 = oparg >> 4; | ||
| uint32_t oparg2 = oparg & 15; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this sentence is accurate anymore (if it ever was).
LOAD_CLOSUREstill exists in order to keepfix_cell_offsetsworking. Pseudo-instructions can't make bytecode more readable, since they don't exist in bytecode.I would just remove this sentence.