-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-107265: Fix code_richcompare for ENTER_EXECUTOR case #108165
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
Conversation
corona10
commented
Aug 20, 2023
•
edited
Loading
edited
- Issue: Decoding instructions should handle ENTER_EXECUTOR #107265
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.
LG, but could you add a test for this? You could add it to test_capi/test_misc.py
in TestOptimizerAPI
.
Thanks, I added the test, and if I understand the intention correctly. Please let me know if I understand wrongly. |
pydoc test failure is unrelated to this PR, I checked it locally and asked to Discord too |
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.
Yes, the arg
must also be restored, since it is overwritten (with the index of the executor to be used in this code object's array of executors). So it looks like writing the test was useful!
if (co_instr.op.code == ENTER_EXECUTOR) { | ||
const int exec_index = co_instr.op.arg; | ||
_PyExecutorObject *exec = co->co_executors->executors[exec_index]; | ||
co_instr.op.code = exec->vm_data.opcode; |
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.
Comparing two code objects must not modify the code object.
The interaction between executor, the specializer and instrumentation is subtle and likely to break without care.
This will leak executors, as it flip-flops between JUMP_BACKWARDS
and ENTER_EXECUTOR
, or worse if an optimizer assumes that a single instruction will only be seen once.
if (cp_instr.op.code == ENTER_EXECUTOR) { | ||
const int exec_index = cp_instr.op.arg; | ||
_PyExecutorObject *exec = cp->co_executors->executors[exec_index]; | ||
cp_instr.op.code = exec->vm_data.opcode; |
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.
Likewise
Please revert this. It will leak, and may not be safe. |
@corona10 We can fix this in the hash PR you are working on. |
Okay got it. |