GH-135379: Remove types from stack items in code generator. (GH-135384)

* Make casts explicit in the instruction definitions
This commit is contained in:
Mark Shannon 2025-06-11 15:52:25 +01:00 committed by GitHub
parent 49d72365cd
commit c87b5b2cb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 257 additions and 255 deletions

View file

@ -604,7 +604,7 @@
_PyStackRef container;
_PyStackRef getitem;
_PyStackRef sub;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 5 cache entries */
// _CHECK_PEP_523
{
@ -650,19 +650,20 @@
// _BINARY_OP_SUBSCR_INIT_CALL
{
sub = stack_pointer[-1];
new_frame = _PyFrame_PushUnchecked(tstate, getitem, 2, frame);
new_frame->localsplus[0] = container;
new_frame->localsplus[1] = sub;
_PyInterpreterFrame* pushed_frame = _PyFrame_PushUnchecked(tstate, getitem, 2, frame);
pushed_frame->localsplus[0] = container;
pushed_frame->localsplus[1] = sub;
frame->return_offset = 6 ;
new_frame = PyStackRef_Wrap(pushed_frame);
}
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -1708,8 +1709,8 @@
_PyStackRef init;
_PyStackRef self;
_PyStackRef *args;
_PyInterpreterFrame *init_frame;
_PyInterpreterFrame *new_frame;
_PyStackRef init_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -1792,17 +1793,17 @@
stack_pointer = _PyFrame_GetStackPointer(frame);
JUMP_TO_LABEL(error);
}
init_frame = temp;
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
tstate->py_recursion_remaining--;
init_frame = PyStackRef_Wrap(temp);
}
// _PUSH_FRAME
{
new_frame = init_frame;
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -1828,7 +1829,7 @@
_PyStackRef null;
_PyStackRef self_or_null;
_PyStackRef *args;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -1921,12 +1922,13 @@
args = &stack_pointer[-oparg];
int has_self = !PyStackRef_IsNull(self_or_null);
STAT_INC(CALL, hit);
new_frame = _PyFrame_PushUnchecked(tstate, callable, oparg + has_self, frame);
_PyStackRef *first_non_self_local = new_frame->localsplus + has_self;
new_frame->localsplus[0] = self_or_null;
_PyInterpreterFrame *pushed_frame = _PyFrame_PushUnchecked(tstate, callable, oparg + has_self, frame);
_PyStackRef *first_non_self_local = pushed_frame->localsplus + has_self;
pushed_frame->localsplus[0] = self_or_null;
for (int i = 0; i < oparg; i++) {
first_non_self_local[i] = args[i];
}
new_frame = PyStackRef_Wrap(pushed_frame);
}
// _SAVE_RETURN_OFFSET
{
@ -1940,11 +1942,11 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -1970,7 +1972,7 @@
_PyStackRef null;
_PyStackRef self_or_null;
_PyStackRef *args;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -2056,7 +2058,7 @@
if (temp == NULL) {
JUMP_TO_LABEL(error);
}
new_frame = temp;
new_frame = PyStackRef_Wrap(temp);
}
// _SAVE_RETURN_OFFSET
{
@ -2070,9 +2072,9 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -3040,7 +3042,7 @@
_PyStackRef self_or_null;
_PyStackRef *args;
_PyStackRef kwnames;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -3127,7 +3129,7 @@
if (temp == NULL) {
JUMP_TO_LABEL(error);
}
new_frame = temp;
new_frame = PyStackRef_Wrap(temp);
}
// _SAVE_RETURN_OFFSET
{
@ -3141,9 +3143,9 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -3304,7 +3306,7 @@
_PyStackRef self_or_null;
_PyStackRef *args;
_PyStackRef kwnames;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -3364,7 +3366,7 @@
if (temp == NULL) {
JUMP_TO_LABEL(error);
}
new_frame = temp;
new_frame = PyStackRef_Wrap(temp);
}
// _SAVE_RETURN_OFFSET
{
@ -3378,9 +3380,9 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -4163,7 +4165,7 @@
_PyStackRef callable;
_PyStackRef self_or_null;
_PyStackRef *args;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -4227,12 +4229,13 @@
args = &stack_pointer[-oparg];
int has_self = !PyStackRef_IsNull(self_or_null);
STAT_INC(CALL, hit);
new_frame = _PyFrame_PushUnchecked(tstate, callable, oparg + has_self, frame);
_PyStackRef *first_non_self_local = new_frame->localsplus + has_self;
new_frame->localsplus[0] = self_or_null;
_PyInterpreterFrame *pushed_frame = _PyFrame_PushUnchecked(tstate, callable, oparg + has_self, frame);
_PyStackRef *first_non_self_local = pushed_frame->localsplus + has_self;
pushed_frame->localsplus[0] = self_or_null;
for (int i = 0; i < oparg; i++) {
first_non_self_local[i] = args[i];
}
new_frame = PyStackRef_Wrap(pushed_frame);
}
// _SAVE_RETURN_OFFSET
{
@ -4246,11 +4249,11 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
stack_pointer += -2 - oparg;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -4275,7 +4278,7 @@
_PyStackRef callable;
_PyStackRef self_or_null;
_PyStackRef *args;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -4334,7 +4337,7 @@
if (temp == NULL) {
JUMP_TO_LABEL(error);
}
new_frame = temp;
new_frame = PyStackRef_Wrap(temp);
}
// _SAVE_RETURN_OFFSET
{
@ -4348,9 +4351,9 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -5785,8 +5788,8 @@
INSTRUCTION_STATS(FOR_ITER_GEN);
static_assert(INLINE_CACHE_ENTRIES_FOR_ITER == 1, "incorrect cache size");
_PyStackRef iter;
_PyInterpreterFrame *gen_frame;
_PyInterpreterFrame *new_frame;
_PyStackRef gen_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -5818,21 +5821,22 @@
JUMP_TO_PREDICTED(FOR_ITER);
}
STAT_INC(FOR_ITER, hit);
gen_frame = &gen->gi_iframe;
_PyFrame_StackPush(gen_frame, PyStackRef_None);
_PyInterpreterFrame *pushed_frame = &gen->gi_iframe;
_PyFrame_StackPush(pushed_frame, PyStackRef_None);
gen->gi_frame_state = FRAME_EXECUTING;
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
gen_frame->previous = frame;
pushed_frame->previous = frame;
frame->return_offset = (uint16_t)( 2 + oparg);
gen_frame = PyStackRef_Wrap(pushed_frame);
}
// _PUSH_FRAME
{
new_frame = gen_frame;
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -8650,7 +8654,7 @@
INSTRUCTION_STATS(LOAD_ATTR_PROPERTY);
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyInterpreterFrame *new_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -8701,8 +8705,9 @@
JUMP_TO_PREDICTED(LOAD_ATTR);
}
STAT_INC(LOAD_ATTR, hit);
new_frame = _PyFrame_PushUnchecked(tstate, PyStackRef_FromPyObjectNew(fget), 1, frame);
new_frame->localsplus[0] = owner;
_PyInterpreterFrame *pushed_frame = _PyFrame_PushUnchecked(tstate, PyStackRef_FromPyObjectNew(fget), 1, frame);
pushed_frame->localsplus[0] = owner;
new_frame = PyStackRef_Wrap(pushed_frame);
}
// _SAVE_RETURN_OFFSET
{
@ -8716,11 +8721,11 @@
// _PUSH_FRAME
{
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;
@ -10661,8 +10666,8 @@
static_assert(INLINE_CACHE_ENTRIES_SEND == 1, "incorrect cache size");
_PyStackRef receiver;
_PyStackRef v;
_PyInterpreterFrame *gen_frame;
_PyInterpreterFrame *new_frame;
_PyStackRef gen_frame;
_PyStackRef new_frame;
/* Skip 1 cache entry */
// _CHECK_PEP_523
{
@ -10688,24 +10693,25 @@
JUMP_TO_PREDICTED(SEND);
}
STAT_INC(SEND, hit);
gen_frame = &gen->gi_iframe;
_PyFrame_StackPush(gen_frame, PyStackRef_MakeHeapSafe(v));
_PyInterpreterFrame *pushed_frame = &gen->gi_iframe;
_PyFrame_StackPush(pushed_frame, PyStackRef_MakeHeapSafe(v));
gen->gi_frame_state = FRAME_EXECUTING;
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
assert( 2 + oparg <= UINT16_MAX);
frame->return_offset = (uint16_t)( 2 + oparg);
gen_frame->previous = frame;
pushed_frame->previous = frame;
gen_frame = PyStackRef_Wrap(pushed_frame);
}
// _PUSH_FRAME
{
new_frame = gen_frame;
assert(tstate->interp->eval_frame == NULL);
_PyInterpreterFrame *temp = new_frame;
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
assert(new_frame->previous == frame || new_frame->previous->previous == frame);
assert(temp->previous == frame || temp->previous->previous == frame);
CALL_STAT_INC(inlined_py_calls);
frame = tstate->current_frame = temp;
tstate->py_recursion_remaining--;