| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good, just a couple of thoughts.
Also, any perf numbers? I doubt it would be too significant, but this is a very perf-sensitive instruction/optimization.
Sorry, something went wrong.
| 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.
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 a problem hiding this comment.
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.
| 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.
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 a problem hiding this comment.
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 a problem hiding this comment.
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.
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.
| Back | FazBrowse Home | New Git URL |
This PR changes LOAD_CONST to specialize into either LOAD_CONST or LOAD_CONST_IMMORTAL.
This ensures that LOAD_CONST for immortals returns to LOAD_CONST_IMMORTAL after instrumentation.
This is unlikely to make any observable difference, but we generally expect instructions to return to their specialized forms after instrumentation is removed and LOAD_CONST is a very common instruction, so is likely to get instrumented.
Skipping news as this should have no observable effect.