mirror of https://github.com/python/cpython
GH-98831: Remove all remaining DISPATCH() calls from bytecodes.c (#99271)
Also mark those opcodes that have no stack effect as such. Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
00ee6d506e
commit
694cdb24a6
|
@ -68,7 +68,6 @@ do { \
|
|||
#define JUMPBY(offset) ((void)0)
|
||||
#define GO_TO_INSTRUCTION(instname) ((void)0)
|
||||
#define DISPATCH_SAME_OPARG() ((void)0)
|
||||
#define DISPATCH() ((void)0)
|
||||
|
||||
#define inst(name, ...) case name:
|
||||
#define super(name) static int SUPER_##name
|
||||
|
@ -104,10 +103,6 @@ dummy_func(
|
|||
{
|
||||
switch (opcode) {
|
||||
|
||||
/* BEWARE!
|
||||
It is essential that any operation that fails must goto error
|
||||
and that all operation that succeed call DISPATCH() ! */
|
||||
|
||||
// BEGIN BYTECODES //
|
||||
inst(NOP, (--)) {
|
||||
}
|
||||
|
@ -152,16 +147,14 @@ dummy_func(
|
|||
super(LOAD_FAST__LOAD_CONST) = LOAD_FAST + LOAD_CONST;
|
||||
super(STORE_FAST__LOAD_FAST) = STORE_FAST + LOAD_FAST;
|
||||
super(STORE_FAST__STORE_FAST) = STORE_FAST + STORE_FAST;
|
||||
super (LOAD_CONST__LOAD_FAST) = LOAD_CONST + LOAD_FAST;
|
||||
super(LOAD_CONST__LOAD_FAST) = LOAD_CONST + LOAD_FAST;
|
||||
|
||||
inst(POP_TOP, (value --)) {
|
||||
Py_DECREF(value);
|
||||
}
|
||||
|
||||
// stack effect: ( -- __0)
|
||||
inst(PUSH_NULL) {
|
||||
/* Use BASIC_PUSH as NULL is not a valid object pointer */
|
||||
BASIC_PUSH(NULL);
|
||||
inst(PUSH_NULL, (-- res)) {
|
||||
res = NULL;
|
||||
}
|
||||
|
||||
inst(END_FOR, (value1, value2 --)) {
|
||||
|
@ -816,12 +809,13 @@ dummy_func(
|
|||
Py_DECREF(receiver);
|
||||
SET_TOP(retval);
|
||||
JUMPBY(oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
assert(gen_status == PYGEN_NEXT);
|
||||
assert(retval != NULL);
|
||||
PUSH(retval);
|
||||
}
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(ASYNC_GEN_WRAP) {
|
||||
|
@ -913,7 +907,6 @@ dummy_func(
|
|||
if (PyErr_GivenExceptionMatches(val, PyExc_StopAsyncIteration)) {
|
||||
Py_DECREF(val);
|
||||
Py_DECREF(POP());
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
PyObject *exc = Py_NewRef(PyExceptionInstance_Class(val));
|
||||
|
@ -935,13 +928,14 @@ dummy_func(
|
|||
Py_DECREF(POP()); // The last sent value.
|
||||
Py_DECREF(POP()); // The delegated sub-iterator.
|
||||
PUSH(value);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
PyObject *exc_type = Py_NewRef(Py_TYPE(exc_value));
|
||||
PyObject *exc_traceback = PyException_GetTraceback(exc_value);
|
||||
_PyErr_Restore(tstate, exc_type, Py_NewRef(exc_value), exc_traceback);
|
||||
goto exception_unwind;
|
||||
}
|
||||
}
|
||||
|
||||
inst(STOPITERATION_ERROR) {
|
||||
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
|
||||
|
@ -982,7 +976,6 @@ dummy_func(
|
|||
PyException_SetContext(error, exc);
|
||||
Py_DECREF(message);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1040,8 +1033,7 @@ dummy_func(
|
|||
goto error;
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(DELETE_NAME) {
|
||||
inst(DELETE_NAME, (--)) {
|
||||
PyObject *name = GETITEM(names, oparg);
|
||||
PyObject *ns = LOCALS();
|
||||
int err;
|
||||
|
@ -1051,6 +1043,7 @@ dummy_func(
|
|||
goto error;
|
||||
}
|
||||
err = PyObject_DelItem(ns, name);
|
||||
// Can't use ERROR_IF here.
|
||||
if (err != 0) {
|
||||
format_exc_check_arg(tstate, PyExc_NameError,
|
||||
NAME_ERROR_MSG,
|
||||
|
@ -1190,11 +1183,11 @@ dummy_func(
|
|||
goto error;
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(DELETE_GLOBAL) {
|
||||
inst(DELETE_GLOBAL, (--)) {
|
||||
PyObject *name = GETITEM(names, oparg);
|
||||
int err;
|
||||
err = PyDict_DelItem(GLOBALS(), name);
|
||||
// Can't use ERROR_IF here.
|
||||
if (err != 0) {
|
||||
if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
|
||||
format_exc_check_arg(tstate, PyExc_NameError,
|
||||
|
@ -1374,18 +1367,13 @@ dummy_func(
|
|||
SET_TOP(Py_NewRef(res));
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(DELETE_FAST) {
|
||||
inst(DELETE_FAST, (--)) {
|
||||
PyObject *v = GETLOCAL(oparg);
|
||||
if (v != NULL) {
|
||||
ERROR_IF(v == NULL, unbound_local_error);
|
||||
SETLOCAL(oparg, NULL);
|
||||
DISPATCH();
|
||||
}
|
||||
goto unbound_local_error;
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(MAKE_CELL) {
|
||||
inst(MAKE_CELL, (--)) {
|
||||
// "initial" is probably NULL but not if it's an arg (or set
|
||||
// via PyFrame_LocalsToFast() before MAKE_CELL has run).
|
||||
PyObject *initial = GETLOCAL(oparg);
|
||||
|
@ -1396,18 +1384,18 @@ dummy_func(
|
|||
SETLOCAL(oparg, cell);
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(DELETE_DEREF) {
|
||||
inst(DELETE_DEREF, (--)) {
|
||||
PyObject *cell = GETLOCAL(oparg);
|
||||
PyObject *oldobj = PyCell_GET(cell);
|
||||
if (oldobj != NULL) {
|
||||
PyCell_SET(cell, NULL);
|
||||
Py_DECREF(oldobj);
|
||||
DISPATCH();
|
||||
}
|
||||
// Can't use ERROR_IF here.
|
||||
// Fortunately we don't need its superpower.
|
||||
if (oldobj == NULL) {
|
||||
format_exc_unbound(tstate, frame->f_code, oparg);
|
||||
goto error;
|
||||
}
|
||||
PyCell_SET(cell, NULL);
|
||||
Py_DECREF(oldobj);
|
||||
}
|
||||
|
||||
// stack effect: ( -- __0)
|
||||
inst(LOAD_CLASSDEREF) {
|
||||
|
@ -1769,15 +1757,15 @@ dummy_func(
|
|||
Py_DECREF(owner);
|
||||
PUSH(meth);
|
||||
}
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
PyObject *res = PyObject_GetAttr(owner, name);
|
||||
if (res == NULL) {
|
||||
goto error;
|
||||
}
|
||||
Py_DECREF(owner);
|
||||
SET_TOP(res);
|
||||
}
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||
}
|
||||
|
||||
|
@ -2435,22 +2423,24 @@ dummy_func(
|
|||
if (Py_IsTrue(cond)) {
|
||||
STACK_SHRINK(1);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsFalse(cond)) {
|
||||
else if (Py_IsFalse(cond)) {
|
||||
JUMPBY(oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
err = PyObject_IsTrue(cond);
|
||||
if (err > 0) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(cond);
|
||||
}
|
||||
else if (err == 0)
|
||||
else if (err == 0) {
|
||||
JUMPBY(oparg);
|
||||
else
|
||||
}
|
||||
else {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// error: JUMP_IF_TRUE_OR_POP stack effect depends on jump flag
|
||||
inst(JUMP_IF_TRUE_OR_POP) {
|
||||
|
@ -2459,12 +2449,11 @@ dummy_func(
|
|||
if (Py_IsFalse(cond)) {
|
||||
STACK_SHRINK(1);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsTrue(cond)) {
|
||||
else if (Py_IsTrue(cond)) {
|
||||
JUMPBY(oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
err = PyObject_IsTrue(cond);
|
||||
if (err > 0) {
|
||||
JUMPBY(oparg);
|
||||
|
@ -2473,9 +2462,11 @@ dummy_func(
|
|||
STACK_SHRINK(1);
|
||||
Py_DECREF(cond);
|
||||
}
|
||||
else
|
||||
else {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stack effect: ( -- )
|
||||
inst(JUMP_BACKWARD_NO_INTERRUPT) {
|
||||
|
@ -2615,8 +2606,8 @@ dummy_func(
|
|||
if (next != NULL) {
|
||||
PUSH(next);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
if (_PyErr_Occurred(tstate)) {
|
||||
if (!_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
|
||||
goto error;
|
||||
|
@ -2633,6 +2624,7 @@ dummy_func(
|
|||
/* Skip END_FOR */
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// stack effect: ( -- __0)
|
||||
inst(FOR_ITER_LIST) {
|
||||
|
@ -2646,7 +2638,7 @@ dummy_func(
|
|||
PyObject *next = PyList_GET_ITEM(seq, it->it_index++);
|
||||
PUSH(Py_NewRef(next));
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
|
||||
DISPATCH();
|
||||
goto end_for_iter_list; // End of this instruction
|
||||
}
|
||||
it->it_seq = NULL;
|
||||
Py_DECREF(seq);
|
||||
|
@ -2654,6 +2646,7 @@ dummy_func(
|
|||
STACK_SHRINK(1);
|
||||
Py_DECREF(it);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
end_for_iter_list:
|
||||
}
|
||||
|
||||
// stack effect: ( -- __0)
|
||||
|
@ -2668,8 +2661,8 @@ dummy_func(
|
|||
STACK_SHRINK(1);
|
||||
Py_DECREF(r);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
long value = (long)(r->start +
|
||||
(unsigned long)(r->index++) * r->step);
|
||||
if (_PyLong_AssignValue(&GETLOCAL(_Py_OPARG(next)), value) < 0) {
|
||||
|
@ -2678,6 +2671,7 @@ dummy_func(
|
|||
// The STORE_FAST is already done.
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + 1);
|
||||
}
|
||||
}
|
||||
|
||||
inst(FOR_ITER_GEN) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
|
|
|
@ -70,8 +70,10 @@
|
|||
}
|
||||
|
||||
TARGET(PUSH_NULL) {
|
||||
/* Use BASIC_PUSH as NULL is not a valid object pointer */
|
||||
BASIC_PUSH(NULL);
|
||||
PyObject *res;
|
||||
res = NULL;
|
||||
STACK_GROW(1);
|
||||
POKE(1, res);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -809,11 +811,12 @@
|
|||
Py_DECREF(receiver);
|
||||
SET_TOP(retval);
|
||||
JUMPBY(oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
assert(gen_status == PYGEN_NEXT);
|
||||
assert(retval != NULL);
|
||||
PUSH(retval);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -904,7 +907,6 @@
|
|||
if (PyErr_GivenExceptionMatches(val, PyExc_StopAsyncIteration)) {
|
||||
Py_DECREF(val);
|
||||
Py_DECREF(POP());
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
PyObject *exc = Py_NewRef(PyExceptionInstance_Class(val));
|
||||
|
@ -926,13 +928,15 @@
|
|||
Py_DECREF(POP()); // The last sent value.
|
||||
Py_DECREF(POP()); // The delegated sub-iterator.
|
||||
PUSH(value);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
PyObject *exc_type = Py_NewRef(Py_TYPE(exc_value));
|
||||
PyObject *exc_traceback = PyException_GetTraceback(exc_value);
|
||||
_PyErr_Restore(tstate, exc_type, Py_NewRef(exc_value), exc_traceback);
|
||||
goto exception_unwind;
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(STOPITERATION_ERROR) {
|
||||
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
|
||||
|
@ -1040,6 +1044,7 @@
|
|||
goto error;
|
||||
}
|
||||
err = PyObject_DelItem(ns, name);
|
||||
// Can't use ERROR_IF here.
|
||||
if (err != 0) {
|
||||
format_exc_check_arg(tstate, PyExc_NameError,
|
||||
NAME_ERROR_MSG,
|
||||
|
@ -1186,6 +1191,7 @@
|
|||
PyObject *name = GETITEM(names, oparg);
|
||||
int err;
|
||||
err = PyDict_DelItem(GLOBALS(), name);
|
||||
// Can't use ERROR_IF here.
|
||||
if (err != 0) {
|
||||
if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
|
||||
format_exc_check_arg(tstate, PyExc_NameError,
|
||||
|
@ -1369,12 +1375,10 @@
|
|||
|
||||
TARGET(DELETE_FAST) {
|
||||
PyObject *v = GETLOCAL(oparg);
|
||||
if (v != NULL) {
|
||||
if (v == NULL) goto unbound_local_error;
|
||||
SETLOCAL(oparg, NULL);
|
||||
DISPATCH();
|
||||
}
|
||||
goto unbound_local_error;
|
||||
}
|
||||
|
||||
TARGET(MAKE_CELL) {
|
||||
// "initial" is probably NULL but not if it's an arg (or set
|
||||
|
@ -1391,14 +1395,16 @@
|
|||
TARGET(DELETE_DEREF) {
|
||||
PyObject *cell = GETLOCAL(oparg);
|
||||
PyObject *oldobj = PyCell_GET(cell);
|
||||
if (oldobj != NULL) {
|
||||
// Can't use ERROR_IF here.
|
||||
// Fortunately we don't need its superpower.
|
||||
if (oldobj == NULL) {
|
||||
format_exc_unbound(tstate, frame->f_code, oparg);
|
||||
goto error;
|
||||
}
|
||||
PyCell_SET(cell, NULL);
|
||||
Py_DECREF(oldobj);
|
||||
DISPATCH();
|
||||
}
|
||||
format_exc_unbound(tstate, frame->f_code, oparg);
|
||||
goto error;
|
||||
}
|
||||
|
||||
TARGET(LOAD_CLASSDEREF) {
|
||||
PyObject *name, *value, *locals = LOCALS();
|
||||
|
@ -1760,15 +1766,15 @@
|
|||
Py_DECREF(owner);
|
||||
PUSH(meth);
|
||||
}
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
PyObject *res = PyObject_GetAttr(owner, name);
|
||||
if (res == NULL) {
|
||||
goto error;
|
||||
}
|
||||
Py_DECREF(owner);
|
||||
SET_TOP(res);
|
||||
}
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||
DISPATCH();
|
||||
}
|
||||
|
@ -2427,21 +2433,23 @@
|
|||
if (Py_IsTrue(cond)) {
|
||||
STACK_SHRINK(1);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsFalse(cond)) {
|
||||
else if (Py_IsFalse(cond)) {
|
||||
JUMPBY(oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
err = PyObject_IsTrue(cond);
|
||||
if (err > 0) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(cond);
|
||||
}
|
||||
else if (err == 0)
|
||||
else if (err == 0) {
|
||||
JUMPBY(oparg);
|
||||
else
|
||||
}
|
||||
else {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -2451,12 +2459,11 @@
|
|||
if (Py_IsFalse(cond)) {
|
||||
STACK_SHRINK(1);
|
||||
_Py_DECREF_NO_DEALLOC(cond);
|
||||
DISPATCH();
|
||||
}
|
||||
if (Py_IsTrue(cond)) {
|
||||
else if (Py_IsTrue(cond)) {
|
||||
JUMPBY(oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
err = PyObject_IsTrue(cond);
|
||||
if (err > 0) {
|
||||
JUMPBY(oparg);
|
||||
|
@ -2465,8 +2472,10 @@
|
|||
STACK_SHRINK(1);
|
||||
Py_DECREF(cond);
|
||||
}
|
||||
else
|
||||
else {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -2608,8 +2617,8 @@
|
|||
if (next != NULL) {
|
||||
PUSH(next);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
if (_PyErr_Occurred(tstate)) {
|
||||
if (!_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
|
||||
goto error;
|
||||
|
@ -2625,6 +2634,7 @@
|
|||
Py_DECREF(iter);
|
||||
/* Skip END_FOR */
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -2639,7 +2649,7 @@
|
|||
PyObject *next = PyList_GET_ITEM(seq, it->it_index++);
|
||||
PUSH(Py_NewRef(next));
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
|
||||
DISPATCH();
|
||||
goto end_for_iter_list; // End of this instruction
|
||||
}
|
||||
it->it_seq = NULL;
|
||||
Py_DECREF(seq);
|
||||
|
@ -2647,6 +2657,7 @@
|
|||
STACK_SHRINK(1);
|
||||
Py_DECREF(it);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
end_for_iter_list:
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -2661,8 +2672,8 @@
|
|||
STACK_SHRINK(1);
|
||||
Py_DECREF(r);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
DISPATCH();
|
||||
}
|
||||
else {
|
||||
long value = (long)(r->start +
|
||||
(unsigned long)(r->index++) * r->step);
|
||||
if (_PyLong_AssignValue(&GETLOCAL(_Py_OPARG(next)), value) < 0) {
|
||||
|
@ -2670,6 +2681,7 @@
|
|||
}
|
||||
// The STORE_FAST is already done.
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + 1);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue