GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — GH-128685: Specialize (rather than quicken) LOAD_CONST into LOAD_CONST_[IM]MORTAL by markshannon · Pull Request #128708 · python/cpython Conversation
|
| Python 3.14a4 3610 (Add VALUE_WITH_FAKE_GLOBALS format to annotationlib) | ||
| Python 3.14a4 3611 (Add NOT_TAKEN instruction) | ||
| Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER) | ||
| Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is a specialization, right? So we shouldn't need a magic bump (since the specialized variants don't occur in marshalled data).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Adding the extra instruction changes the allocated numbers for other instructions.
Even if it isn't absolutely necessary, it is harmless.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| inst(LOAD_CONST, (-- value)) { | ||
| /* We can't do this in the bytecode compiler as | ||
| * marshalling can intern strings and make them immortal. */ | ||
| PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); | ||
| value = PyStackRef_FromPyObjectNew(obj); | ||
| #if ENABLE_SPECIALIZATION | ||
| if (this_instr->op.code == LOAD_CONST) { | ||
| this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL; | ||
| } | ||
| #endif | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why the check for this_instr->op.code == LOAD_CONST?
Also, minor, but maybe a bit more idiomatic with the rest of the bytecode definitions to split the specializing part out and reuse the code for loading the const? I think this would also make LOAD_CONST a viable tier two instruction (which it currently isn't). Though actually tracing through one should be rare, I can think of cases where it might happen.
| inst(LOAD_CONST, (-- value)) { | |
| /* We can't do this in the bytecode compiler as | |
| * marshalling can intern strings and make them immortal. */ | |
| PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg); | |
| value = PyStackRef_FromPyObjectNew(obj); | |
| #if ENABLE_SPECIALIZATION | |
| if (this_instr->op.code == LOAD_CONST) { | |
| this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL; | |
| } | |
| #endif | |
| } | |
| specializing op(_SPECIALIZE_LOAD_CONST, (--)) { | |
| /* We can't do this in the bytecode compiler as | |
| * marshalling can intern strings and make them immortal. */ | |
| #if ENABLE_SPECIALIZATION | |
| this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL; | |
| #endif | |
| } | |
| macro(LOAD_CONST) = _SPECIALIZE_LOAD_CONST + LOAD_CONST_MORTAL; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why the check for this_instr->op.code == LOAD_CONST?
Instrumentation. The opcode might be INSTRUMENTED_LINE for example.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
split the specializing part out
The specializing part needs to load the value to test it, so separating out the specialization just duplicates that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This was previously handled by `_PyCode_Quicken`, but moved to specialization in pythongh-128708. Enable it for the free-threaded build.
This was previously handled by `_PyCode_Quicken`, but moved to specialization in pythongh-128708. Enable it for the free-threaded build.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.