8000 gh-104584: Fix error handling from backedge optimization by gvanrossum · Pull Request #106484 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104584: Fix error handling from backedge optimization #106484

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 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve offsets in debug output
Offsets in debug output identifying the start of the trace
are now measured in bytes (and the text shows it).
  • Loading branch information
gvanrossum committed Jul 6, 2023
commit 9a911cb4ba20e41a2b28667d8b2ed32fe3f8e3c4
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2737,11 +2737,11 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
#endif

DPRINTF(3,
"Entering _PyUopExecute for %s (%s:%d) at offset %ld\n",
"Entering _PyUopExecute for %s (%s:%d) at byte offset %ld\n",
PyUnicode_AsUTF8(_PyFrame_GetCode(frame)->co_qualname),
PyUnicode_AsUTF8(_PyFrame_GetCode(frame)->co_filename),
_PyFrame_GetCode(frame)->co_firstlineno,
(long)(frame->prev_instr + 1 -
2 * (long)(frame->prev_instr + 1 -
(_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive));

PyThreadState *tstate = _PyThreadState_GET();
Expand Down
16 changes: 9 additions & 7 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNI
}
insert_executor(code, src, index, executor);
assert(frame->prev_instr == src);
frame->prev_instr = dest - 1;
return executor->execute(executor, frame, stack_pointer);
jump_to_destination:
frame->prev_instr = dest - 1;
Expand All @@ -201,7 +202,7 @@ PyUnstable_GetExecutor(PyCodeObject *code, int offset)
}
i += _PyInstruction_GetLength(code, i);
}
PyErr_SetString(PyExc_ValueError, "no executor at given offset");
PyErr_SetString(PyExc_ValueError, "no executor at given byte offset");
return NULL;
}

Expand Down Expand Up @@ -373,6 +374,7 @@ translate_bytecode_to_trace(
_PyUOpInstruction *trace,
int max_length)
{
_Py_CODEUNIT *initial_instr = instr;
int trace_length = 0;

#ifdef Py_DEBUG
Expand All @@ -398,11 +400,11 @@ translate_bytecode_to_trace(
trace_length++;

DPRINTF(4,
"Optimizing %s (%s:%d) at offset %ld\n",
"Optimizing %s (%s:%d) at byte offset %ld\n",
PyUnicode_AsUTF8(code->co_qualname),
PyUnicode_AsUTF8(code->co_filename),
code->co_firstlineno,
(long)(instr - (_Py_CODEUNIT *)code->co_code_adaptive));
2 * (long)(initial_instr - (_Py_CODEUNIT *)code->co_code_adaptive));

for (;;) {
ADD_TO_TRACE(SAVE_IP, (int)(instr - (_Py_CODEUNIT *)code->co_code_adaptive));
Expand Down Expand Up @@ -492,21 +494,21 @@ translate_bytecode_to_trace(
if (trace_length > 3) {
ADD_TO_TRACE(EXIT_TRACE, 0);
DPRINTF(1,
"Created a trace for %s (%s:%d) at offset %ld -- length %d\n",
"Created a trace for %s (%s:%d) at byte offset %ld -- length %d\n",
PyUnicode_AsUTF8(code->co_qualname),
PyUnicode_AsUTF8(code->co_filename),
code->co_firstlineno,
(long)(instr - (_Py_CODEUNIT *)code->co_code_adaptive),
2 * (long)(initial_instr - (_Py_CODEUNIT *)code->co_code_adaptive),
trace_length);
return trace_length;
}
else {
DPRINTF(4,
"No trace for %s (%s:%d) at offset %ld\n",
"No trace for %s (%s:%d) at byte offset %ld\n",
PyUnicode_AsUTF8(code->co_qualname),
PyUnicode_AsUTF8(code->co_filename),
code->co_firstlineno,
4AD1 (long)(instr - (_Py_CODEUNIT *)code->co_code_adaptive));
2 * (long)(initial_instr - (_Py_CODEUNIT *)code->co_code_adaptive));
}
return 0;

Expand Down
0