Skip to content

Commit

Permalink
remove yield_offset from the frame
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Oct 13, 2023
1 parent cbee4f8 commit 3a9a029
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 49 deletions.
7 changes: 0 additions & 7 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ typedef struct _PyInterpreterFrame {
/* The instruction that is currently executing (possibly not started yet). */
_Py_CODEUNIT *instr_ptr;
int stacktop; /* Offset of TOS from localsplus */
/* The yield_offset determines where a `YIELD_VALUE` should go in the caller,
* relative to `instr_ptr`.
* It must be set by SEND, SEND_GEN, FOR_ITER_GEN and used by YIELD_VALUE.
*/
uint16_t yield_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
Expand Down Expand Up @@ -136,7 +131,6 @@ _PyFrame_Initialize(
frame->frame_obj = NULL;
frame->instr_ptr = _PyCode_CODE(code);
frame->next_instr_offset = 0;
frame->yield_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;

for (int i = null_locals_from; i < code->co_nlocalsplus; i++) {
Expand Down Expand Up @@ -301,7 +295,6 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
frame->instr_ptr = _PyCode_CODE(code) + 1;
frame->owner = FRAME_OWNED_BY_THREAD;
frame->next_instr_offset = 0;
frame->yield_offset = 0;
return frame;
}

Expand Down
17 changes: 0 additions & 17 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ dummy_func(
new_frame->localsplus[0] = container;
new_frame->localsplus[1] = sub;
SKIP_OVER(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
frame->yield_offset = 0;
assert(1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR == next_instr - frame->instr_ptr);
frame->next_instr_offset = 1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR;
DISPATCH_INLINED(new_frame);
Expand Down Expand Up @@ -795,7 +794,6 @@ dummy_func(
_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 All @@ -822,7 +820,6 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->yield_offset = 0;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
}
Expand All @@ -847,7 +844,6 @@ dummy_func(
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->yield_offset = 0;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
}
Expand Down Expand Up @@ -985,7 +981,6 @@ dummy_func(
tstate->exc_info = &gen->gi_exc_state;
SKIP_OVER(INLINE_CACHE_ENTRIES_SEND);
assert(NEXT_INSTR_OFFSET_FOR_YIELD == next_instr - frame->instr_ptr);
frame->yield_offset = NEXT_INSTR_OFFSET_FOR_YIELD;
frame->next_instr_offset = 1 + INLINE_CACHE_ENTRIES_SEND + oparg;
DISPATCH_INLINED(gen_frame);
}
Expand Down Expand Up @@ -1025,7 +1020,6 @@ dummy_func(
tstate->exc_info = &gen->gi_exc_state;
SKIP_OVER(INLINE_CACHE_ENTRIES_SEND);
assert(NEXT_INSTR_OFFSET_FOR_YIELD == next_instr - frame->instr_ptr);
frame->yield_offset = NEXT_INSTR_OFFSET_FOR_YIELD;
frame->next_instr_offset = 1 + INLINE_CACHE_ENTRIES_SEND + oparg;
DISPATCH_INLINED(gen_frame);
}
Expand All @@ -1048,9 +1042,7 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
assert(frame->yield_offset == NEXT_INSTR_OFFSET_FOR_YIELD || frame->owner == FRAME_OWNED_BY_CSTACK);
frame->next_instr_offset = frame->owner == FRAME_OWNED_BY_CSTACK ? 0 : NEXT_INSTR_OFFSET_FOR_YIELD;
frame->yield_offset = 0;
goto resume_frame;
}

Expand All @@ -1071,9 +1063,7 @@ dummy_func(
frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
assert(frame->yield_offset == NEXT_INSTR_OFFSET_FOR_YIELD || frame->owner == FRAME_OWNED_BY_CSTACK);
frame->next_instr_offset = frame->owner == FRAME_OWNED_BY_CSTACK ? 0 : NEXT_INSTR_OFFSET_FOR_YIELD;
frame->yield_offset = 0;
goto resume_frame;
}

Expand Down Expand Up @@ -2691,7 +2681,6 @@ dummy_func(
assert(next_instr[oparg].op.code == END_FOR ||
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
assert(NEXT_INSTR_OFFSET_FOR_YIELD == next_instr - frame->instr_ptr);
frame->yield_offset = NEXT_INSTR_OFFSET_FOR_YIELD;
frame->next_instr_offset = 1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg;
DISPATCH_INLINED(gen_frame);
}
Expand Down Expand Up @@ -3091,7 +3080,6 @@ dummy_func(
op(_PUSH_FRAME, (new_frame: _PyInterpreterFrame* -- unused)) {
// Write it out explicitly because it's subtly different.
// Eventually this should be the only occurrence of this code.
frame->yield_offset = 0;
frame->next_instr_offset = next_instr - frame->instr_ptr;
assert(tstate->interp->eval_frame == NULL);
STORE_SP();
Expand Down Expand Up @@ -3160,7 +3148,6 @@ dummy_func(
// Manipulate stack and cache directly since we leave using DISPATCH_INLINED().
STACK_SHRINK(oparg + 2);
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->yield_offset = 0;
assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - frame->instr_ptr);
frame->next_instr_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
DISPATCH_INLINED(new_frame);
Expand Down Expand Up @@ -3239,7 +3226,6 @@ dummy_func(
init_frame->localsplus[i+1] = args[i];
}
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->yield_offset = 0;
assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - frame->instr_ptr);
frame->next_instr_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
STACK_SHRINK(oparg+2);
Expand Down Expand Up @@ -3610,7 +3596,6 @@ dummy_func(
if (new_frame == NULL) {
goto error;
}
frame->yield_offset = 0;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}
Expand Down Expand Up @@ -3707,7 +3692,6 @@ dummy_func(
if (new_frame == NULL) {
goto error;
}
frame->yield_offset = 0;
frame->next_instr_offset = next_instr - frame->instr_ptr;
DISPATCH_INLINED(new_frame);
}
Expand Down Expand Up @@ -3781,7 +3765,6 @@ dummy_func(
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
frame = tstate->current_frame = prev;
frame->yield_offset = 0;
_PyFrame_StackPush(frame, (PyObject *)gen);
goto resume_frame;
}
Expand Down
5 changes: 2 additions & 3 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
entry_frame.instr_ptr = (_Py_CODEUNIT *)_Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS + 1;
entry_frame.stacktop = 0;
entry_frame.owner = FRAME_OWNED_BY_CSTACK;
entry_frame.yield_offset = 0;
entry_frame.next_instr_offset = 0;
/* Push frame */
entry_frame.previous = tstate->current_frame;
Expand Down Expand Up @@ -739,7 +738,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
#define SET_LOCALS_FROM_FRAME() \
/* Jump back to the last instruction executed... */ \
next_instr = frame->instr_ptr + frame->next_instr_offset; \
frame->next_instr_offset = frame->yield_offset = 0; \
frame->next_instr_offset = 0; \
stack_pointer = _PyFrame_GetStackPointer(frame);

start_frame:
Expand Down Expand Up @@ -932,7 +931,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
_PyInterpreterFrame *dying = frame;
frame = tstate->current_frame = dying->previous;
_PyEval_FrameClearAndPop(tstate, dying);
frame->yield_offset = frame->next_instr_offset = 0;
frame->next_instr_offset = 0;
if (frame == &entry_frame) {
/* Restore previous frame and exit */
tstate->current_frame = frame->previous;
Expand Down
3 changes: 1 addition & 2 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
if (0) fprintf(stderr, "-- %s frame=%p\n", _PyOpcode_OpName[op], frame); \
frame->instr_ptr = next_instr++; \
frame->next_instr_offset = 0; \
assert(frame->yield_offset == 0); \
} while(0)
#endif

Expand Down Expand Up @@ -351,7 +350,7 @@ do { \
do { \
_PyFrame_SetStackPointer(frame, stack_pointer); \
next_instr = _Py_call_instrumentation_jump(tstate, event, frame, src, dest); \
frame->next_instr_offset = frame->yield_offset = 0; \
frame->next_instr_offset = 0; \
stack_pointer = _PyFrame_GetStackPointer(frame); \
if (next_instr == NULL) { \
next_instr = (dest)+1; \
Expand Down
1 change: 0 additions & 1 deletion Python/executor_cases.c.h

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

19 changes: 0 additions & 19 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 3a9a029

Please sign in to comment.