aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-04-14 12:19:53 +0100
committerGitHub <noreply@github.com>2025-04-14 12:19:53 +0100
commit844596c09fc812a58ac1b381b51bee12d327da31 (patch)
tree2396230f46529229bba300f1adecf92c4a88deb4 /Python
parentbe763e550e28e740b7b22c3267d14565d126f28d (diff)
downloadcpython-844596c09fc812a58ac1b381b51bee12d327da31.tar.gz
cpython-844596c09fc812a58ac1b381b51bee12d327da31.zip
GH-131498: Cases generator: Allow input and 'peek' variables to be modified (GH-132506)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c27
-rw-r--r--Python/executor_cases.c.h39
-rw-r--r--Python/generated_cases.c.h68
-rw-r--r--Python/optimizer_cases.c.h6
4 files changed, 48 insertions, 92 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index e9dced654d1..95786c91371 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -4725,15 +4725,9 @@ dummy_func(
_CALL_KW_NON_PY +
_CHECK_PERIODIC;
- op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs_in -- func, unused, tuple, kwargs_out)) {
+ op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs -- func, unused, callargs, kwargs)) {
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
- if (PyTuple_CheckExact(callargs_o)) {
- tuple = callargs;
- kwargs_out = kwargs_in;
- DEAD(kwargs_in);
- DEAD(callargs);
- }
- else {
+ if (!PyTuple_CheckExact(callargs_o)) {
int err = _Py_Check_ArgsIterable(tstate, PyStackRef_AsPyObjectBorrow(func), callargs_o);
if (err < 0) {
ERROR_NO_POP();
@@ -4742,10 +4736,9 @@ dummy_func(
if (tuple_o == NULL) {
ERROR_NO_POP();
}
- kwargs_out = kwargs_in;
- DEAD(kwargs_in);
- PyStackRef_CLOSE(callargs);
- tuple = PyStackRef_FromPyObjectSteal(tuple_o);
+ _PyStackRef temp = callargs;
+ callargs = PyStackRef_FromPyObjectSteal(tuple_o);
+ PyStackRef_CLOSE(temp);
}
}
@@ -4965,11 +4958,11 @@ dummy_func(
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;
- pure inst(SWAP, (bottom[1], unused[oparg-2], top[1] --
- bottom[1], unused[oparg-2], top[1])) {
- _PyStackRef temp = bottom[0];
- bottom[0] = top[0];
- top[0] = temp;
+ pure inst(SWAP, (bottom, unused[oparg-2], top --
+ bottom, unused[oparg-2], top)) {
+ _PyStackRef temp = bottom;
+ bottom = top;
+ top = temp;
assert(oparg >= 2);
}
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 938a80fe665..9bfb13e2d97 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -6350,20 +6350,12 @@
}
case _MAKE_CALLARGS_A_TUPLE: {
- _PyStackRef kwargs_in;
_PyStackRef callargs;
_PyStackRef func;
- _PyStackRef tuple;
- _PyStackRef kwargs_out;
- kwargs_in = stack_pointer[-1];
callargs = stack_pointer[-2];
func = stack_pointer[-4];
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
- if (PyTuple_CheckExact(callargs_o)) {
- tuple = callargs;
- kwargs_out = kwargs_in;
- }
- else {
+ if (!PyTuple_CheckExact(callargs_o)) {
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _Py_Check_ArgsIterable(tstate, PyStackRef_AsPyObjectBorrow(func), callargs_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -6376,17 +6368,14 @@
if (tuple_o == NULL) {
JUMP_TO_ERROR();
}
- kwargs_out = kwargs_in;
- stack_pointer += -2;
- assert(WITHIN_STACK_BOUNDS());
+ _PyStackRef temp = callargs;
+ callargs = PyStackRef_FromPyObjectSteal(tuple_o);
+ stack_pointer[-2] = callargs;
_PyFrame_SetStackPointer(frame, stack_pointer);
- PyStackRef_CLOSE(callargs);
+ PyStackRef_CLOSE(temp);
stack_pointer = _PyFrame_GetStackPointer(frame);
- tuple = PyStackRef_FromPyObjectSteal(tuple_o);
- stack_pointer += 2;
}
- stack_pointer[-2] = tuple;
- stack_pointer[-1] = kwargs_out;
+ stack_pointer[-2] = callargs;
break;
}
@@ -6631,15 +6620,17 @@
}
case _SWAP: {
- _PyStackRef *top;
- _PyStackRef *bottom;
+ _PyStackRef top;
+ _PyStackRef bottom;
oparg = CURRENT_OPARG();
- top = &stack_pointer[-1];
- bottom = &stack_pointer[-2 - (oparg-2)];
- _PyStackRef temp = bottom[0];
- bottom[0] = top[0];
- top[0] = temp;
+ top = stack_pointer[-1];
+ bottom = stack_pointer[-2 - (oparg-2)];
+ _PyStackRef temp = bottom;
+ bottom = top;
+ top = temp;
assert(oparg >= 2);
+ stack_pointer[-2 - (oparg-2)] = bottom;
+ stack_pointer[-1] = top;
break;
}
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 97bffce8d82..6fe647d6197 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -2330,9 +2330,6 @@
opcode = CALL_FUNCTION_EX;
_PyStackRef func;
_PyStackRef callargs;
- _PyStackRef kwargs_in;
- _PyStackRef tuple;
- _PyStackRef kwargs_out;
_PyStackRef func_st;
_PyStackRef null;
_PyStackRef callargs_st;
@@ -2340,15 +2337,10 @@
_PyStackRef result;
// _MAKE_CALLARGS_A_TUPLE
{
- kwargs_in = stack_pointer[-1];
callargs = stack_pointer[-2];
func = stack_pointer[-4];
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
- if (PyTuple_CheckExact(callargs_o)) {
- tuple = callargs;
- kwargs_out = kwargs_in;
- }
- else {
+ if (!PyTuple_CheckExact(callargs_o)) {
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _Py_Check_ArgsIterable(tstate, PyStackRef_AsPyObjectBorrow(func), callargs_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -2361,20 +2353,18 @@
if (tuple_o == NULL) {
JUMP_TO_LABEL(error);
}
- kwargs_out = kwargs_in;
- stack_pointer += -2;
- assert(WITHIN_STACK_BOUNDS());
+ _PyStackRef temp = callargs;
+ callargs = PyStackRef_FromPyObjectSteal(tuple_o);
+ stack_pointer[-2] = callargs;
_PyFrame_SetStackPointer(frame, stack_pointer);
- PyStackRef_CLOSE(callargs);
+ PyStackRef_CLOSE(temp);
stack_pointer = _PyFrame_GetStackPointer(frame);
- tuple = PyStackRef_FromPyObjectSteal(tuple_o);
- stack_pointer += 2;
}
}
// _DO_CALL_FUNCTION_EX
{
- kwargs_st = kwargs_out;
- callargs_st = tuple;
+ kwargs_st = stack_pointer[-1];
+ callargs_st = callargs;
null = stack_pointer[-3];
func_st = func;
(void)null;
@@ -2390,7 +2380,6 @@
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : &_PyInstrumentation_MISSING;
stack_pointer[-2] = callargs_st;
- stack_pointer[-1] = kwargs_st;
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _Py_call_instrumentation_2args(
tstate, PY_MONITORING_EVENT_CALL,
@@ -2456,7 +2445,6 @@
PyObject *kwargs = PyStackRef_AsPyObjectBorrow(kwargs_st);
assert(kwargs == NULL || PyDict_CheckExact(kwargs));
stack_pointer[-2] = callargs_st;
- stack_pointer[-1] = kwargs_st;
_PyFrame_SetStackPointer(frame, stack_pointer);
result_o = PyObject_Call(func, callargs, kwargs);
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -6289,9 +6277,6 @@
opcode = INSTRUMENTED_CALL_FUNCTION_EX;
_PyStackRef func;
_PyStackRef callargs;
- _PyStackRef kwargs_in;
- _PyStackRef tuple;
- _PyStackRef kwargs_out;
_PyStackRef func_st;
_PyStackRef null;
_PyStackRef callargs_st;
@@ -6299,15 +6284,10 @@
_PyStackRef result;
// _MAKE_CALLARGS_A_TUPLE
{
- kwargs_in = stack_pointer[-1];
callargs = stack_pointer[-2];
func = stack_pointer[-4];
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
- if (PyTuple_CheckExact(callargs_o)) {
- tuple = callargs;
- kwargs_out = kwargs_in;
- }
- else {
+ if (!PyTuple_CheckExact(callargs_o)) {
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _Py_Check_ArgsIterable(tstate, PyStackRef_AsPyObjectBorrow(func), callargs_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -6320,20 +6300,18 @@
if (tuple_o == NULL) {
JUMP_TO_LABEL(error);
}
- kwargs_out = kwargs_in;
- stack_pointer += -2;
- assert(WITHIN_STACK_BOUNDS());
+ _PyStackRef temp = callargs;
+ callargs = PyStackRef_FromPyObjectSteal(tuple_o);
+ stack_pointer[-2] = callargs;
_PyFrame_SetStackPointer(frame, stack_pointer);
- PyStackRef_CLOSE(callargs);
+ PyStackRef_CLOSE(temp);
stack_pointer = _PyFrame_GetStackPointer(frame);
- tuple = PyStackRef_FromPyObjectSteal(tuple_o);
- stack_pointer += 2;
}
}
// _DO_CALL_FUNCTION_EX
{
- kwargs_st = kwargs_out;
- callargs_st = tuple;
+ kwargs_st = stack_pointer[-1];
+ callargs_st = callargs;
null = stack_pointer[-3];
func_st = func;
(void)null;
@@ -6349,7 +6327,6 @@
PyObject *arg = PyTuple_GET_SIZE(callargs) > 0 ?
PyTuple_GET_ITEM(callargs, 0) : &_PyInstrumentation_MISSING;
stack_pointer[-2] = callargs_st;
- stack_pointer[-1] = kwargs_st;
_PyFrame_SetStackPointer(frame, stack_pointer);
int err = _Py_call_instrumentation_2args(
tstate, PY_MONITORING_EVENT_CALL,
@@ -6415,7 +6392,6 @@
PyObject *kwargs = PyStackRef_AsPyObjectBorrow(kwargs_st);
assert(kwargs == NULL || PyDict_CheckExact(kwargs));
stack_pointer[-2] = callargs_st;
- stack_pointer[-1] = kwargs_st;
_PyFrame_SetStackPointer(frame, stack_pointer);
result_o = PyObject_Call(func, callargs, kwargs);
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -11358,14 +11334,16 @@
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(SWAP);
- _PyStackRef *bottom;
- _PyStackRef *top;
- top = &stack_pointer[-1];
- bottom = &stack_pointer[-2 - (oparg-2)];
- _PyStackRef temp = bottom[0];
- bottom[0] = top[0];
- top[0] = temp;
+ _PyStackRef bottom;
+ _PyStackRef top;
+ top = stack_pointer[-1];
+ bottom = stack_pointer[-2 - (oparg-2)];
+ _PyStackRef temp = bottom;
+ bottom = top;
+ top = temp;
assert(oparg >= 2);
+ stack_pointer[-2 - (oparg-2)] = bottom;
+ stack_pointer[-1] = top;
DISPATCH();
}
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 0c617137a88..6a20cef9062 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -2047,12 +2047,6 @@
}
case _MAKE_CALLARGS_A_TUPLE: {
- JitOptSymbol *tuple;
- JitOptSymbol *kwargs_out;
- tuple = sym_new_not_null(ctx);
- kwargs_out = sym_new_not_null(ctx);
- stack_pointer[-2] = tuple;
- stack_pointer[-1] = kwargs_out;
break;
}