Skip to content

Commit 234cfd2

Browse files
committed
Remove TOS caching parts
1 parent 492df4e commit 234cfd2

File tree

11 files changed

+2006
-4447
lines changed

11 files changed

+2006
-4447
lines changed

Include/internal/pycore_interpframe.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static inline PyFunctionObject *_PyFrame_GetFunction(_PyInterpreterFrame *f) {
4343
}
4444

4545
static inline _PyStackRef *_PyFrame_Stackbase(_PyInterpreterFrame *f) {
46-
return (f->localsplus + _PyFrame_GetCode(f)->co_nlocalsplus + 1);
46+
return (f->localsplus + _PyFrame_GetCode(f)->co_nlocalsplus);
4747
}
4848

4949
static inline _PyStackRef _PyFrame_StackPeek(_PyInterpreterFrame *f) {
@@ -134,7 +134,7 @@ _PyFrame_Initialize(
134134
frame->f_builtins = func_obj->func_builtins;
135135
frame->f_globals = func_obj->func_globals;
136136
frame->f_locals = locals;
137-
frame->stackpointer = frame->localsplus + code->co_nlocalsplus + 1;
137+
frame->stackpointer = frame->localsplus + code->co_nlocalsplus;
138138
frame->frame_obj = NULL;
139139
#ifdef Py_GIL_DISABLED
140140
_PyFrame_InitializeTLBC(tstate, frame, code);
@@ -149,7 +149,7 @@ _PyFrame_Initialize(
149149
frame->lltrace = 0;
150150
#endif
151151

152-
for (int i = null_locals_from; i <= code->co_nlocalsplus; i++) {
152+
for (int i = null_locals_from; i < code->co_nlocalsplus; i++) {
153153
frame->localsplus[i] = PyStackRef_NULL;
154154
}
155155
}
@@ -317,7 +317,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
317317
#endif
318318
frame->f_locals = NULL;
319319
assert(stackdepth <= code->co_stacksize);
320-
frame->stackpointer = frame->localsplus + code->co_nlocalsplus + stackdepth + 1;
320+
frame->stackpointer = frame->localsplus + code->co_nlocalsplus + stackdepth;
321321
frame->frame_obj = NULL;
322322
#ifdef Py_GIL_DISABLED
323323
_PyFrame_InitializeTLBC(tstate, frame, code);

Lib/test/test_sys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,9 @@ def func():
16611661
return sys._getframe()
16621662
x = func()
16631663
if support.Py_GIL_DISABLED:
1664-
INTERPRETER_FRAME = '9PihcPP'
1664+
INTERPRETER_FRAME = '9PihcP'
16651665
else:
1666-
INTERPRETER_FRAME = '9PhcPP'
1666+
INTERPRETER_FRAME = '9PhcP'
16671667
check(x, size('3PiccPPP' + INTERPRETER_FRAME + 'P'))
16681668
# function
16691669
def func(): pass

Objects/codeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
546546
/* derived values */
547547
co->co_nlocalsplus = nlocalsplus;
548548
co->co_nlocals = nlocals;
549-
co->co_framesize = nlocalsplus + con->stacksize + FRAME_SPECIALS_SIZE + 1;
549+
co->co_framesize = nlocalsplus + con->stacksize + FRAME_SPECIALS_SIZE;
550550
co->co_ncellvars = ncellvars;
551551
co->co_nfreevars = nfreevars;
552552
#ifdef Py_GIL_DISABLED

Python/bytecodes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,9 +3997,8 @@ dummy_func(
39973997
tstate, (PyCodeObject *)&_Py_InitCleanup, 1, frame);
39983998
assert(_PyFrame_GetBytecode(shim)[0].op.code == EXIT_INIT_CHECK);
39993999
assert(_PyFrame_GetBytecode(shim)[1].op.code == RETURN_VALUE);
4000-
shim->localsplus[0] = PyStackRef_NULL;
40014000
/* Push self onto stack of shim */
4002-
shim->localsplus[1] = PyStackRef_DUP(self[0]);
4001+
shim->localsplus[0] = PyStackRef_DUP(self[0]);
40034002
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
40044003
tstate, init[0], NULL, args-1, oparg+1, NULL, shim);
40054004
DEAD(init);

Python/ceval.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,13 @@ dump_stack(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
190190

191191
static void
192192
lltrace_instruction(_PyInterpreterFrame *frame,
193-
_PyStackRef _tos,
194193
_PyStackRef *stack_pointer,
195194
_Py_CODEUNIT *next_instr,
196195
int opcode,
197196
int oparg)
198197
{
199198
int offset = 0;
200199
if (frame->owner < FRAME_OWNED_BY_INTERPRETER) {
201-
printf("_tos = ");
202-
dump_item(_tos);
203-
printf("; ");
204200
dump_stack(frame, stack_pointer);
205201
offset = (int)(next_instr - _PyFrame_GetBytecode(frame));
206202
}
@@ -947,13 +943,6 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch)
947943
/* This setting is reversed below following _PyEval_EvalFrameDefault */
948944
#endif
949945

950-
#ifdef Py_GIL_DISABLED
951-
#define Py_FREE_THREADING 1
952-
#else
953-
#define Py_FREE_THREADING 0
954-
#endif
955-
956-
957946
#if Py_TAIL_CALL_INTERP
958947
#include "opcode_targets.h"
959948
#include "generated_cases.c.h"
@@ -1003,7 +992,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
1003992
#endif
1004993
entry_frame.f_executable = PyStackRef_None;
1005994
entry_frame.instr_ptr = (_Py_CODEUNIT *)_Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS + 1;
1006-
entry_frame.stackpointer = entry_frame.localsplus + 1;
995+
entry_frame.stackpointer = entry_frame.localsplus;
1007996
entry_frame.owner = FRAME_OWNED_BY_INTERPRETER;
1008997
entry_frame.visited = 0;
1009998
entry_frame.return_offset = 0;
@@ -1050,7 +1039,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10501039
_PyExecutorObject *current_executor = NULL;
10511040
const _PyUOpInstruction *next_uop = NULL;
10521041
#endif
1053-
_PyStackRef _tos = PyStackRef_NULL;
10541042
#if Py_TAIL_CALL_INTERP
10551043
return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, 0);
10561044
#else

Python/ceval_macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
111111
#ifdef Py_DEBUG
112112
#define PRE_DISPATCH_GOTO() if (frame->lltrace >= 5) { \
113-
lltrace_instruction(frame, _tos, stack_pointer, next_instr, opcode, oparg); }
113+
lltrace_instruction(frame, stack_pointer, next_instr, opcode, oparg); }
114114
#else
115115
#define PRE_DISPATCH_GOTO() ((void)0)
116116
#endif
@@ -238,7 +238,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
238238
#endif
239239

240240
#define WITHIN_STACK_BOUNDS() \
241-
(frame->owner == FRAME_OWNED_BY_INTERPRETER || (STACK_LEVEL() >= -1 && STACK_LEVEL() <= STACK_SIZE()))
241+
(frame->owner == FRAME_OWNED_BY_INTERPRETER || (STACK_LEVEL() >= 0 && STACK_LEVEL() <= STACK_SIZE()))
242242

243243
/* Data access macros */
244244
#define FRAME_CO_CONSTS (_PyFrame_GetCode(frame)->co_consts)

Python/executor_cases.c.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)