gh-145866: Convert _CALL_METHOD_DESCRIPTOR_NOARGS to leave its inputs on the stack to be cleaned up by _POP_TOP (GH-148227)

This commit is contained in:
Sacul 2026-04-08 23:21:37 +08:00 committed by GitHub
parent d2fa4b2b13
commit bb03c8bd02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 140 additions and 74 deletions

View file

@ -4948,7 +4948,7 @@ dummy_func(
EXIT_IF(!Py_IS_TYPE(self, method->d_common.d_type));
}
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res)) {
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res, c, s)) {
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
@ -4963,15 +4963,16 @@ dummy_func(
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc, self, NULL);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
PyStackRef_CLOSE(self_stackref);
DEAD(args);
DEAD(self_or_null);
PyStackRef_CLOSE(callable);
ERROR_IF(res_o == NULL);
if (res_o == NULL) {
ERROR_NO_POP();
}
c = callable;
s = args[0];
INPUTS_DEAD();
res = PyStackRef_FromPyObjectSteal(res_o);
}
tier2 op(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, (callable, args[oparg], cfunc/4 -- res)) {
tier2 op(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, (callable, args[oparg], cfunc/4 -- res, c, s)) {
assert(oparg == 1);
_PyStackRef self_stackref = args[0];
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
@ -4980,10 +4981,12 @@ dummy_func(
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc_v, self, NULL);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
PyStackRef_CLOSE(self_stackref);
DEAD(args);
PyStackRef_CLOSE(callable);
ERROR_IF(res_o == NULL);
if (res_o == NULL) {
ERROR_NO_POP();
}
c = callable;
s = args[0];
INPUTS_DEAD();
res = PyStackRef_FromPyObjectSteal(res_o);
}
@ -4994,6 +4997,8 @@ dummy_func(
_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS +
_CHECK_RECURSION_LIMIT +
_CALL_METHOD_DESCRIPTOR_NOARGS +
POP_TOP +
POP_TOP +
_CHECK_PERIODIC_AT_END;
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {

View file

@ -17402,13 +17402,15 @@
break;
}
case _CALL_METHOD_DESCRIPTOR_NOARGS_r01: {
case _CALL_METHOD_DESCRIPTOR_NOARGS_r03: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef *args;
_PyStackRef self_or_null;
_PyStackRef callable;
_PyStackRef res;
_PyStackRef c;
_PyStackRef s;
oparg = CURRENT_OPARG();
args = &stack_pointer[-oparg];
self_or_null = stack_pointer[-1 - oparg];
@ -17428,33 +17430,31 @@
stack_pointer = _PyFrame_GetStackPointer(frame);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(self_stackref);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += -2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(callable);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_o == NULL) {
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
c = callable;
s = args[0];
res = PyStackRef_FromPyObjectSteal(res_o);
_tos_cache2 = s;
_tos_cache1 = c;
_tos_cache0 = res;
_tos_cache1 = PyStackRef_ZERO_BITS;
_tos_cache2 = PyStackRef_ZERO_BITS;
SET_CURRENT_CACHED_VALUES(1);
SET_CURRENT_CACHED_VALUES(3);
stack_pointer += -2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _CALL_METHOD_DESCRIPTOR_NOARGS_INLINE_r01: {
case _CALL_METHOD_DESCRIPTOR_NOARGS_INLINE_r03: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef *args;
_PyStackRef callable;
_PyStackRef res;
_PyStackRef c;
_PyStackRef s;
oparg = CURRENT_OPARG();
args = &stack_pointer[-oparg];
callable = stack_pointer[-1 - oparg];
@ -17469,23 +17469,19 @@
stack_pointer = _PyFrame_GetStackPointer(frame);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(self_stackref);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += -1 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(callable);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_o == NULL) {
SET_CURRENT_CACHED_VALUES(0);
JUMP_TO_ERROR();
}
c = callable;
s = args[0];
res = PyStackRef_FromPyObjectSteal(res_o);
_tos_cache2 = s;
_tos_cache1 = c;
_tos_cache0 = res;
_tos_cache1 = PyStackRef_ZERO_BITS;
_tos_cache2 = PyStackRef_ZERO_BITS;
SET_CURRENT_CACHED_VALUES(1);
SET_CURRENT_CACHED_VALUES(3);
stack_pointer += -1 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}

View file

@ -3970,6 +3970,9 @@
_PyStackRef self_or_null;
_PyStackRef *args;
_PyStackRef res;
_PyStackRef c;
_PyStackRef s;
_PyStackRef value;
/* Skip 1 cache entry */
/* Skip 2 cache entries */
// _GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS
@ -4031,24 +4034,35 @@
stack_pointer = _PyFrame_GetStackPointer(frame);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(self_stackref);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += -2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(callable);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (res_o == NULL) {
JUMP_TO_LABEL(error);
}
c = callable;
s = args[0];
res = PyStackRef_FromPyObjectSteal(res_o);
}
// _POP_TOP
{
value = s;
stack_pointer[-2 - oparg] = res;
stack_pointer[-1 - oparg] = c;
stack_pointer += -oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_XCLOSE(value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
// _POP_TOP
{
value = c;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_XCLOSE(value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
// _CHECK_PERIODIC_AT_END
{
stack_pointer[0] = res;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = check_periodics(tstate);
stack_pointer = _PyFrame_GetStackPointer(frame);

View file

@ -1407,7 +1407,7 @@ dummy_func(void) {
ctx->frame->is_c_recursion_checked = true;
}
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res)) {
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res, c, s)) {
PyObject *callable_o = sym_get_const(ctx, callable);
if (callable_o && Py_IS_TYPE(callable_o, &PyMethodDescr_Type)
&& sym_is_not_null(self_or_null)) {
@ -1416,6 +1416,17 @@ dummy_func(void) {
ADD_OP(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, oparg + 1, (uintptr_t)cfunc);
}
res = sym_new_not_null(ctx);
c = callable;
if (sym_is_not_null(self_or_null)) {
args--;
s = args[0];
}
else if (sym_is_null(self_or_null)) {
s = args[0];
}
else {
s = sym_new_unknown(ctx);
}
}
op(_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS, (callable, self_or_null, args[oparg] -- res)) {

View file

@ -4314,9 +4314,13 @@
}
case _CALL_METHOD_DESCRIPTOR_NOARGS: {
JitOptRef *args;
JitOptRef self_or_null;
JitOptRef callable;
JitOptRef res;
JitOptRef c;
JitOptRef s;
args = &stack_pointer[-oparg];
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
PyObject *callable_o = sym_get_const(ctx, callable);
@ -4327,19 +4331,38 @@
ADD_OP(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, oparg + 1, (uintptr_t)cfunc);
}
res = sym_new_not_null(ctx);
CHECK_STACK_BOUNDS(-1 - oparg);
c = callable;
if (sym_is_not_null(self_or_null)) {
args--;
s = args[0];
}
else if (sym_is_null(self_or_null)) {
s = args[0];
}
else {
s = sym_new_unknown(ctx);
}
CHECK_STACK_BOUNDS(1 - oparg);
stack_pointer[-2 - oparg] = res;
stack_pointer += -1 - oparg;
stack_pointer[-1 - oparg] = c;
stack_pointer[-oparg] = s;
stack_pointer += 1 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}
case _CALL_METHOD_DESCRIPTOR_NOARGS_INLINE: {
JitOptRef res;
JitOptRef c;
JitOptRef s;
res = sym_new_not_null(ctx);
CHECK_STACK_BOUNDS(-oparg);
c = sym_new_not_null(ctx);
s = sym_new_not_null(ctx);
CHECK_STACK_BOUNDS(2 - oparg);
stack_pointer[-1 - oparg] = res;
stack_pointer += -oparg;
stack_pointer[-oparg] = c;
stack_pointer[1 - oparg] = s;
stack_pointer += 2 - oparg;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}