Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44878: Remove loop from interpreter. All dispatching is done by gotos. #27727

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove the loop from the bytecode interpreter. All instructions end with a
DISPATCH macro, so the loop is now redundant.
31 changes: 17 additions & 14 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ eval_frame_handle_pending(PyThreadState *tstate)

#define CHECK_EVAL_BREAKER() \
if (_Py_atomic_load_relaxed(eval_breaker)) { \
continue; \
goto check_eval_breaker; \
}


Expand Down Expand Up @@ -1584,7 +1584,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
assert(!_PyErr_Occurred(tstate));
#endif

for (;;) {
check_eval_breaker:
{
assert(STACK_LEVEL() >= 0); /* else underflow */
assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */
assert(!_PyErr_Occurred(tstate));
Expand Down Expand Up @@ -4292,6 +4293,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
CHECK_EVAL_BREAKER();
DISPATCH();
}

TARGET(CALL_METHOD_KW): {
/* Designed to work in tandem with LOAD_METHOD. Same as CALL_METHOD
but pops TOS to get a tuple of keyword names. */
Expand All @@ -4315,6 +4317,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
CHECK_EVAL_BREAKER();
DISPATCH();
}

TARGET(CALL_FUNCTION): {
PREDICTED(CALL_FUNCTION);
PyObject **sp, *res;
Expand Down Expand Up @@ -4621,7 +4624,17 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR)
int level, handler, lasti;
if (get_exception_handler(co, offset, &level, &handler, &lasti) == 0) {
// No handlers, so exit.
break;
assert(retval == NULL);
assert(_PyErr_Occurred(tstate));

/* Pop remaining stack entries. */
while (!EMPTY()) {
PyObject *o = POP();
Py_XDECREF(o);
}
frame->stackdepth = 0;
frame->f_state = FRAME_RAISED;
goto exiting;
}

assert(STACK_LEVEL() >= level);
Expand Down Expand Up @@ -4661,18 +4674,8 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR)
NEXTOPARG();
PRE_DISPATCH_GOTO();
DISPATCH_GOTO();
} /* main loop */

assert(retval == NULL);
assert(_PyErr_Occurred(tstate));

/* Pop remaining stack entries. */
while (!EMPTY()) {
PyObject *o = POP();
Py_XDECREF(o);
}
frame->stackdepth = 0;
frame->f_state = FRAME_RAISED;

exiting:
if (cframe.use_tracing) {
if (tstate->c_tracefunc) {
Expand Down