8000 GH-118093: Better handling of short and mid-loop traces by brandtbucher · Pull Request #122252 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-118093: Better handling of short and mid-loop traces #122252

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

Merged
merged 10 commits into from
Jul 29, 2024
Prev Previous commit
Next Next commit
Add asserts back and teach is_resume about ENTER_EXECUTOR
  • Loading branch information
brandtbucher committed Jul 26, 2024
commit ba3d68becca72bb2755d92334345aba0aa3bd5e5
33 changes: 24 additions & 9 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pycore_gc.h" // _PyGC_CLEAR_FINALIZED()
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt
#include "pycore_opcode_utils.h" // RESUME_AFTER_YIELD_FROM
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_*
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
Expand Down Expand Up @@ -327,21 +328,35 @@
}

static inline bool
is_resume(_Py_CODEUNIT *instr)
is_resume(_PyInterpreterFrame *frame, uint8_t *oparg_p)
{
uint8_t code = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.code);
return (
code == RESUME ||
code == RESUME_CHECK ||
code == INSTRUMENTED_RESUME
);
PyCodeObject *code = _PyFrame_GetCode(frame);
int offset = frame->instr_ptr - _PyCode_CODE(code);
uint8_t opcode = _Py_GetBaseOpcode(code, offset);
uint8_t oparg = frame->instr_ptr->op.arg;
if (opcode == ENTER_EXECUTOR) {
_PyExecutorObject *executor = _Py_GetExecutor(code, sizeof(_Py_CODEUNIT) * offset);
opcode = _PyOpcode_Deopt[executor->vm_data.opcode];
oparg = executor->vm_data.oparg;
Py_DECREF(executor);
}
if (opcode == RESUME) {
*oparg_p = oparg;
return true;
}
return false;
}

PyObject *
_PyGen_yf(PyGenObject *gen)
{
if (gen->gi_frame_state == FRAME_SUSPENDED_YIELD_FROM) {
_PyInterpreterFrame *frame = &gen->gi_iframe;
#ifndef NDEBUG
uint8_t oparg;

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.0.13)

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.5)

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.2.1)

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Check warning on line 356 in Objects/genobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

‘oparg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
assert(is_resume(frame, &oparg));
assert((oparg & RESUME_OPARG_LOCATION_MASK) >= RESUME_AFTER_YIELD_FROM);
#endif
return PyStackRef_AsPyObjectNew(_PyFrame_StackPeek(frame));
}
return NULL;
Expand Down Expand Up @@ -370,11 +385,11 @@
Py_DECREF(yf);
}
_PyInterpreterFrame *frame = &gen->gi_iframe;
if (is_resume(frame->instr_ptr)) {
uint8_t oparg;
if (is_resume(frame, &oparg)) {
/* We can safely ignore the outermost try block
* as it is automatically generated to handle
* StopIteration. */
int oparg = frame->instr_ptr->op.arg;
if (oparg & RESUME_OPARG_DEPTH1_MASK) {
// RESUME after YIELD_VALUE and exception depth is 1
assert((oparg & RESUME_OPARG_LOCATION_MASK) != RESUME_AT_FUNC_START);
Expand Down
Loading
0