Skip to content

Commit

Permalink
remove prev_traced_instr
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Oct 11, 2023
1 parent 8bade18 commit 8b14bde
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 52 deletions.
7 changes: 0 additions & 7 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ typedef struct _PyInterpreterFrame {
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
// NOTE: This is not necessarily the last instruction started in the given
// frame. Rather, it is the code unit *prior to* the *next* instruction. For
// example, it may be an inline CACHE entry, an instruction we just jumped
// over, or (in the case of a newly-created frame) a totally invalid value:
_Py_CODEUNIT *prev_traced_instr;
/* The instruction that is currently executing (possibly not started yet). */
_Py_CODEUNIT *instr_ptr;
int stacktop; /* Offset of TOS from localsplus */
Expand Down Expand Up @@ -151,7 +146,6 @@ _PyFrame_Initialize(
frame->f_locals = locals;
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->prev_traced_instr = NULL;
frame->instr_ptr = _PyCode_CODE(code);
frame->new_return_offset = 0;
frame->yield_offset = 0;
Expand Down Expand Up @@ -316,7 +310,6 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
frame->f_locals = NULL;
frame->stacktop = code->co_nlocalsplus + stackdepth;
frame->frame_obj = NULL;
frame->prev_traced_instr = NULL;
frame->instr_ptr = _PyCode_CODE(code) + previous_instr + 1;
frame->owner = FRAME_OWNED_BY_THREAD;
frame->new_return_offset = 0;
Expand Down
28 changes: 14 additions & 14 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,10 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->instr_ptr += frame->new_return_offset;
frame->new_return_offset = 0;
_PyFrame_StackPush(frame, retval);
LOAD_SP();
LOAD_IP();
frame->yield_offset = 0;
#if LLTRACE && TIER_ONE
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
if (lltrace < 0) {
Expand Down Expand Up @@ -822,8 +821,7 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->instr_ptr += frame->new_return_offset;
frame->new_return_offset = 0;
frame->yield_offset = 0;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
}
Expand All @@ -849,8 +847,7 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->instr_ptr += frame->new_return_offset;
frame->new_return_offset = 0;
frame->yield_offset = 0;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
}
Expand Down Expand Up @@ -1050,6 +1047,8 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
frame->new_return_offset = frame->yield_offset;
frame->yield_offset = 0;
goto resume_frame;
}

Expand All @@ -1070,8 +1069,8 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
frame->instr_ptr += frame->yield_offset;
frame->new_return_offset = frame->yield_offset = 0;
frame->new_return_offset = frame->yield_offset;
frame->yield_offset = 0;
goto resume_frame;
}

Expand Down Expand Up @@ -3009,8 +3008,6 @@ dummy_func(
Py_DECREF(args[i]);
}
ERROR_IF(res == NULL, error);
frame->yield_offset = 0;
frame->new_return_offset = 0;
CHECK_EVAL_BREAKER();
}

Expand Down Expand Up @@ -3760,8 +3757,7 @@ dummy_func(
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
frame = tstate->current_frame = prev;
frame->instr_ptr += frame->new_return_offset;
frame->new_return_offset = 0;
frame->yield_offset = 0;
_PyFrame_StackPush(frame, (PyObject *)gen);
goto resume_frame;
}
Expand Down Expand Up @@ -3958,8 +3954,12 @@ dummy_func(

op(_SAVE_CURRENT_IP, (--)) {
#if TIER_ONE
assert(frame->new_return_offset == 0);
frame->new_return_offset = next_instr - frame->instr_ptr + frame->new_return_offset;
if (frame->new_return_offset == 0) {
frame->new_return_offset = next_instr - frame->instr_ptr;
}
else {
assert(next_instr == frame->instr_ptr);
}
#endif
#if TIER_TWO
// Relies on a preceding _SET_IP
Expand Down
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
#endif
{
DUMP_FRAME("INSTRUMENTED_LINE");
_Py_CODEUNIT *prev = frame->prev_traced_instr;
_Py_CODEUNIT *here = frame->instr_ptr = frame->prev_traced_instr = next_instr;
_Py_CODEUNIT *prev = frame->instr_ptr;
_Py_CODEUNIT *here = frame->instr_ptr = next_instr;
_PyFrame_SetStackPointer(frame, stack_pointer);
int original_opcode = _Py_call_instrumentation_line(
tstate, frame, here, prev);
Expand Down
7 changes: 4 additions & 3 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
do { \
if (VERBOSE) fprintf(stderr, "--- %s: frame=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d yield_offset=%d\n", _PyOpcode_OpName[op], frame, frame->instr_ptr, next_instr, frame->new_return_offset, frame->yield_offset); \
frame->instr_ptr = next_instr++; \
frame->new_return_offset = 0; \
assert(frame->yield_offset == 0); \
if (VERBOSE) fprintf(stderr, "=== %s: frame=%p frame->instr_ptr=%p next_instr=%p new_return_offset=%d yield_offset=%d\n", _PyOpcode_OpName[op], frame, frame->instr_ptr, next_instr, frame->new_return_offset, frame->yield_offset); \
} while(0)
#endif
Expand Down Expand Up @@ -352,6 +354,7 @@ do { \
do { \
_PyFrame_SetStackPointer(frame, stack_pointer); \
next_instr = _Py_call_instrumentation_jump(tstate, event, frame, src, dest); \
frame->new_return_offset = frame->yield_offset = 0; \
stack_pointer = _PyFrame_GetStackPointer(frame); \
if (next_instr == NULL) { \
next_instr = (dest)+1; \
Expand Down Expand Up @@ -393,9 +396,7 @@ static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) {
#if TIER_ONE

#define LOAD_IP() do { \
frame->instr_ptr += frame->new_return_offset; \
frame->new_return_offset = 0; \
next_instr = frame->instr_ptr; \
next_instr = frame->instr_ptr + frame->new_return_offset; \
} while (0)

#define STORE_SP() \
Expand Down
11 changes: 7 additions & 4 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 33 additions & 22 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b14bde

Please sign in to comment.