Skip to content

Conversation

@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jan 15, 2026

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided that _BINARY_OP_INPLACE_ADD_UNICODE leaves the VM in a valid state (and I believe it does), then it doesn't matter if the following STORE_FAST is replaced by ENTER_EXECUTOR or instrumented.

It is the assert that needs changing. You'll need to use _Py_GetBaseCodeUnit

@bedevere-app
Copy link

bedevere-app bot commented Jan 16, 2026

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@Fidget-Spinner
Copy link
Member Author

It is the assert that needs changing. You'll need to use _Py_GetBaseCodeUnit

It matters because we get the next instruction's oparg and check it next_oparg = next_instr->op.arg;. ENTER_EXECUTOR overrides the oparg. If we use _Py_GetBaseCodeUnit, it will significantly slow down the current code, so I choose to deopt instead.

@markshannon
Copy link
Member

We need to check for ENTER_EXECUTOR either way, so we might as well handle that case without deopting and losing the big-O improvement.

next_oparg = next_instr->op.arg;
if (next_instr->op.code == ENTER_EXECUTOR) {
    _PyExecutorObject *exec = _PyFrame_GetCode(frame)->co_executors->executors[next_oparg];
    next_oparg = exec->vm_data.oparg;
}
// Updated assert goes here

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case seems to have a lot of extra stuff in it, but no check that it is testing what it is supposed to be testing.

Can we tidy it up and add a check that it it working?

# https://github.com/python/cpython/issues/143358

result = script_helper.run_python_until_end('-c', textwrap.dedent(f"""
import sys
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems like a lot of extraneous stuff in this test, and no check that the STORE_FAST is overwritten by an ENTER_EXECUTOR.

next_oparg = exec->vm_data.oparg;
}
#endif
assert(next_instr->op.code == STORE_FAST || next_instr->op.code == ENTER_EXECUTOR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong as it will fail if the code is instrumented. You'll need to use _Py_GetBaseCodeUnit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants