Skip to content

Commit

Permalink
rename new_return_offset to next_instr_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Oct 11, 2023
1 parent 3639796 commit 41bba62
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 62 deletions.
20 changes: 9 additions & 11 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ typedef struct _PyInterpreterFrame {
* It must be set by SEND, SEND_GEN, FOR_ITER_GEN and used by YIELD_VALUE.
*/
uint16_t yield_offset;
/* The new_return_offset determines where a `RETURN` should go in the caller,
* relative to `instr_ptr`.
* It is only meaningful to the callee,
* so it needs to be set in any CALL (to a Python function)
* or SEND (to a coroutine or generator).
* If there is no callee, then it is meaningless. */
uint16_t new_return_offset;
/* The next_instr_offset determines where the next instruction is relative
* to instr_ptr. It enables us to keep instr_ptr pointing to the current
* instruction until it is time to begin executing the next one. This is
* necessary for tracebacks and tracing. */
uint16_t next_instr_offset;
char owner;
/* Locals and stack */
PyObject *localsplus[1];
Expand All @@ -91,8 +89,8 @@ dump_frame_ip(const char* title, _PyInterpreterFrame *frame) {
if (frame) {
fprintf(stderr, "%s: frame=%p frame->instr_ptr=%p ",
title, frame, frame->instr_ptr);
fprintf(stderr, "new_return_offset=%d yield_offset=%d \n",
frame->new_return_offset, frame->yield_offset);
fprintf(stderr, "next_instr_offset=%d yield_offset=%d \n",
frame->next_instr_offset, frame->yield_offset);
}
}

Expand Down Expand Up @@ -147,7 +145,7 @@ _PyFrame_Initialize(
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->instr_ptr = _PyCode_CODE(code);
frame->new_return_offset = 0;
frame->next_instr_offset = 0;
frame->yield_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;

Expand Down Expand Up @@ -312,7 +310,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
frame->frame_obj = NULL;
frame->instr_ptr = _PyCode_CODE(code) + previous_instr + 1;
frame->owner = FRAME_OWNED_BY_THREAD;
frame->new_return_offset = 0;
frame->next_instr_offset = 0;
frame->yield_offset = 0;
return frame;
}
Expand Down
32 changes: 16 additions & 16 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ dummy_func(
new_frame->localsplus[1] = sub;
SKIP_OVER(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
frame->yield_offset = 0;
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}

Expand Down Expand Up @@ -986,7 +986,7 @@ dummy_func(
tstate->exc_info = &gen->gi_exc_state;
SKIP_OVER(INLINE_CACHE_ENTRIES_SEND);
frame->yield_offset = next_instr - frame->instr_ptr;
frame->new_return_offset = next_instr - frame->instr_ptr + oparg;
frame->next_instr_offset = next_instr - frame->instr_ptr + oparg;
DISPATCH_INLINED(gen_frame);
}
if (Py_IsNone(v) && PyIter_Check(receiver)) {
Expand Down Expand Up @@ -1025,7 +1025,7 @@ dummy_func(
tstate->exc_info = &gen->gi_exc_state;
SKIP_OVER(INLINE_CACHE_ENTRIES_SEND);
frame->yield_offset = next_instr - frame->instr_ptr;
frame->new_return_offset = next_instr - frame->instr_ptr + oparg;
frame->next_instr_offset = next_instr - frame->instr_ptr + oparg;
DISPATCH_INLINED(gen_frame);
}

Expand All @@ -1047,7 +1047,7 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
frame->new_return_offset = frame->yield_offset;
frame->next_instr_offset = frame->yield_offset;
frame->yield_offset = 0;
goto resume_frame;
}
Expand All @@ -1069,7 +1069,7 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
frame->new_return_offset = frame->yield_offset;
frame->next_instr_offset = frame->yield_offset;
frame->yield_offset = 0;
goto resume_frame;
}
Expand Down Expand Up @@ -2022,7 +2022,7 @@ dummy_func(
STACK_SHRINK(1);
new_frame->localsplus[0] = owner;
SKIP_OVER(INLINE_CACHE_ENTRIES_LOAD_ATTR);
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}

Expand All @@ -2049,7 +2049,7 @@ dummy_func(
new_frame->localsplus[0] = owner;
new_frame->localsplus[1] = Py_NewRef(name);
SKIP_OVER(INLINE_CACHE_ENTRIES_LOAD_ATTR);
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}

Expand Down Expand Up @@ -2686,7 +2686,7 @@ dummy_func(
assert(next_instr[oparg].op.code == END_FOR ||
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
frame->yield_offset = next_instr - frame->instr_ptr;
frame->new_return_offset = oparg + next_instr - frame->instr_ptr;
frame->next_instr_offset = oparg + next_instr - frame->instr_ptr;
DISPATCH_INLINED(gen_frame);
}

Expand Down Expand Up @@ -2997,7 +2997,7 @@ dummy_func(
goto error;
}
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}
/* Callable is not a normal Python function */
Expand Down Expand Up @@ -3085,7 +3085,7 @@ dummy_func(
// Write it out explicitly because it's subtly different.
// Eventually this should be the only occurrence of this code.
frame->yield_offset = 0;
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
assert(tstate->interp->eval_frame == NULL);
STORE_SP();
new_frame->previous = frame;
Expand Down Expand Up @@ -3156,7 +3156,7 @@ dummy_func(
STACK_SHRINK(oparg + 2);
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->yield_offset = 0;
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}

Expand Down Expand Up @@ -3234,7 +3234,7 @@ dummy_func(
}
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->yield_offset = 0;
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
STACK_SHRINK(oparg+2);
_PyFrame_SetStackPointer(frame, stack_pointer);
/* Link frames */
Expand Down Expand Up @@ -3604,7 +3604,7 @@ dummy_func(
goto error;
}
frame->yield_offset = 0;
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}
/* Callable is not a normal Python function */
Expand Down Expand Up @@ -3703,7 +3703,7 @@ dummy_func(
goto error;
}
frame->yield_offset = 0;
frame->new_return_offset = next_instr - frame->instr_ptr;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}
result = PyObject_Call(func, callargs, kwargs);
Expand Down Expand Up @@ -3973,8 +3973,8 @@ dummy_func(

op(_SAVE_CURRENT_IP, (--)) {
#if TIER_ONE
if (frame->new_return_offset == 0) {
frame->new_return_offset = next_instr - frame->instr_ptr;
if (frame->next_instr_offset == 0) {
frame->next_instr_offset = next_instr - frame->instr_ptr;
}
else {
assert(next_instr == frame->instr_ptr);
Expand Down
8 changes: 4 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
entry_frame.stacktop = 0;
entry_frame.owner = FRAME_OWNED_BY_CSTACK;
entry_frame.yield_offset = 0;
entry_frame.new_return_offset = 0;
entry_frame.next_instr_offset = 0;
/* Push frame */
entry_frame.previous = tstate->current_frame;
frame->previous = &entry_frame;
Expand Down Expand Up @@ -747,8 +747,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
#define SET_LOCALS_FROM_FRAME() \
/* Jump back to the last instruction executed... */ \
DUMP_FRAME("SET_LOCALS_FROM_FRAME1"); \
next_instr = frame->instr_ptr + frame->new_return_offset; \
frame->new_return_offset = frame->yield_offset = 0; \
next_instr = frame->instr_ptr + frame->next_instr_offset; \
frame->next_instr_offset = frame->yield_offset = 0; \
DUMP_FRAME("SET_LOCALS_FROM_FRAME2"); \
stack_pointer = _PyFrame_GetStackPointer(frame);

Expand Down Expand Up @@ -945,7 +945,7 @@ if (VERBOSE) fprintf(stderr, "Exception Handler: %d\n", handler);
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->yield_offset = frame->new_return_offset = 0;
frame->yield_offset = frame->next_instr_offset = 0;
DUMP_FRAME("exit_unwind");
if (frame == &entry_frame) {
/* Restore previous frame and exit */
Expand Down
12 changes: 6 additions & 6 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
#else
#define INSTRUCTION_START(op) \
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); \
if (VERBOSE) fprintf(stderr, "--- %s: frame=%p frame->instr_ptr=%p next_instr=%p next_instr_offset=%d yield_offset=%d\n", _PyOpcode_OpName[op], frame, frame->instr_ptr, next_instr, frame->next_instr_offset, frame->yield_offset); \
frame->instr_ptr = next_instr++; \
frame->new_return_offset = 0; \
frame->next_instr_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); \
if (VERBOSE) fprintf(stderr, "=== %s: frame=%p frame->instr_ptr=%p next_instr=%p next_instr_offset=%d yield_offset=%d\n", _PyOpcode_OpName[op], frame, frame->instr_ptr, next_instr, frame->next_instr_offset, frame->yield_offset); \
} while(0)
#endif

Expand Down Expand Up @@ -154,7 +154,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
} while (0)
#define JUMPTO(x) do { \
next_instr = _PyCode_CODE(_PyFrame_GetCode(frame)) + (x); \
frame->new_return_offset = 0; \
frame->next_instr_offset = 0; \
} while(0)

/* JUMPBY makes the generator identify the instruction as a jump. SKIP_OVER is
Expand Down Expand Up @@ -354,7 +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; \
frame->next_instr_offset = frame->yield_offset = 0; \
stack_pointer = _PyFrame_GetStackPointer(frame); \
if (next_instr == NULL) { \
next_instr = (dest)+1; \
Expand Down Expand Up @@ -396,7 +396,7 @@ static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) {
#if TIER_ONE

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

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

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

Loading

0 comments on commit 41bba62

Please sign in to comment.