From bd00f828b0091b71f23de067426b9c3df0b95dba Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Wed, 5 Jan 2022 18:01:20 +0000
Subject: [PATCH 01/34] Add PRECALL_FUNCTION opcode.

---
 Include/opcode.h           |  1 +
 Lib/opcode.py              |  1 +
 Programs/test_frozenmain.h | 61 +++++++++++++++++++-------------------
 Python/ceval.c             | 31 +++++++++----------
 Python/compile.c           |  8 +++++
 Python/opcode_targets.h    |  2 +-
 6 files changed, 56 insertions(+), 48 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index 1af54943e1ca58..65377c849ccac5 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -108,6 +108,7 @@ extern "C" {
 #define SET_UPDATE                      163
 #define DICT_MERGE                      164
 #define DICT_UPDATE                     165
+#define PRECALL_FUNCTION                167
 #define PRECALL_METHOD                  168
 #define CALL_NO_KW                      169
 #define CALL_KW                         170
diff --git a/Lib/opcode.py b/Lib/opcode.py
index f99e20ad0a6704..5bde10abc96c72 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -191,6 +191,7 @@ def jabs_op(name, op):
 def_op('DICT_MERGE', 164)
 def_op('DICT_UPDATE', 165)
 
+def_op('PRECALL_FUNCTION', 167)
 def_op('PRECALL_METHOD', 168)
 def_op('CALL_NO_KW', 169)
 def_op('CALL_KW', 170)
diff --git a/Programs/test_frozenmain.h b/Programs/test_frozenmain.h
index 45ca31e1b5e95e..2738e37c0d91e4 100644
--- a/Programs/test_frozenmain.h
+++ b/Programs/test_frozenmain.h
@@ -1,35 +1,36 @@
 // Auto-generated by Programs/freeze_test_frozenmain.py
 unsigned char M_test_frozenmain[] = {
     227,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,
-    0,0,0,0,0,115,86,0,0,0,100,0,100,1,108,0,
-    90,0,100,0,100,1,108,1,90,1,101,2,100,2,169,1,
-    1,0,101,2,100,3,101,0,106,3,169,2,1,0,101,1,
-    106,4,169,0,100,4,25,0,90,5,100,5,68,0,93,14,
-    90,6,101,2,100,6,101,6,155,0,100,7,101,5,101,6,
-    25,0,155,0,157,4,169,1,1,0,113,26,100,1,83,0,
-    41,8,233,0,0,0,0,78,122,18,70,114,111,122,101,110,
-    32,72,101,108,108,111,32,87,111,114,108,100,122,8,115,121,
-    115,46,97,114,103,118,218,6,99,111,110,102,105,103,41,5,
-    90,12,112,114,111,103,114,97,109,95,110,97,109,101,218,10,
-    101,120,101,99,117,116,97,98,108,101,90,15,117,115,101,95,
-    101,110,118,105,114,111,110,109,101,110,116,90,17,99,111,110,
-    102,105,103,117,114,101,95,99,95,115,116,100,105,111,90,14,
-    98,117,102,102,101,114,101,100,95,115,116,100,105,111,122,7,
-    99,111,110,102,105,103,32,122,2,58,32,41,7,218,3,115,
-    121,115,90,17,95,116,101,115,116,105,110,116,101,114,110,97,
-    108,99,97,112,105,218,5,112,114,105,110,116,218,4,97,114,
-    103,118,90,11,103,101,116,95,99,111,110,102,105,103,115,114,
-    2,0,0,0,218,3,107,101,121,169,0,243,0,0,0,0,
-    250,18,116,101,115,116,95,102,114,111,122,101,110,109,97,105,
-    110,46,112,121,218,8,60,109,111,100,117,108,101,62,114,11,
-    0,0,0,1,0,0,0,115,16,0,0,0,8,3,8,1,
-    8,2,12,1,12,1,8,1,26,7,4,249,115,18,0,0,
-    0,8,3,8,1,8,2,12,1,12,1,2,7,4,1,2,
-    249,30,7,115,86,0,0,0,1,11,1,11,1,11,1,11,
-    1,25,1,25,1,25,1,25,1,6,7,27,1,28,1,28,
-    1,6,7,17,19,22,19,27,1,28,1,28,10,27,10,39,
-    10,41,42,50,10,51,1,7,12,2,1,42,1,42,5,8,
-    5,10,11,41,21,24,11,41,11,41,28,34,35,38,28,39,
-    11,41,11,41,5,42,5,42,5,42,1,42,1,42,114,9,
+    0,0,0,0,0,115,94,0,0,0,100,0,100,1,108,0,
+    90,0,100,0,100,1,108,1,90,1,101,2,100,2,167,1,
+    169,1,1,0,101,2,100,3,101,0,106,3,167,2,169,2,
+    1,0,101,1,106,4,167,0,169,0,100,4,25,0,90,5,
+    100,5,68,0,93,15,90,6,101,2,100,6,101,6,155,0,
+    100,7,101,5,101,6,25,0,155,0,157,4,167,1,169,1,
+    1,0,113,29,100,1,83,0,41,8,233,0,0,0,0,78,
+    122,18,70,114,111,122,101,110,32,72,101,108,108,111,32,87,
+    111,114,108,100,122,8,115,121,115,46,97,114,103,118,218,6,
+    99,111,110,102,105,103,41,5,90,12,112,114,111,103,114,97,
+    109,95,110,97,109,101,218,10,101,120,101,99,117,116,97,98,
+    108,101,90,15,117,115,101,95,101,110,118,105,114,111,110,109,
+    101,110,116,90,17,99,111,110,102,105,103,117,114,101,95,99,
+    95,115,116,100,105,111,90,14,98,117,102,102,101,114,101,100,
+    95,115,116,100,105,111,122,7,99,111,110,102,105,103,32,122,
+    2,58,32,41,7,218,3,115,121,115,90,17,95,116,101,115,
+    116,105,110,116,101,114,110,97,108,99,97,112,105,218,5,112,
+    114,105,110,116,218,4,97,114,103,118,90,11,103,101,116,95,
+    99,111,110,102,105,103,115,114,2,0,0,0,218,3,107,101,
+    121,169,0,243,0,0,0,0,250,18,116,101,115,116,95,102,
+    114,111,122,101,110,109,97,105,110,46,112,121,218,8,60,109,
+    111,100,117,108,101,62,114,11,0,0,0,1,0,0,0,115,
+    16,0,0,0,8,3,8,1,10,2,14,1,14,1,8,1,
+    28,7,4,249,115,18,0,0,0,8,3,8,1,10,2,14,
+    1,14,1,2,7,4,1,2,249,32,7,115,94,0,0,0,
+    1,11,1,11,1,11,1,11,1,25,1,25,1,25,1,25,
+    1,6,7,27,1,28,1,28,1,28,1,6,7,17,19,22,
+    19,27,1,28,1,28,1,28,10,27,10,39,10,41,10,41,
+    42,50,10,51,1,7,12,2,1,42,1,42,5,8,5,10,
+    11,41,21,24,11,41,11,41,28,34,35,38,28,39,11,41,
+    11,41,5,42,5,42,5,42,5,42,1,42,1,42,114,9,
     0,0,0,
 };
diff --git a/Python/ceval.c b/Python/ceval.c
index b4ac9ec848f773..6c28f2e0739fd7 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1662,15 +1662,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     PyObject *kwnames;
     int nargs;
     /*
-     * It is only between a PRECALL_METHOD instruction and the following instruction,
-     * that these two values can be anything other than their defaults. */
+     * It is only between a PRECALL_METHOD/FUNCTION instruction and the following instruction,
+     * that these two values have any meaning. */
     int postcall_shrink = 1;
     int extra_args = 0;
-#define RESET_STACK_ADJUST_FOR_CALLS \
-    do { \
-        postcall_shrink = 1; \
-        extra_args = 0; \
-    } while (0)
 #define STACK_ADJUST_IS_RESET \
     (postcall_shrink == 1 && extra_args == 0)
 
@@ -2588,12 +2583,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             PyObject *iter = _PyCoro_GetAwaitableIter(iterable);
 
             if (iter == NULL) {
-                int opcode_at_minus_3 = 0;
-                if ((next_instr - first_instr) > 2) {
-                    opcode_at_minus_3 = _Py_OPCODE(next_instr[-3]);
+                int opcode_at_minus_4 = 0;
+                if ((next_instr - first_instr) > 4) {
+                    opcode_at_minus_4 = _Py_OPCODE(next_instr[-4]);
                 }
                 format_awaitable_error(tstate, Py_TYPE(iterable),
-                                       opcode_at_minus_3,
+                                       opcode_at_minus_4,
                                        _Py_OPCODE(next_instr[-2]));
             }
 
@@ -4526,6 +4521,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
+        TARGET(PRECALL_FUNCTION) {
+            postcall_shrink = 1;
+            extra_args = 0;
+            DISPATCH();
+        }
+
         TARGET(PRECALL_METHOD) {
             /* Designed to work in tamdem with LOAD_METHOD. */
             /* `meth` is NULL when LOAD_METHOD thinks that it's not
@@ -4600,7 +4601,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                         stack_pointer, nargs, kwnames
                     );
                     STACK_SHRINK(postcall_shrink);
-                    RESET_STACK_ADJUST_FOR_CALLS;
                     // The frame has stolen all the arguments from the stack,
                     // so there is no need to clean them up.
                     Py_XDECREF(kwnames);
@@ -4632,7 +4632,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 Py_DECREF(stack_pointer[i]);
             }
             STACK_SHRINK(postcall_shrink);
-            RESET_STACK_ADJUST_FOR_CALLS;
             PUSH(res);
             if (res == NULL) {
                 goto error;
@@ -4680,7 +4679,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE;
             InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
             if (new_frame == NULL) {
-                RESET_STACK_ADJUST_FOR_CALLS;
                 goto error;
             }
             _PyFrame_InitializeSpecials(new_frame, func,
@@ -4699,7 +4697,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 new_frame->localsplus[i] = NULL;
             }
             STACK_SHRINK(postcall_shrink);
-            RESET_STACK_ADJUST_FOR_CALLS;
             Py_DECREF(func);
             _PyFrame_SetStackPointer(frame, stack_pointer);
             new_frame->previous = frame;
@@ -7350,7 +7347,7 @@ format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
 }
 
 static void
-format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevopcode, int prevopcode)
+format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevprevopcode, int prevopcode)
 {
     if (type->tp_as_async == NULL || type->tp_as_async->am_await == NULL) {
         if (prevopcode == BEFORE_ASYNC_WITH) {
@@ -7359,7 +7356,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop
                           "that does not implement __await__: %.100s",
                           type->tp_name);
         }
-        else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL_NO_KW && prevprevopcode == DUP_TOP)) {
+        else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL_NO_KW && prevprevprevopcode == DUP_TOP)) {
             _PyErr_Format(tstate, PyExc_TypeError,
                           "'async with' received an object from __aexit__ "
                           "that does not implement __await__: %.100s",
diff --git a/Python/compile.c b/Python/compile.c
index 3a390751fe2d22..10e36d5eebd883 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1154,6 +1154,8 @@ stack_effect(int opcode, int oparg, int jump)
         /* Functions and calls */
         case PRECALL_METHOD:
             return -1;
+        case PRECALL_FUNCTION:
+            return 0;
         case CALL_NO_KW:
             return -oparg;
         case CALL_KW:
@@ -1816,6 +1818,7 @@ compiler_call_exit_with_nones(struct compiler *c) {
     ADDOP_LOAD_CONST(c, Py_None);
     ADDOP(c, DUP_TOP);
     ADDOP(c, DUP_TOP);
+    ADDOP_I(c, PRECALL_FUNCTION, 3);
     ADDOP_I(c, CALL_NO_KW, 3);
     return 1;
 }
@@ -2197,6 +2200,7 @@ compiler_apply_decorators(struct compiler *c, asdl_expr_seq* decos)
     int old_end_col_offset = c->u->u_end_col_offset;
     for (Py_ssize_t i = asdl_seq_LEN(decos) - 1; i > -1; i--) {
         SET_LOC(c, (expr_ty)asdl_seq_GET(decos, i));
+        ADDOP_I(c, PRECALL_FUNCTION, 1);
         ADDOP_I(c, CALL_NO_KW, 1);
     }
     c->u->u_lineno = old_lineno;
@@ -3896,6 +3900,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
     ADDOP(c, LOAD_ASSERTION_ERROR);
     if (s->v.Assert.msg) {
         VISIT(c, expr, s->v.Assert.msg);
+        ADDOP_I(c, PRECALL_FUNCTION, 1);
         ADDOP_I(c, CALL_NO_KW, 1);
     }
     ADDOP_I(c, RAISE_VARARGS, 1);
@@ -4949,10 +4954,12 @@ compiler_call_helper(struct compiler *c,
         if (!compiler_call_simple_kw_helper(c, keywords, nkwelts)) {
             return 0;
         };
+        ADDOP_I(c, PRECALL_FUNCTION, n + nelts + nkwelts + 1);
         ADDOP_I(c, CALL_KW, n + nelts + nkwelts);
         return 1;
     }
     else {
+        ADDOP_I(c, PRECALL_FUNCTION, n + nelts);
         ADDOP_I(c, CALL_NO_KW, n + nelts);
         return 1;
     }
@@ -5350,6 +5357,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
         ADDOP(c, GET_ITER);
     }
 
+    ADDOP_I(c, PRECALL_FUNCTION, 1);
     ADDOP_I(c, CALL_NO_KW, 1);
 
     if (is_async_generator && type != COMP_GENEXP) {
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index e9f1a483b970c7..da8977672d4b5f 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -166,7 +166,7 @@ static void *opcode_targets[256] = {
     &&TARGET_DICT_MERGE,
     &&TARGET_DICT_UPDATE,
     &&_unknown_opcode,
-    &&_unknown_opcode,
+    &&TARGET_PRECALL_FUNCTION,
     &&TARGET_PRECALL_METHOD,
     &&TARGET_CALL_NO_KW,
     &&TARGET_CALL_KW,

From 78e6da5286b77aa3072e4b1b0f2a303ad083e530 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 6 Jan 2022 17:23:29 +0000
Subject: [PATCH 02/34] Move all call-shape variables into a struct.

---
 Python/ceval.c | 75 +++++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 31 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 6c28f2e0739fd7..c5c9a7fef52f93 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1639,6 +1639,17 @@ pop_frame(PyThreadState *tstate, InterpreterFrame *frame)
     return prev_frame;
 }
 
+/* It is only between a PRECALL_METHOD/FUNCTION instruction and the following instruction,
+ * that these two values have any meaning.
+ */
+typedef struct {
+    PyObject *kwnames;
+    int nargs;
+    int postcall_shrink;;
+    int extra_args;
+} CallShape;
+
+
 PyObject* _Py_HOT_FUNCTION
 _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int throwflag)
 {
@@ -1657,17 +1668,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     _Py_atomic_int * const eval_breaker = &tstate->interp->ceval.eval_breaker;
 
     CFrame cframe;
+    CallShape call_shape;
+    call_shape.kwnames = NULL;
+    call_shape.postcall_shrink = 1;
+    call_shape.extra_args = 0;
 
-    /* Variables used for making calls */
-    PyObject *kwnames;
-    int nargs;
-    /*
-     * It is only between a PRECALL_METHOD/FUNCTION instruction and the following instruction,
-     * that these two values have any meaning. */
-    int postcall_shrink = 1;
-    int extra_args = 0;
 #define STACK_ADJUST_IS_RESET \
-    (postcall_shrink == 1 && extra_args == 0)
+    (call_shape.postcall_shrink == 1 && call_shape.extra_args == 0 && call_shape.kwnames == NULL)
 
     /* WARNING: Because the CFrame lives on the C stack,
      * but can be accessed from a heap allocated object (tstate)
@@ -4522,8 +4529,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(PRECALL_FUNCTION) {
-            postcall_shrink = 1;
-            extra_args = 0;
+            call_shape.postcall_shrink = 1;
+            call_shape.extra_args = 0;
+            call_shape.kwnames = NULL;
             DISPATCH();
         }
 
@@ -4555,25 +4563,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                make it accept the `self` as a first argument.
             */
             int is_method = (PEEK(oparg + 2) != NULL);
-            extra_args = is_method;
-            postcall_shrink = 2-is_method;
+            call_shape.extra_args = is_method;
+            call_shape.postcall_shrink = 2-is_method;
+            call_shape.kwnames = NULL;
             DISPATCH();
         }
 
         TARGET(CALL_KW) {
-            kwnames = POP();
-            oparg += extra_args;
-            extra_args = 0;
-            nargs = oparg - (int)PyTuple_GET_SIZE(kwnames);
+            call_shape.kwnames = POP();
+            oparg += call_shape.extra_args;
+            call_shape.extra_args = 0;
+            call_shape.nargs = oparg - (int)PyTuple_GET_SIZE(call_shape.kwnames);
             goto call_function;
         }
 
         TARGET(CALL_NO_KW) {
             PyObject *function;
             PREDICTED(CALL_NO_KW);
-            kwnames = NULL;
-            oparg += extra_args;
-            nargs = oparg;
+            call_shape.kwnames = NULL;
+            oparg += call_shape.extra_args;
+            call_shape.nargs = oparg;
         call_function:
             function = PEEK(oparg + 1);
             if (Py_TYPE(function) == &PyMethod_Type) {
@@ -4585,9 +4594,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 Py_DECREF(function);
                 function = meth;
                 oparg++;
-                nargs++;
-                assert(postcall_shrink >= 1);
-                postcall_shrink--;
+                call_shape.nargs++;
+                assert(call_shape.postcall_shrink >= 1);
+                call_shape.postcall_shrink--;
             }
             // Check if the call can be inlined or not
             if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
@@ -4598,12 +4607,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                     STACK_SHRINK(oparg);
                     InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
                         tstate, (PyFunctionObject *)function, locals,
-                        stack_pointer, nargs, kwnames
+                        stack_pointer, call_shape.nargs, call_shape.kwnames
                     );
-                    STACK_SHRINK(postcall_shrink);
+                    STACK_SHRINK(call_shape.postcall_shrink);
                     // The frame has stolen all the arguments from the stack,
                     // so there is no need to clean them up.
-                    Py_XDECREF(kwnames);
+                    Py_XDECREF(call_shape.kwnames);
                     Py_DECREF(function);
                     if (new_frame == NULL) {
                         goto error;
@@ -4617,21 +4626,25 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             /* Callable is not a normal Python function */
             PyObject *res;
             if (cframe.use_tracing) {
-                res = trace_call_function(tstate, function, stack_pointer-oparg, nargs, kwnames);
+                res = trace_call_function(
+                    tstate, function, stack_pointer-oparg,
+                    call_shape.nargs, call_shape.kwnames);
             }
             else {
-                res = PyObject_Vectorcall(function, stack_pointer-oparg,
-                                          nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
+                res = PyObject_Vectorcall(
+                    function, stack_pointer-oparg,
+                    call_shape.nargs | PY_VECTORCALL_ARGUMENTS_OFFSET,
+                    call_shape.kwnames);
             }
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
             Py_DECREF(function);
-            Py_XDECREF(kwnames);
+            Py_XDECREF(call_shape.kwnames);
             /* Clear the stack */
             STACK_SHRINK(oparg);
             for (int i = 0; i < oparg; i++) {
                 Py_DECREF(stack_pointer[i]);
             }
-            STACK_SHRINK(postcall_shrink);
+            STACK_SHRINK(call_shape.postcall_shrink);
             PUSH(res);
             if (res == NULL) {
                 goto error;

From 42c04605789ea540de3cb57479869acf08d3b9f1 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 7 Jan 2022 12:02:09 +0000
Subject: [PATCH 03/34] Move 'call shape' varaibles into struct.

---
 Python/ceval.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index c5c9a7fef52f93..ee2ebc929141ca 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4658,7 +4658,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             oparg = cache->adaptive.original_oparg;
             if (cache->adaptive.counter == 0) {
                 next_instr--;
-                int nargs = oparg+extra_args;
+                int nargs = oparg + call_shape.extra_args;
                 if (_Py_Specialize_CallNoKw(
                     PEEK(nargs + 1), next_instr, nargs, cache, BUILTINS()) < 0) {
                     goto error;
@@ -4668,9 +4668,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             else {
                 STAT_INC(CALL_NO_KW, deferred);
                 cache->adaptive.counter--;
-                kwnames = NULL;
-                oparg += extra_args;
-                nargs = oparg;
+                call_shape.kwnames = NULL;
+                oparg += call_shape.extra_args;
+                call_shape.nargs = oparg;
                 goto call_function;
             }
         }
@@ -4678,7 +4678,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_PY_SIMPLE) {
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            int argcount = cache0->original_oparg + extra_args;
+            int argcount = cache0->original_oparg + call_shape.extra_args;
             DEOPT_IF(argcount != cache0->index, CALL_NO_KW);
             _PyCallCache *cache1 = &caches[-1].call;
             PyObject *callable = PEEK(argcount+1);
@@ -4709,7 +4709,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             for (int i = argcount+deflen; i < code->co_nlocalsplus; i++) {
                 new_frame->localsplus[i] = NULL;
             }
-            STACK_SHRINK(postcall_shrink);
+            STACK_SHRINK(call_shape.postcall_shrink);
             Py_DECREF(func);
             _PyFrame_SetStackPointer(frame, stack_pointer);
             new_frame->previous = frame;
@@ -4884,12 +4884,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_LIST_APPEND) {
             assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
             assert(GET_CACHE()->adaptive.original_oparg == 1);
-            DEOPT_IF(extra_args == 0, CALL_NO_KW);
+            DEOPT_IF(call_shape.extra_args == 0, CALL_NO_KW);
             PyObject *list = SECOND();
             DEOPT_IF(!PyList_CheckExact(list), CALL_NO_KW);
             STAT_INC(CALL_NO_KW, hit);
-            assert(extra_args == 1);
-            extra_args = 0;
+            assert(call_shape.extra_args == 1);
+            call_shape.extra_args = 0;
             assert(STACK_ADJUST_IS_RESET);
             PyObject *arg = TOP();
             int err = PyList_Append(list, arg);
@@ -4909,14 +4909,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
             assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
             assert(GET_CACHE()->adaptive.original_oparg == 1);
-            DEOPT_IF(extra_args == 0, CALL_NO_KW);
-            assert(extra_args == 1);
+            DEOPT_IF(call_shape.extra_args == 0, CALL_NO_KW);
+            assert(call_shape.extra_args == 1);
             PyObject *callable = THIRD();
             DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL_NO_KW);
             DEOPT_IF(((PyMethodDescrObject *)callable)->d_method->ml_flags != METH_O, CALL_NO_KW);
             STAT_INC(CALL_NO_KW, hit);
-            assert(extra_args == 1);
-            extra_args = 0;
+            assert(call_shape.extra_args == 1);
+            call_shape.extra_args = 0;
             assert(STACK_ADJUST_IS_RESET);
             PyCFunction cfunc = ((PyMethodDescrObject *)callable)->d_method->ml_meth;
             // This is slower but CPython promises to check all non-vectorcall
@@ -4944,16 +4944,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             /* Builtin METH_FASTCALL methods, without keywords */
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            DEOPT_IF(extra_args == 0, CALL_NO_KW);
-            assert(extra_args == 1);
+            DEOPT_IF(call_shape.extra_args == 0, CALL_NO_KW);
+            assert(call_shape.extra_args == 1);
             int nargs = cache0->original_oparg;
             PyObject *callable = PEEK(nargs + 2);
             DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type),  CALL_NO_KW);
             PyMethodDef *meth = ((PyMethodDescrObject *)callable)->d_method;
             DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL_NO_KW);
             STAT_INC(CALL_NO_KW, hit);
-            assert(extra_args == 1);
-            extra_args = 0;
+            assert(call_shape.extra_args == 1);
+            call_shape.extra_args = 0;
             assert(STACK_ADJUST_IS_RESET);
             _PyCFunctionFast cfunc = (_PyCFunctionFast)(void(*)(void))meth->ml_meth;
             PyObject *self = PEEK(nargs+1);

From a947bf1b4dfe59d90d0ae8312621f10cbbf62027 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 7 Jan 2022 16:59:39 +0000
Subject: [PATCH 04/34] Replace CALL_NO_KW and CALL_KW with KW_NAMES and CALL
 instructions.

---
 Include/opcode.h                     |   6 +-
 Lib/importlib/_bootstrap_external.py |   4 +-
 Lib/opcode.py                        |   7 +-
 Lib/test/test_compile.py             |   7 +-
 Lib/test/test_dis.py                 | 406 ++++++++++++++-------------
 Programs/test_frozenmain.h           |   6 +-
 Python/ceval.c                       | 172 ++++++------
 Python/compile.c                     |  57 ++--
 Python/opcode_targets.h              |   6 +-
 Python/specialize.c                  |   6 +-
 10 files changed, 351 insertions(+), 326 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index 65377c849ccac5..7507b3b1894845 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -110,8 +110,8 @@ extern "C" {
 #define DICT_UPDATE                     165
 #define PRECALL_FUNCTION                167
 #define PRECALL_METHOD                  168
-#define CALL_NO_KW                      169
-#define CALL_KW                         170
+#define CALL                            171
+#define KW_NAMES                        172
 #define BINARY_OP_ADAPTIVE                7
 #define BINARY_OP_ADD_INT                 8
 #define BINARY_OP_ADD_FLOAT              13
@@ -133,7 +133,7 @@ extern "C" {
 #define STORE_SUBSCR_ADAPTIVE            36
 #define STORE_SUBSCR_LIST_INT            37
 #define STORE_SUBSCR_DICT                38
-#define CALL_NO_KW_ADAPTIVE              39
+#define CALL_ADAPTIVE                    39
 #define CALL_NO_KW_BUILTIN_O             40
 #define CALL_NO_KW_BUILTIN_FAST          41
 #define CALL_NO_KW_LEN                   42
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 872d6d96a74b41..c1190a08dab5f0 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -379,6 +379,8 @@ def _write_atomic(path, data, mode=0o666):
 #     Python 3.11a4 3471 (bpo-46202: remove pop POP_EXCEPT_AND_RERAISE)
 #     Python 3.11a4 3472 (bpo-46009: replace GEN_START with POP_TOP)
 
+#     Python 3.11a4 3477 (New CALL opcodes)
+
 #
 # MAGIC must change whenever the bytecode emitted by the compiler may no
 # longer be understood by older implementations of the eval loop (usually
@@ -387,7 +389,7 @@ def _write_atomic(path, data, mode=0o666):
 # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
 # in PC/launcher.c must also be updated.
 
-MAGIC_NUMBER = (3472).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3477).to_bytes(2, 'little') + b'\r\n'
 _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little')  # For import.c
 
 _PYCACHE = '__pycache__'
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 5bde10abc96c72..bd42c52c87962b 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -193,8 +193,9 @@ def jabs_op(name, op):
 
 def_op('PRECALL_FUNCTION', 167)
 def_op('PRECALL_METHOD', 168)
-def_op('CALL_NO_KW', 169)
-def_op('CALL_KW', 170)
+
+def_op('CALL', 171)
+def_op('KW_NAMES', 172)
 
 del def_op, name_op, jrel_op, jabs_op
 
@@ -249,7 +250,7 @@ def jabs_op(name, op):
     "STORE_SUBSCR_ADAPTIVE",
     "STORE_SUBSCR_LIST_INT",
     "STORE_SUBSCR_DICT",
-    "CALL_NO_KW_ADAPTIVE",
+    "CALL_ADAPTIVE",
     "CALL_NO_KW_BUILTIN_O",
     "CALL_NO_KW_BUILTIN_FAST",
     "CALL_NO_KW_LEN",
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 11615b32232e84..7bde877070ca11 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -837,9 +837,8 @@ def foo(x):
                 opcodes = list(dis.get_instructions(func))
                 instructions = [opcode.opname for opcode in opcodes]
                 self.assertNotIn('LOAD_METHOD', instructions)
-                self.assertNotIn('CALL_METHOD', instructions)
                 self.assertIn('LOAD_ATTR', instructions)
-                self.assertIn('CALL_NO_KW', instructions)
+                self.assertIn('PRECALL_FUNCTION', instructions)
 
     def test_lineno_procedure_call(self):
         def call():
@@ -1095,7 +1094,7 @@ def test_multiline_expression(self):
 )
 """
         compiled_code, _ = self.check_positions_against_ast(snippet)
-        self.assertOpcodeSourcePositionIs(compiled_code, 'CALL_NO_KW',
+        self.assertOpcodeSourcePositionIs(compiled_code, 'CALL',
             line=1, end_line=3, column=0, end_column=1)
 
     def test_very_long_line_end_offset(self):
@@ -1105,7 +1104,7 @@ def test_very_long_line_end_offset(self):
         snippet = f"g('{long_string}')"
 
         compiled_code, _ = self.check_positions_against_ast(snippet)
-        self.assertOpcodeSourcePositionIs(compiled_code, 'CALL_NO_KW',
+        self.assertOpcodeSourcePositionIs(compiled_code, 'CALL',
             line=1, end_line=1, column=None, end_column=None)
 
     def test_complex_single_line_expression(self):
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 7857458e240a50..63cc6d684d5b28 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -95,11 +95,12 @@ def _f(a):
 dis_f = """\
 %3d           0 LOAD_GLOBAL              0 (print)
               2 LOAD_FAST                0 (a)
-              4 CALL_NO_KW               1
-              6 POP_TOP
+              4 PRECALL_FUNCTION         1
+              6 CALL                     0
+              8 POP_TOP
 
-%3d           8 LOAD_CONST               1 (1)
-             10 RETURN_VALUE
+%3d          10 LOAD_CONST               1 (1)
+             12 RETURN_VALUE
 """ % (_f.__code__.co_firstlineno + 1,
        _f.__code__.co_firstlineno + 2)
 
@@ -107,10 +108,11 @@ def _f(a):
 dis_f_co_code = """\
           0 LOAD_GLOBAL              0
           2 LOAD_FAST                0
-          4 CALL_NO_KW               1
-          6 POP_TOP
-          8 LOAD_CONST               1
-         10 RETURN_VALUE
+          4 PRECALL_FUNCTION         1
+          6 CALL                     0
+          8 POP_TOP
+         10 LOAD_CONST               1
+         12 RETURN_VALUE
 """
 
 
@@ -125,15 +127,16 @@ def bug708901():
 
 %3d           4 LOAD_CONST               2 (10)
 
-%3d           6 CALL_NO_KW               2
-              8 GET_ITER
-        >>   10 FOR_ITER                 2 (to 16)
-             12 STORE_FAST               0 (res)
+%3d           6 PRECALL_FUNCTION         2
+              8 CALL                     0
+             10 GET_ITER
+        >>   12 FOR_ITER                 2 (to 18)
+             14 STORE_FAST               0 (res)
 
-%3d          14 JUMP_ABSOLUTE            5 (to 10)
+%3d          16 JUMP_ABSOLUTE            6 (to 12)
 
-%3d     >>   16 LOAD_CONST               0 (None)
-             18 RETURN_VALUE
+%3d     >>   18 LOAD_CONST               0 (None)
+             20 RETURN_VALUE
 """ % (bug708901.__code__.co_firstlineno + 1,
        bug708901.__code__.co_firstlineno + 2,
        bug708901.__code__.co_firstlineno + 1,
@@ -152,13 +155,15 @@ def bug1333982(x=[]):
               4 MAKE_FUNCTION            0
               6 LOAD_FAST                0 (x)
               8 GET_ITER
-             10 CALL_NO_KW               1
+             10 PRECALL_FUNCTION         1
+             12 CALL                     0
 
-%3d          12 LOAD_CONST               3 (1)
+%3d          14 LOAD_CONST               3 (1)
 
-%3d          14 BINARY_OP                0 (+)
-             16 CALL_NO_KW               1
-             18 RAISE_VARARGS            1
+%3d          16 BINARY_OP                0 (+)
+             18 PRECALL_FUNCTION         1
+             20 CALL                     0
+             22 RAISE_VARARGS            1
 """ % (bug1333982.__code__.co_firstlineno + 1,
        __file__,
        bug1333982.__code__.co_firstlineno + 1,
@@ -260,21 +265,23 @@ def bug42562():
 
   3          14 LOAD_NAME                3 (fun)
              16 LOAD_CONST               0 (1)
-             18 CALL_NO_KW               1
-             20 LOAD_NAME                2 (__annotations__)
-             22 LOAD_CONST               2 ('y')
-             24 STORE_SUBSCR
-
-  4          26 LOAD_CONST               0 (1)
-             28 LOAD_NAME                4 (lst)
-             30 LOAD_NAME                3 (fun)
-             32 LOAD_CONST               3 (0)
-             34 CALL_NO_KW               1
-             36 STORE_SUBSCR
-             38 LOAD_NAME                1 (int)
-             40 POP_TOP
-             42 LOAD_CONST               4 (None)
-             44 RETURN_VALUE
+             18 PRECALL_FUNCTION         1
+             20 CALL                     0
+             22 LOAD_NAME                2 (__annotations__)
+             24 LOAD_CONST               2 ('y')
+             26 STORE_SUBSCR
+
+  4          28 LOAD_CONST               0 (1)
+             30 LOAD_NAME                4 (lst)
+             32 LOAD_NAME                3 (fun)
+             34 LOAD_CONST               3 (0)
+             36 PRECALL_FUNCTION         1
+             38 CALL                     0
+             40 STORE_SUBSCR
+             42 LOAD_NAME                1 (int)
+             44 POP_TOP
+             46 LOAD_CONST               4 (None)
+             48 RETURN_VALUE
 """
 
 compound_stmt_str = """\
@@ -384,20 +391,22 @@ def _tryfinallyconst(b):
 %3d           2 LOAD_FAST                0 (a)
 
 %3d           4 LOAD_FAST                1 (b)
-              6 CALL_NO_KW               0
-              8 POP_TOP
-             10 RETURN_VALUE
-        >>   12 PUSH_EXC_INFO
-             14 LOAD_FAST                1 (b)
-             16 CALL_NO_KW               0
-             18 POP_TOP
-             20 RERAISE                  0
-        >>   22 COPY                     3
-             24 POP_EXCEPT
-             26 RERAISE                  1
+              6 PRECALL_FUNCTION         0
+              8 CALL                     0
+             10 POP_TOP
+             12 RETURN_VALUE
+        >>   14 PUSH_EXC_INFO
+             16 LOAD_FAST                1 (b)
+             18 PRECALL_FUNCTION         0
+             20 CALL                     0
+             22 POP_TOP
+             24 RERAISE                  0
+        >>   26 COPY                     3
+             28 POP_EXCEPT
+             30 RERAISE                  1
 ExceptionTable:
-  2 to 2 -> 12 [0]
-  12 to 20 -> 22 [1] lasti
+  2 to 2 -> 14 [0]
+  14 to 24 -> 26 [1] lasti
 """ % (_tryfinally.__code__.co_firstlineno + 1,
        _tryfinally.__code__.co_firstlineno + 2,
        _tryfinally.__code__.co_firstlineno + 4,
@@ -409,20 +418,22 @@ def _tryfinallyconst(b):
 %3d           2 NOP
 
 %3d           4 LOAD_FAST                0 (b)
-              6 CALL_NO_KW               0
-              8 POP_TOP
-             10 LOAD_CONST               1 (1)
-             12 RETURN_VALUE
-             14 PUSH_EXC_INFO
-             16 LOAD_FAST                0 (b)
-             18 CALL_NO_KW               0
-             20 POP_TOP
-             22 RERAISE                  0
-        >>   24 COPY                     3
-             26 POP_EXCEPT
-             28 RERAISE                  1
+              6 PRECALL_FUNCTION         0
+              8 CALL                     0
+             10 POP_TOP
+             12 LOAD_CONST               1 (1)
+             14 RETURN_VALUE
+             16 PUSH_EXC_INFO
+             18 LOAD_FAST                0 (b)
+             20 PRECALL_FUNCTION         0
+             22 CALL                     0
+             24 POP_TOP
+             26 RERAISE                  0
+        >>   28 COPY                     3
+             30 POP_EXCEPT
+             32 RERAISE                  1
 ExceptionTable:
-  14 to 22 -> 24 [1] lasti
+  16 to 26 -> 28 [1] lasti
 """ % (_tryfinallyconst.__code__.co_firstlineno + 1,
        _tryfinallyconst.__code__.co_firstlineno + 2,
        _tryfinallyconst.__code__.co_firstlineno + 4,
@@ -472,8 +483,9 @@ def foo(x):
              10 MAKE_FUNCTION            8 (closure)
              12 LOAD_DEREF               1 (y)
              14 GET_ITER
-             16 CALL_NO_KW               1
-             18 RETURN_VALUE
+             16 PRECALL_FUNCTION         1
+             18 CALL                     0
+             20 RETURN_VALUE
 """ % (dis_nested_0,
        __file__,
        _h.__code__.co_firstlineno + 1,
@@ -1008,10 +1020,11 @@ def _prepare_test_cases():
   Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=28, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offset=30, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Hello world!', argrepr="'Hello world!'", offset=32, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=7, argval=7, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=38, starts_line=8, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=7, argval=7, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=40, starts_line=8, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=42, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 expected_opinfo_f = [
@@ -1032,10 +1045,11 @@ def _prepare_test_cases():
   Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=28, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=30, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=32, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=4, argval=4, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=38, starts_line=6, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=4, argval=4, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=40, starts_line=6, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=42, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 expected_opinfo_inner = [
@@ -1047,131 +1061,144 @@ def _prepare_test_cases():
   Instruction(opname='LOAD_DEREF', opcode=137, arg=5, argval='d', argrepr='d', offset=10, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', offset=12, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', offset=14, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=6, argval=6, argrepr='', offset=16, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=20, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=22, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=6, argval=6, argrepr='', offset=16, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=22, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=24, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 expected_opinfo_jumpy = [
   Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='range', argrepr='range', offset=0, starts_line=3, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=10, argrepr='10', offset=2, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=4, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='GET_ITER', opcode=68, arg=None, argval=None, argrepr='', offset=6, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='FOR_ITER', opcode=93, arg=17, argval=44, argrepr='to 44', offset=8, starts_line=None, is_jump_target=True, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=10, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=12, starts_line=4, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=14, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=16, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=20, starts_line=5, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=22, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=24, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=15, argval=30, argrepr='to 30', offset=26, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=4, argval=8, argrepr='to 8', offset=28, starts_line=6, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=30, starts_line=7, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=32, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=34, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=21, argval=42, argrepr='to 42', offset=36, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=8, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=5, argval=52, argrepr='to 52', offset=40, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=4, argval=8, argrepr='to 8', offset=42, starts_line=7, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=44, starts_line=10, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=46, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=48, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=50, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=52, starts_line=11, is_jump_target=True, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=48, argval=96, argrepr='to 96', offset=54, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=56, starts_line=12, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=58, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=60, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=62, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=64, starts_line=13, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=66, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='BINARY_OP', opcode=122, arg=23, argval=23, argrepr='-=', offset=68, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=70, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=72, starts_line=14, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=74, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=76, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=41, argval=82, argrepr='to 82', offset=78, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=26, argval=52, argrepr='to 52', offset=80, starts_line=15, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=82, starts_line=16, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=84, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=86, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=46, argval=92, argrepr='to 92', offset=88, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=6, argval=104, argrepr='to 104', offset=90, starts_line=17, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=92, starts_line=11, is_jump_target=True, positions=None),
-  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=28, argval=56, argrepr='to 56', offset=94, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=96, starts_line=19, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=98, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=100, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=102, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=104, starts_line=20, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=106, starts_line=21, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=108, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='BINARY_OP', opcode=122, arg=11, argval=11, argrepr='/', offset=110, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=4, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=6, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='GET_ITER', opcode=68, arg=None, argval=None, argrepr='', offset=8, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='FOR_ITER', opcode=93, arg=18, argval=48, argrepr='to 48', offset=10, starts_line=None, is_jump_target=True, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=12, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=14, starts_line=4, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=16, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=22, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=24, starts_line=5, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=26, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=28, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=17, argval=34, argrepr='to 34', offset=30, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=5, argval=10, argrepr='to 10', offset=32, starts_line=6, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=34, starts_line=7, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=36, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=38, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=23, argval=46, argrepr='to 46', offset=40, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=42, starts_line=8, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=6, argval=58, argrepr='to 58', offset=44, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=5, argval=10, argrepr='to 10', offset=46, starts_line=7, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=48, starts_line=10, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=50, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=52, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=54, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=56, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=58, starts_line=11, is_jump_target=True, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=52, argval=104, argrepr='to 104', offset=60, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=62, starts_line=12, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=64, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=66, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=68, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=70, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=72, starts_line=13, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=74, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='BINARY_OP', opcode=122, arg=23, argval=23, argrepr='-=', offset=76, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=78, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=80, starts_line=14, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=82, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=84, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=45, argval=90, argrepr='to 90', offset=86, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=29, argval=58, argrepr='to 58', offset=88, starts_line=15, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=90, starts_line=16, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=92, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=94, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=50, argval=100, argrepr='to 100', offset=96, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=7, argval=114, argrepr='to 114', offset=98, starts_line=17, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=100, starts_line=11, is_jump_target=True, positions=None),
+  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=31, argval=62, argrepr='to 62', offset=102, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=104, starts_line=19, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=106, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=108, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=110, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=112, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=14, argval=144, argrepr='to 144', offset=114, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=116, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=118, starts_line=22, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=68, argval=136, argrepr='to 136', offset=120, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=114, starts_line=20, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=116, starts_line=21, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=118, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='BINARY_OP', opcode=122, arg=11, argval=11, argrepr='/', offset=120, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=122, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=124, starts_line=23, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=126, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=128, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=130, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=132, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=34, argval=204, argrepr='to 204', offset=134, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=136, starts_line=22, is_jump_target=True, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=138, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=144, starts_line=25, is_jump_target=True, positions=None),
-  Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=146, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=148, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=150, starts_line=26, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=152, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=154, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=158, starts_line=25, is_jump_target=False, positions=None),
-  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=160, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=3, argval=3, argrepr='', offset=164, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=192, argrepr='to 192', offset=168, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=170, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=92, argval=184, argrepr='to 184', offset=174, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=176, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=178, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=True, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=192, starts_line=28, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=194, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=196, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=198, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=200, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=202, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=204, starts_line=23, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=206, starts_line=28, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=208, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=210, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=212, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=214, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=220, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=222, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=224, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=226, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=228, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None)]
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=15, argval=156, argrepr='to 156', offset=124, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=126, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=128, starts_line=22, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=74, argval=148, argrepr='to 148', offset=130, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=132, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=134, starts_line=23, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=136, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=138, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=144, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=37, argval=222, argrepr='to 222', offset=146, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=148, starts_line=22, is_jump_target=True, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=150, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=152, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=154, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=156, starts_line=25, is_jump_target=True, positions=None),
+  Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=160, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=162, starts_line=26, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=164, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=170, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=172, starts_line=25, is_jump_target=False, positions=None),
+  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=174, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=176, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=3, argval=3, argrepr='', offset=178, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=208, argrepr='to 208', offset=184, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=100, argval=200, argrepr='to 200', offset=190, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=192, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=194, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=196, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=198, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=200, starts_line=None, is_jump_target=True, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=202, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=206, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=208, starts_line=28, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=210, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=212, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=214, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=218, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=220, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=222, starts_line=23, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=224, starts_line=28, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=226, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=228, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=234, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=236, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=238, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=240, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=242, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=244, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=246, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=248, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=250, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=252, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=254, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=256, starts_line=None, is_jump_target=False, positions=None),
+]
 
 # One last piece of inspect fodder to check the default line number handling
 def simple(): pass
@@ -1237,6 +1264,7 @@ def test_co_positions(self):
             (1, 3, 0, 1),
             (1, 3, 0, 1),
             (1, 3, 0, 1),
+            (1, 3, 0, 1),
             (1, 3, 0, 1)
         ]
         self.assertEqual(positions, expected)
diff --git a/Programs/test_frozenmain.h b/Programs/test_frozenmain.h
index 2738e37c0d91e4..da16290d1e9505 100644
--- a/Programs/test_frozenmain.h
+++ b/Programs/test_frozenmain.h
@@ -3,10 +3,10 @@ unsigned char M_test_frozenmain[] = {
     227,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,
     0,0,0,0,0,115,94,0,0,0,100,0,100,1,108,0,
     90,0,100,0,100,1,108,1,90,1,101,2,100,2,167,1,
-    169,1,1,0,101,2,100,3,101,0,106,3,167,2,169,2,
-    1,0,101,1,106,4,167,0,169,0,100,4,25,0,90,5,
+    171,0,1,0,101,2,100,3,101,0,106,3,167,2,171,0,
+    1,0,101,1,106,4,167,0,171,0,100,4,25,0,90,5,
     100,5,68,0,93,15,90,6,101,2,100,6,101,6,155,0,
-    100,7,101,5,101,6,25,0,155,0,157,4,167,1,169,1,
+    100,7,101,5,101,6,25,0,155,0,157,4,167,1,171,0,
     1,0,113,29,100,1,83,0,41,8,233,0,0,0,0,78,
     122,18,70,114,111,122,101,110,32,72,101,108,108,111,32,87,
     111,114,108,100,122,8,115,121,115,46,97,114,103,118,218,6,
diff --git a/Python/ceval.c b/Python/ceval.c
index ee2ebc929141ca..9bda675521ebac 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1643,10 +1643,11 @@ pop_frame(PyThreadState *tstate, InterpreterFrame *frame)
  * that these two values have any meaning.
  */
 typedef struct {
+    PyObject *callable;
     PyObject *kwnames;
-    int nargs;
-    int postcall_shrink;;
-    int extra_args;
+    int positional_args;
+    int named_args;
+    int postcall_shrink;
 } CallShape;
 
 
@@ -1671,10 +1672,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     CallShape call_shape;
     call_shape.kwnames = NULL;
     call_shape.postcall_shrink = 1;
-    call_shape.extra_args = 0;
-
-#define STACK_ADJUST_IS_RESET \
-    (call_shape.postcall_shrink == 1 && call_shape.extra_args == 0 && call_shape.kwnames == NULL)
+    call_shape.positional_args = 0;
+    call_shape.named_args = 0;
 
     /* WARNING: Because the CFrame lives on the C stack,
      * but can be accessed from a heap allocated object (tstate)
@@ -4208,7 +4207,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             if (iter == NULL)
                 goto error;
             PREDICT(FOR_ITER);
-            PREDICT(CALL_NO_KW);
             DISPATCH();
         }
 
@@ -4529,8 +4527,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(PRECALL_FUNCTION) {
+            call_shape.callable = PEEK(oparg + 1);
             call_shape.postcall_shrink = 1;
-            call_shape.extra_args = 0;
+            call_shape.positional_args = oparg;
+            call_shape.named_args = 0;
             call_shape.kwnames = NULL;
             DISPATCH();
         }
@@ -4563,56 +4563,59 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                make it accept the `self` as a first argument.
             */
             int is_method = (PEEK(oparg + 2) != NULL);
-            call_shape.extra_args = is_method;
+            int nargs = oparg + is_method;
+            call_shape.callable = PEEK(nargs + 1);
+            call_shape.positional_args = nargs;
             call_shape.postcall_shrink = 2-is_method;
+            call_shape.named_args = 0;
             call_shape.kwnames = NULL;
             DISPATCH();
         }
 
-        TARGET(CALL_KW) {
-            call_shape.kwnames = POP();
-            oparg += call_shape.extra_args;
-            call_shape.extra_args = 0;
-            call_shape.nargs = oparg - (int)PyTuple_GET_SIZE(call_shape.kwnames);
-            goto call_function;
+        TARGET(KW_NAMES) {
+            assert(call_shape.kwnames == NULL);
+            assert(oparg < PyTuple_GET_SIZE(consts));
+            call_shape.kwnames = GETITEM(consts, oparg);
+            call_shape.named_args = PyTuple_GET_SIZE(call_shape.kwnames);
+            call_shape.positional_args -= call_shape.named_args;
+            DISPATCH();
         }
 
-        TARGET(CALL_NO_KW) {
+        TARGET(CALL) {
             PyObject *function;
-            PREDICTED(CALL_NO_KW);
-            call_shape.kwnames = NULL;
-            oparg += call_shape.extra_args;
-            call_shape.nargs = oparg;
+            PREDICTED(CALL);
+            assert(call_shape.named_args == oparg);
+            assert((oparg == 0 && call_shape.kwnames == NULL)
+                || (oparg != 0 && oparg == PyTuple_GET_SIZE(call_shape.kwnames)));
         call_function:
-            function = PEEK(oparg + 1);
+            function = call_shape.callable;
             if (Py_TYPE(function) == &PyMethod_Type) {
                 PyObject *meth = ((PyMethodObject *)function)->im_func;
                 PyObject *self = ((PyMethodObject *)function)->im_self;
                 Py_INCREF(meth);
                 Py_INCREF(self);
-                PEEK(oparg + 1) = self;
+                PEEK(call_shape.positional_args + call_shape.named_args + 1) = self;
                 Py_DECREF(function);
                 function = meth;
-                oparg++;
-                call_shape.nargs++;
+                call_shape.positional_args++;
                 assert(call_shape.postcall_shrink >= 1);
                 call_shape.postcall_shrink--;
             }
+            int total_args = call_shape.positional_args + call_shape.named_args;
             // Check if the call can be inlined or not
             if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
                 int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
                 int is_generator = code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR);
                 if (!is_generator) {
                     PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function);
-                    STACK_SHRINK(oparg);
+                    STACK_SHRINK(total_args);
                     InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
                         tstate, (PyFunctionObject *)function, locals,
-                        stack_pointer, call_shape.nargs, call_shape.kwnames
+                        stack_pointer, call_shape.positional_args, call_shape.kwnames
                     );
                     STACK_SHRINK(call_shape.postcall_shrink);
                     // The frame has stolen all the arguments from the stack,
                     // so there is no need to clean them up.
-                    Py_XDECREF(call_shape.kwnames);
                     Py_DECREF(function);
                     if (new_frame == NULL) {
                         goto error;
@@ -4627,21 +4630,20 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             PyObject *res;
             if (cframe.use_tracing) {
                 res = trace_call_function(
-                    tstate, function, stack_pointer-oparg,
-                    call_shape.nargs, call_shape.kwnames);
+                    tstate, function, stack_pointer-total_args,
+                    call_shape.positional_args, call_shape.kwnames);
             }
             else {
                 res = PyObject_Vectorcall(
-                    function, stack_pointer-oparg,
-                    call_shape.nargs | PY_VECTORCALL_ARGUMENTS_OFFSET,
+                    function, stack_pointer-total_args,
+                    call_shape.positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
                     call_shape.kwnames);
             }
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
             Py_DECREF(function);
-            Py_XDECREF(call_shape.kwnames);
             /* Clear the stack */
-            STACK_SHRINK(oparg);
-            for (int i = 0; i < oparg; i++) {
+            STACK_SHRINK(total_args);
+            for (int i = 0; i < total_args; i++) {
                 Py_DECREF(stack_pointer[i]);
             }
             STACK_SHRINK(call_shape.postcall_shrink);
@@ -4653,24 +4655,25 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
-        TARGET(CALL_NO_KW_ADAPTIVE) {
+        TARGET(CALL_ADAPTIVE) {
             SpecializedCacheEntry *cache = GET_CACHE();
-            oparg = cache->adaptive.original_oparg;
+            int named_args = cache->adaptive.original_oparg;
+            assert(call_shape.named_args == named_args);
+            assert((named_args == 0 && call_shape.kwnames == NULL)
+                || (named_args != 0 && named_args == PyTuple_GET_SIZE(call_shape.kwnames)));
             if (cache->adaptive.counter == 0) {
                 next_instr--;
-                int nargs = oparg + call_shape.extra_args;
+                int nargs = call_shape.positional_args;
                 if (_Py_Specialize_CallNoKw(
-                    PEEK(nargs + 1), next_instr, nargs, cache, BUILTINS()) < 0) {
+                    call_shape.callable, next_instr, nargs, cache, BUILTINS()) < 0) {
                     goto error;
                 }
                 DISPATCH();
             }
             else {
-                STAT_INC(CALL_NO_KW, deferred);
+                STAT_INC(CALL, deferred);
                 cache->adaptive.counter--;
-                call_shape.kwnames = NULL;
-                oparg += call_shape.extra_args;
-                call_shape.nargs = oparg;
+                oparg = named_args;
                 goto call_function;
             }
         }
@@ -4678,16 +4681,17 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_PY_SIMPLE) {
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            int argcount = cache0->original_oparg + call_shape.extra_args;
-            DEOPT_IF(argcount != cache0->index, CALL_NO_KW);
+            int argcount = call_shape.positional_args;
+            assert(call_shape.named_args == 0);
+            DEOPT_IF(argcount != cache0->index, CALL);
             _PyCallCache *cache1 = &caches[-1].call;
             PyObject *callable = PEEK(argcount+1);
-            DEOPT_IF(!PyFunction_Check(callable), CALL_NO_KW);
+            DEOPT_IF(!PyFunction_Check(callable), CALL);
             PyFunctionObject *func = (PyFunctionObject *)callable;
-            DEOPT_IF(func->func_version != cache1->func_version, CALL_NO_KW);
+            DEOPT_IF(func->func_version != cache1->func_version, CALL);
             /* PEP 523 */
-            DEOPT_IF(tstate->interp->eval_frame != NULL, CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
+            DEOPT_IF(tstate->interp->eval_frame != NULL, CALL);
+            STAT_INC(CALL, hit);
             PyCodeObject *code = (PyCodeObject *)func->func_code;
             size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE;
             InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
@@ -4718,11 +4722,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_TYPE_1) {
-            assert(STACK_ADJUST_IS_RESET);
             assert(GET_CACHE()->adaptive.original_oparg == 1);
             PyObject *obj = TOP();
             PyObject *callable = SECOND();
-            DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL_NO_KW);
+            DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL);
             PyObject *res = Py_NewRef(Py_TYPE(obj));
             STACK_SHRINK(1);
             Py_DECREF(callable);
@@ -4732,15 +4735,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_BUILTIN_CLASS_1) {
-            assert(STACK_ADJUST_IS_RESET);
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
             assert(cache0->original_oparg == 1);
             PyObject *callable = SECOND();
             PyObject *arg = TOP();
-            DEOPT_IF(!PyType_Check(callable), CALL_NO_KW);
+            DEOPT_IF(!PyType_Check(callable), CALL);
             PyTypeObject *tp = (PyTypeObject *)callable;
-            DEOPT_IF(tp->tp_version_tag != cache0->version, CALL_NO_KW);
+            DEOPT_IF(tp->tp_version_tag != cache0->version, CALL);
             STACK_SHRINK(1);
             PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer, 1, NULL);
             SET_TOP(res);
@@ -4754,13 +4756,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_BUILTIN_O) {
             assert(cframe.use_tracing == 0);
-            assert(STACK_ADJUST_IS_RESET);
             /* Builtin METH_O functions */
 
             PyObject *callable = SECOND();
-            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL_NO_KW);
-            DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
+            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
+            DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, CALL);
+            STAT_INC(CALL, hit);
 
             PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
             // This is slower but CPython promises to check all non-vectorcall
@@ -4785,17 +4786,16 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_BUILTIN_FAST) {
             assert(cframe.use_tracing == 0);
-            assert(STACK_ADJUST_IS_RESET);
             /* Builtin METH_FASTCALL functions, without keywords */
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
             int nargs = cache0->original_oparg;
             PyObject **pfunc = &PEEK(nargs + 1);
             PyObject *callable = *pfunc;
-            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL_NO_KW);
+            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_FASTCALL,
-                CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
+                CALL);
+            STAT_INC(CALL, hit);
 
             PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
             /* res = func(self, args, nargs) */
@@ -4824,15 +4824,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_LEN) {
             assert(cframe.use_tracing == 0);
-            assert(STACK_ADJUST_IS_RESET);
             /* len(o) */
             SpecializedCacheEntry *caches = GET_CACHE();
             assert(caches[0].adaptive.original_oparg == 1);
             _PyObjectCache *cache1 = &caches[-1].obj;
 
             PyObject *callable = SECOND();
-            DEOPT_IF(callable != cache1->obj, CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
+            DEOPT_IF(callable != cache1->obj, CALL);
+            STAT_INC(CALL, hit);
 
             Py_ssize_t len_i = PyObject_Length(TOP());
             if (len_i < 0) {
@@ -4853,15 +4852,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_ISINSTANCE) {
             assert(cframe.use_tracing == 0);
-            assert(STACK_ADJUST_IS_RESET);
             /* isinstance(o, o2) */
             SpecializedCacheEntry *caches = GET_CACHE();
             assert(caches[0].adaptive.original_oparg == 2);
             _PyObjectCache *cache1 = &caches[-1].obj;
 
             PyObject *callable = THIRD();
-            DEOPT_IF(callable != cache1->obj, CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
+            DEOPT_IF(callable != cache1->obj, CALL);
+            STAT_INC(CALL, hit);
 
             int retval = PyObject_IsInstance(SECOND(), TOP());
             if (retval < 0) {
@@ -4884,13 +4882,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_LIST_APPEND) {
             assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
             assert(GET_CACHE()->adaptive.original_oparg == 1);
-            DEOPT_IF(call_shape.extra_args == 0, CALL_NO_KW);
+            DEOPT_IF(call_shape.positional_args == oparg, CALL);
+            assert(call_shape.positional_args == oparg+1);
             PyObject *list = SECOND();
-            DEOPT_IF(!PyList_CheckExact(list), CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
-            assert(call_shape.extra_args == 1);
-            call_shape.extra_args = 0;
-            assert(STACK_ADJUST_IS_RESET);
+            DEOPT_IF(!PyList_CheckExact(list), CALL);
+            STAT_INC(CALL, hit);
             PyObject *arg = TOP();
             int err = PyList_Append(list, arg);
             if (err) {
@@ -4909,15 +4905,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
             assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
             assert(GET_CACHE()->adaptive.original_oparg == 1);
-            DEOPT_IF(call_shape.extra_args == 0, CALL_NO_KW);
-            assert(call_shape.extra_args == 1);
+            DEOPT_IF(call_shape.positional_args == oparg, CALL);
+            assert(call_shape.positional_args == oparg+1);
             PyObject *callable = THIRD();
-            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL_NO_KW);
-            DEOPT_IF(((PyMethodDescrObject *)callable)->d_method->ml_flags != METH_O, CALL_NO_KW);
+            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
+            DEOPT_IF(((PyMethodDescrObject *)callable)->d_method->ml_flags != METH_O, CALL);
             STAT_INC(CALL_NO_KW, hit);
-            assert(call_shape.extra_args == 1);
-            call_shape.extra_args = 0;
-            assert(STACK_ADJUST_IS_RESET);
             PyCFunction cfunc = ((PyMethodDescrObject *)callable)->d_method->ml_meth;
             // This is slower but CPython promises to check all non-vectorcall
             // function calls.
@@ -4944,17 +4937,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             /* Builtin METH_FASTCALL methods, without keywords */
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            DEOPT_IF(call_shape.extra_args == 0, CALL_NO_KW);
-            assert(call_shape.extra_args == 1);
+            DEOPT_IF(call_shape.positional_args == oparg, CALL);
+            assert(call_shape.positional_args == oparg+1);
             int nargs = cache0->original_oparg;
             PyObject *callable = PEEK(nargs + 2);
-            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type),  CALL_NO_KW);
+            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
             PyMethodDef *meth = ((PyMethodDescrObject *)callable)->d_method;
-            DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL_NO_KW);
-            STAT_INC(CALL_NO_KW, hit);
-            assert(call_shape.extra_args == 1);
-            call_shape.extra_args = 0;
-            assert(STACK_ADJUST_IS_RESET);
+            DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
+            STAT_INC(CALL, hit);
             _PyCFunctionFast cfunc = (_PyCFunctionFast)(void(*)(void))meth->ml_meth;
             PyObject *self = PEEK(nargs+1);
             PyObject *res = cfunc(self, &PEEK(nargs), nargs);
@@ -5281,7 +5271,7 @@ MISS_WITH_CACHE(LOAD_ATTR)
 MISS_WITH_CACHE(STORE_ATTR)
 MISS_WITH_CACHE(LOAD_GLOBAL)
 MISS_WITH_CACHE(LOAD_METHOD)
-MISS_WITH_CACHE(CALL_NO_KW)
+MISS_WITH_CACHE(CALL)
 MISS_WITH_CACHE(BINARY_OP)
 MISS_WITH_CACHE(COMPARE_OP)
 MISS_WITH_CACHE(BINARY_SUBSCR)
@@ -7369,7 +7359,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevpr
                           "that does not implement __await__: %.100s",
                           type->tp_name);
         }
-        else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL_NO_KW && prevprevprevopcode == DUP_TOP)) {
+        else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL && prevprevprevopcode == DUP_TOP)) {
             _PyErr_Format(tstate, PyExc_TypeError,
                           "'async with' received an object from __aexit__ "
                           "that does not implement __await__: %.100s",
diff --git a/Python/compile.c b/Python/compile.c
index 10e36d5eebd883..cca4d613e26718 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1153,13 +1153,14 @@ stack_effect(int opcode, int oparg, int jump)
 
         /* Functions and calls */
         case PRECALL_METHOD:
-            return -1;
+            return -oparg-1;
         case PRECALL_FUNCTION:
-            return 0;
-        case CALL_NO_KW:
             return -oparg;
-        case CALL_KW:
-            return -oparg-1;
+        case KW_NAMES:
+            return 0;
+        case CALL:
+            return 0;
+
         case CALL_FUNCTION_EX:
             return -1 - ((oparg & 0x01) != 0);
         case MAKE_FUNCTION:
@@ -1819,7 +1820,7 @@ compiler_call_exit_with_nones(struct compiler *c) {
     ADDOP(c, DUP_TOP);
     ADDOP(c, DUP_TOP);
     ADDOP_I(c, PRECALL_FUNCTION, 3);
-    ADDOP_I(c, CALL_NO_KW, 3);
+    ADDOP_I(c, CALL, 0);
     return 1;
 }
 
@@ -2201,7 +2202,7 @@ compiler_apply_decorators(struct compiler *c, asdl_expr_seq* decos)
     for (Py_ssize_t i = asdl_seq_LEN(decos) - 1; i > -1; i--) {
         SET_LOC(c, (expr_ty)asdl_seq_GET(decos, i));
         ADDOP_I(c, PRECALL_FUNCTION, 1);
-        ADDOP_I(c, CALL_NO_KW, 1);
+        ADDOP_I(c, CALL, 0);
     }
     c->u->u_lineno = old_lineno;
     c->u->u_end_lineno = old_end_lineno;
@@ -3901,7 +3902,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
     if (s->v.Assert.msg) {
         VISIT(c, expr, s->v.Assert.msg);
         ADDOP_I(c, PRECALL_FUNCTION, 1);
-        ADDOP_I(c, CALL_NO_KW, 1);
+        ADDOP_I(c, CALL, 0);
     }
     ADDOP_I(c, RAISE_VARARGS, 1);
     compiler_use_next_block(c, end);
@@ -4706,15 +4707,16 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
     VISIT_SEQ(c, expr, e->v.Call.args);
 
     if (kwdsl) {
+        VISIT_SEQ(c, keyword, kwds);
+        ADDOP_I(c, PRECALL_METHOD, argsl + kwdsl);
         if (!compiler_call_simple_kw_helper(c, kwds, kwdsl)) {
             return 0;
         };
-        ADDOP_I(c, PRECALL_METHOD, argsl + kwdsl+1);
-        ADDOP_I(c, CALL_KW, argsl + kwdsl);
+        ADDOP_I(c, CALL, kwdsl);
     }
     else {
         ADDOP_I(c, PRECALL_METHOD, argsl);
-        ADDOP_I(c, CALL_NO_KW, argsl);
+        ADDOP_I(c, CALL, 0);
     }
     c->u->u_lineno = old_lineno;
     return 1;
@@ -4782,7 +4784,7 @@ compiler_joined_str(struct compiler *c, expr_ty e)
             ADDOP_I(c, LIST_APPEND, 1);
         }
         ADDOP_I(c, PRECALL_METHOD, 1);
-        ADDOP_I(c, CALL_NO_KW, 1);
+        ADDOP_I(c, CALL, 0);
     }
     else {
         VISIT_SEQ(c, expr, e->v.JoinedStr.values);
@@ -4883,21 +4885,15 @@ compiler_subkwargs(struct compiler *c, asdl_keyword_seq *keywords, Py_ssize_t be
 }
 
 /* Used by compiler_call_helper and maybe_optimize_method_call to emit
-LOAD_CONST kw1
-LOAD_CONST kw2
-...
-LOAD_CONST <tuple of kwnames>
-before a CALL_(FUNCTION|METHOD)_KW.
-
-Returns 1 on success, 0 on error.
-*/
+ * KW_NAMES before CALL.
+ * Returns 1 on success, 0 on error.
+ */
 static int
 compiler_call_simple_kw_helper(struct compiler *c,
                                asdl_keyword_seq *keywords,
                                Py_ssize_t nkwelts)
 {
     PyObject *names;
-    VISIT_SEQ(c, keyword, keywords);
     names = PyTuple_New(nkwelts);
     if (names == NULL) {
         return 0;
@@ -4907,7 +4903,12 @@ compiler_call_simple_kw_helper(struct compiler *c,
         Py_INCREF(kw->arg);
         PyTuple_SET_ITEM(names, i, kw->arg);
     }
-    ADDOP_LOAD_CONST_NEW(c, names);
+    Py_ssize_t arg = compiler_add_const(c, names);
+    if (arg < 0) {
+        return 0;
+    }
+    Py_DECREF(names);
+    ADDOP_I(c, KW_NAMES, arg);
     return 1;
 }
 
@@ -4951,16 +4952,17 @@ compiler_call_helper(struct compiler *c,
         VISIT(c, expr, elt);
     }
     if (nkwelts) {
+        VISIT_SEQ(c, keyword, keywords);
+        ADDOP_I(c, PRECALL_FUNCTION, n + nelts + nkwelts);
         if (!compiler_call_simple_kw_helper(c, keywords, nkwelts)) {
             return 0;
         };
-        ADDOP_I(c, PRECALL_FUNCTION, n + nelts + nkwelts + 1);
-        ADDOP_I(c, CALL_KW, n + nelts + nkwelts);
+        ADDOP_I(c, CALL, nkwelts);
         return 1;
     }
     else {
         ADDOP_I(c, PRECALL_FUNCTION, n + nelts);
-        ADDOP_I(c, CALL_NO_KW, n + nelts);
+        ADDOP_I(c, CALL, 0);
         return 1;
     }
 
@@ -5358,7 +5360,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
     }
 
     ADDOP_I(c, PRECALL_FUNCTION, 1);
-    ADDOP_I(c, CALL_NO_KW, 1);
+    ADDOP_I(c, CALL, 0);
 
     if (is_async_generator && type != COMP_GENEXP) {
         ADDOP(c, GET_AWAITABLE);
@@ -8980,7 +8982,8 @@ trim_unused_consts(struct compiler *c, struct assembler *a, PyObject *consts)
     int max_const_index = 0;
     for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
         for (int i = 0; i < b->b_iused; i++) {
-            if (b->b_instr[i].i_opcode == LOAD_CONST &&
+            if ((b->b_instr[i].i_opcode == LOAD_CONST ||
+                b->b_instr[i].i_opcode == KW_NAMES) &&
                     b->b_instr[i].i_oparg > max_const_index) {
                 max_const_index = b->b_instr[i].i_oparg;
             }
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index da8977672d4b5f..c44828eae28bb7 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -38,7 +38,7 @@ static void *opcode_targets[256] = {
     &&TARGET_STORE_SUBSCR_ADAPTIVE,
     &&TARGET_STORE_SUBSCR_LIST_INT,
     &&TARGET_STORE_SUBSCR_DICT,
-    &&TARGET_CALL_NO_KW_ADAPTIVE,
+    &&TARGET_CALL_ADAPTIVE,
     &&TARGET_CALL_NO_KW_BUILTIN_O,
     &&TARGET_CALL_NO_KW_BUILTIN_FAST,
     &&TARGET_CALL_NO_KW_LEN,
@@ -168,10 +168,10 @@ static void *opcode_targets[256] = {
     &&_unknown_opcode,
     &&TARGET_PRECALL_FUNCTION,
     &&TARGET_PRECALL_METHOD,
-    &&TARGET_CALL_NO_KW,
-    &&TARGET_CALL_KW,
     &&_unknown_opcode,
     &&_unknown_opcode,
+    &&TARGET_CALL,
+    &&TARGET_KW_NAMES,
     &&_unknown_opcode,
     &&_unknown_opcode,
     &&_unknown_opcode,
diff --git a/Python/specialize.c b/Python/specialize.c
index 2da9e0f29b7a43..a5f8bd95f040cc 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -251,7 +251,7 @@ static uint8_t adaptive_opcodes[256] = {
     [LOAD_METHOD] = LOAD_METHOD_ADAPTIVE,
     [BINARY_SUBSCR] = BINARY_SUBSCR_ADAPTIVE,
     [STORE_SUBSCR] = STORE_SUBSCR_ADAPTIVE,
-    [CALL_NO_KW] = CALL_NO_KW_ADAPTIVE,
+    [CALL] = CALL_ADAPTIVE,
     [STORE_ATTR] = STORE_ATTR_ADAPTIVE,
     [BINARY_OP] = BINARY_OP_ADAPTIVE,
     [COMPARE_OP] = COMPARE_OP_ADAPTIVE,
@@ -264,7 +264,7 @@ static uint8_t cache_requirements[256] = {
     [LOAD_METHOD] = 3, /* _PyAdaptiveEntry, _PyAttrCache and _PyObjectCache */
     [BINARY_SUBSCR] = 2, /* _PyAdaptiveEntry, _PyObjectCache */
     [STORE_SUBSCR] = 0,
-    [CALL_NO_KW] = 2, /* _PyAdaptiveEntry and _PyObjectCache/_PyCallCache */
+    [CALL] = 2, /* _PyAdaptiveEntry and _PyObjectCache/_PyCallCache */
     [STORE_ATTR] = 2, /* _PyAdaptiveEntry and _PyAttrCache */
     [BINARY_OP] = 1,  // _PyAdaptiveEntry
     [COMPARE_OP] = 1, /* _PyAdaptiveEntry */
@@ -1567,6 +1567,8 @@ _Py_Specialize_CallNoKw(
     int nargs, SpecializedCacheEntry *cache,
     PyObject *builtins)
 {
+    cache_backoff(&cache->adaptive);
+    return 0;
     int fail;
     if (PyCFunction_CheckExact(callable)) {
         fail = specialize_c_call(callable, instr, nargs, cache, builtins);

From f47f8a10c9533b1a76a5b137918dc97b8c1d3773 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 7 Jan 2022 17:15:22 +0000
Subject: [PATCH 05/34] Remove named_args from call_shape struct.

---
 Python/ceval.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index b0ee0c298a1cf8..1e259e6fc1e74a 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1657,7 +1657,6 @@ typedef struct {
     PyObject *callable;
     PyObject *kwnames;
     int positional_args;
-    int named_args;
     int postcall_shrink;
 } CallShape;
 
@@ -1684,7 +1683,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     call_shape.kwnames = NULL;
     call_shape.postcall_shrink = 1;
     call_shape.positional_args = 0;
-    call_shape.named_args = 0;
 
     /* WARNING: Because the CFrame lives on the C stack,
      * but can be accessed from a heap allocated object (tstate)
@@ -4572,7 +4570,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.callable = PEEK(oparg + 1);
             call_shape.postcall_shrink = 1;
             call_shape.positional_args = oparg;
-            call_shape.named_args = 0;
             call_shape.kwnames = NULL;
             DISPATCH();
         }
@@ -4609,7 +4606,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.callable = PEEK(nargs + 1);
             call_shape.positional_args = nargs;
             call_shape.postcall_shrink = 2-is_method;
-            call_shape.named_args = 0;
             call_shape.kwnames = NULL;
             DISPATCH();
         }
@@ -4618,32 +4614,31 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(call_shape.kwnames == NULL);
             assert(oparg < PyTuple_GET_SIZE(consts));
             call_shape.kwnames = GETITEM(consts, oparg);
-            call_shape.named_args = PyTuple_GET_SIZE(call_shape.kwnames);
-            call_shape.positional_args -= call_shape.named_args;
             DISPATCH();
         }
 
         TARGET(CALL) {
-            PyObject *function;
+            int total_args;
             PREDICTED(CALL);
-            assert(call_shape.named_args == oparg);
             assert((oparg == 0 && call_shape.kwnames == NULL)
                 || (oparg != 0 && oparg == PyTuple_GET_SIZE(call_shape.kwnames)));
         call_function:
-            function = call_shape.callable;
+            total_args = call_shape.positional_args;
+            call_shape.positional_args -= oparg;
+            PyObject *function = call_shape.callable;
             if (Py_TYPE(function) == &PyMethod_Type) {
                 PyObject *meth = ((PyMethodObject *)function)->im_func;
                 PyObject *self = ((PyMethodObject *)function)->im_self;
                 Py_INCREF(meth);
                 Py_INCREF(self);
-                PEEK(call_shape.positional_args + call_shape.named_args + 1) = self;
+                PEEK(call_shape.positional_args + oparg + 1) = self;
                 Py_DECREF(function);
                 function = meth;
                 call_shape.positional_args++;
+                total_args++;
                 assert(call_shape.postcall_shrink >= 1);
                 call_shape.postcall_shrink--;
             }
-            int total_args = call_shape.positional_args + call_shape.named_args;
             // Check if the call can be inlined or not
             if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
                 int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
@@ -4700,7 +4695,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_ADAPTIVE) {
             SpecializedCacheEntry *cache = GET_CACHE();
             int named_args = cache->adaptive.original_oparg;
-            assert(call_shape.named_args == named_args);
             assert((named_args == 0 && call_shape.kwnames == NULL)
                 || (named_args != 0 && named_args == PyTuple_GET_SIZE(call_shape.kwnames)));
             if (cache->adaptive.counter == 0) {
@@ -4724,7 +4718,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
             int argcount = call_shape.positional_args;
-            assert(call_shape.named_args == 0);
             DEOPT_IF(argcount != cache0->index, CALL);
             _PyCallCache *cache1 = &caches[-1].call;
             PyObject *callable = PEEK(argcount+1);
@@ -4764,7 +4757,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_TYPE_1) {
-            assert(GET_CACHE()->adaptive.original_oparg == 1);
+            assert(call_shape.positional_args = 1);
+            assert(GET_CACHE()->adaptive.original_oparg == 0);
             PyObject *obj = TOP();
             PyObject *callable = SECOND();
             DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL);

From 7ea553fc1a10b2363e556ecb9e4f674fc86d3b89 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 7 Jan 2022 17:28:13 +0000
Subject: [PATCH 06/34] Handle bound-methods in PRECALL instructions.

---
 Python/ceval.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 1e259e6fc1e74a..03bc014cdd866f 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4571,6 +4571,18 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.postcall_shrink = 1;
             call_shape.positional_args = oparg;
             call_shape.kwnames = NULL;
+            if (Py_TYPE(call_shape.callable) == &PyMethod_Type) {
+                PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
+                PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
+                Py_INCREF(meth);
+                Py_INCREF(self);
+                PEEK(oparg + 1) = self;
+                Py_DECREF(call_shape.callable);
+                call_shape.callable = meth;
+                call_shape.positional_args++;
+                assert(call_shape.postcall_shrink >= 1);
+                call_shape.postcall_shrink--;
+            }
             DISPATCH();
         }
 
@@ -4607,6 +4619,18 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.positional_args = nargs;
             call_shape.postcall_shrink = 2-is_method;
             call_shape.kwnames = NULL;
+            if (Py_TYPE(call_shape.callable) == &PyMethod_Type) {
+                PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
+                PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
+                Py_INCREF(meth);
+                Py_INCREF(self);
+                PEEK(nargs + 1) = self;
+                Py_DECREF(call_shape.callable);
+                call_shape.callable = meth;
+                call_shape.positional_args++;
+                assert(call_shape.postcall_shrink >= 1);
+                call_shape.postcall_shrink--;
+            }
             DISPATCH();
         }
 
@@ -4626,19 +4650,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             total_args = call_shape.positional_args;
             call_shape.positional_args -= oparg;
             PyObject *function = call_shape.callable;
-            if (Py_TYPE(function) == &PyMethod_Type) {
-                PyObject *meth = ((PyMethodObject *)function)->im_func;
-                PyObject *self = ((PyMethodObject *)function)->im_self;
-                Py_INCREF(meth);
-                Py_INCREF(self);
-                PEEK(call_shape.positional_args + oparg + 1) = self;
-                Py_DECREF(function);
-                function = meth;
-                call_shape.positional_args++;
-                total_args++;
-                assert(call_shape.postcall_shrink >= 1);
-                call_shape.postcall_shrink--;
-            }
             // Check if the call can be inlined or not
             if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
                 int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;

From 0b52de2ea9bdb49f9eb422d99a44e3483719e0c7 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Mon, 10 Jan 2022 14:48:43 +0000
Subject: [PATCH 07/34] Restore specialization of calls to builtin functions.

---
 Python/ceval.c      | 60 +++++++++++++++++++++++++--------------------
 Python/specialize.c | 31 +++++++++++------------
 2 files changed, 50 insertions(+), 41 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 03bc014cdd866f..c68ca7f561db25 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4804,8 +4804,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_BUILTIN_O) {
             assert(cframe.use_tracing == 0);
             /* Builtin METH_O functions */
-
-            PyObject *callable = SECOND();
+            assert(call_shape.kwnames == NULL);
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            PyObject *callable = call_shape.callable;
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, CALL);
             STAT_INC(CALL, hit);
@@ -4816,14 +4817,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
                 goto error;
             }
-            PyObject *arg = POP();
+            PyObject *arg = TOP();
             PyObject *res = cfunc(PyCFunction_GET_SELF(callable), arg);
             _Py_LeaveRecursiveCall(tstate);
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
 
-            /* Clear the stack of the function object. */
             Py_DECREF(arg);
             Py_DECREF(callable);
+            STACK_SHRINK(call_shape.postcall_shrink);
             SET_TOP(res);
             if (res == NULL) {
                 goto error;
@@ -4836,27 +4837,29 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             /* Builtin METH_FASTCALL functions, without keywords */
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            int nargs = cache0->original_oparg;
-            PyObject **pfunc = &PEEK(nargs + 1);
-            PyObject *callable = *pfunc;
+            assert(cache0->original_oparg == 0);
+            PyObject *callable = call_shape.callable;
+            assert(call_shape.kwnames == NULL);
+            int nargs = call_shape.positional_args;
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_FASTCALL,
                 CALL);
             STAT_INC(CALL, hit);
 
             PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
+            STACK_SHRINK(nargs);
             /* res = func(self, args, nargs) */
             PyObject *res = ((_PyCFunctionFast)(void(*)(void))cfunc)(
                 PyCFunction_GET_SELF(callable),
-                &PEEK(nargs),
+                stack_pointer,
                 nargs);
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
 
-            /* Clear the stack of the function object. */
-            while (stack_pointer > pfunc) {
-                PyObject *x = POP();
-                Py_DECREF(x);
+            /* Free the arguments. */
+            for (int i = 0; i < nargs; i++) {
+                Py_DECREF(stack_pointer[i]);
             }
+            STACK_SHRINK(call_shape.postcall_shrink);
             PUSH(res);
             if (res == NULL) {
                 /* Not deopting because this doesn't mean our optimization was
@@ -4871,26 +4874,29 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_LEN) {
             assert(cframe.use_tracing == 0);
+            assert(call_shape.kwnames == NULL);
             /* len(o) */
             SpecializedCacheEntry *caches = GET_CACHE();
-            assert(caches[0].adaptive.original_oparg == 1);
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            assert(caches[0].adaptive.original_oparg == 0);
             _PyObjectCache *cache1 = &caches[-1].obj;
 
-            PyObject *callable = SECOND();
+            PyObject *callable = call_shape.callable;
             DEOPT_IF(callable != cache1->obj, CALL);
             STAT_INC(CALL, hit);
 
-            Py_ssize_t len_i = PyObject_Length(TOP());
+            PyObject *arg = TOP();
+            Py_ssize_t len_i = PyObject_Length(arg);
             if (len_i < 0) {
                 goto error;
             }
             PyObject *res = PyLong_FromSsize_t(len_i);
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
 
-            /* Clear the stack of the function object. */
-            Py_DECREF(POP());
-            Py_DECREF(callable);
+            STACK_SHRINK(call_shape.postcall_shrink);
             SET_TOP(res);
+            Py_DECREF(callable);
+            Py_DECREF(arg);
             if (res == NULL) {
                 goto error;
             }
@@ -4901,25 +4907,27 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(cframe.use_tracing == 0);
             /* isinstance(o, o2) */
             SpecializedCacheEntry *caches = GET_CACHE();
-            assert(caches[0].adaptive.original_oparg == 2);
+            assert(caches[0].adaptive.original_oparg == 0);
+            DEOPT_IF(call_shape.positional_args != 2, CALL);
             _PyObjectCache *cache1 = &caches[-1].obj;
 
-            PyObject *callable = THIRD();
-            DEOPT_IF(callable != cache1->obj, CALL);
+            DEOPT_IF(call_shape.callable != cache1->obj, CALL);
             STAT_INC(CALL, hit);
 
-            int retval = PyObject_IsInstance(SECOND(), TOP());
+            PyObject *cls = POP();
+            PyObject *inst = TOP();
+            int retval = PyObject_IsInstance(inst, cls);
             if (retval < 0) {
                 goto error;
             }
             PyObject *res = PyBool_FromLong(retval);
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
 
-            /* Clear the stack of the function object. */
-            Py_DECREF(POP());
-            Py_DECREF(POP());
-            Py_DECREF(callable);
+            STACK_SHRINK(call_shape.postcall_shrink);
             SET_TOP(res);
+            Py_DECREF(inst);
+            Py_DECREF(cls);
+            Py_DECREF(call_shape.callable);
             if (res == NULL) {
                 goto error;
             }
diff --git a/Python/specialize.c b/Python/specialize.c
index a5f8bd95f040cc..4ed557b335acde 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1487,8 +1487,8 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
     SpecializedCacheEntry *cache, PyObject *builtins)
 {
     _PyObjectCache *cache1 = &cache[-1].obj;
-    if (_Py_OPCODE(instr[-1]) == PRECALL_METHOD) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_C_METHOD_CALL);
+    if (_Py_OPCODE(instr[-1]) == KW_NAMES) {
+        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_COMPLEX_PARAMETERS);
         return -1;
     }
     if (PyCFunction_GET_FUNCTION(callable) == NULL) {
@@ -1567,26 +1567,27 @@ _Py_Specialize_CallNoKw(
     int nargs, SpecializedCacheEntry *cache,
     PyObject *builtins)
 {
-    cache_backoff(&cache->adaptive);
-    return 0;
     int fail;
     if (PyCFunction_CheckExact(callable)) {
         fail = specialize_c_call(callable, instr, nargs, cache, builtins);
     }
-    else if (PyFunction_Check(callable)) {
-        fail = specialize_py_call((PyFunctionObject *)callable, instr, nargs, cache);
-    }
-    else if (PyType_Check(callable)) {
-        fail = specialize_class_call(callable, instr, nargs, cache);
-    }
-    else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
-        fail = specialize_method_descriptor(
-            (PyMethodDescrObject *)callable, instr, nargs, cache);
-    }
     else {
-        SPECIALIZATION_FAIL(CALL_NO_KW, call_fail_kind(callable));
         fail = -1;
     }
+//     else if (PyFunction_Check(callable)) {
+//         fail = specialize_py_call((PyFunctionObject *)callable, instr, nargs, cache);
+//     }
+//     else if (PyType_Check(callable)) {
+//         fail = specialize_class_call(callable, instr, nargs, cache);
+//     }
+//     else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
+//         fail = specialize_method_descriptor(
+//             (PyMethodDescrObject *)callable, instr, nargs, cache);
+//     }
+//     else {
+//         SPECIALIZATION_FAIL(CALL_NO_KW, call_fail_kind(callable));
+//         fail = -1;
+//     }
     _PyAdaptiveEntry *cache0 = &cache->adaptive;
     if (fail) {
         STAT_INC(CALL_NO_KW, failure);

From d2e5834fe91aa3ed6dc79f06c999ab6e37ab0f69 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Tue, 11 Jan 2022 15:54:50 +0000
Subject: [PATCH 08/34] Get specialized versions of CALL working again.

---
 Include/internal/pycore_code.h  |   5 +-
 Include/internal/pycore_frame.h |   3 +
 Include/opcode.h                |  59 ++++++-------
 Lib/opcode.py                   |   3 +-
 Python/ceval.c                  | 143 ++++++++++++++++++--------------
 Python/frame.c                  |  15 +++-
 Python/opcode_targets.h         |  22 ++---
 Python/specialize.c             | 113 +++++++++++++------------
 8 files changed, 207 insertions(+), 156 deletions(-)

diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index dfc75300315e29..357c677a3e1f87 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -38,7 +38,7 @@ typedef struct {
 
 typedef struct {
     uint32_t func_version;
-    uint16_t defaults_start;
+    uint16_t min_args;
     uint16_t defaults_len;
 } _PyCallCache;
 
@@ -271,7 +271,8 @@ int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNI
 int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
 int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
 int _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *instr);
-int _Py_Specialize_CallNoKw(PyObject *callable, _Py_CODEUNIT *instr, int nargs, SpecializedCacheEntry *cache, PyObject *builtins);
+int _Py_Specialize_CallNoKw(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
+    PyObject *kwnames, SpecializedCacheEntry *cache, PyObject *builtins);
 void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
                              SpecializedCacheEntry *cache);
 void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
index 42df51f635615d..fe3e73bf5dacb5 100644
--- a/Include/internal/pycore_frame.h
+++ b/Include/internal/pycore_frame.h
@@ -189,6 +189,9 @@ _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
 
 void _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame *frame);
 
+InterpreterFrame *
+_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Include/opcode.h b/Include/opcode.h
index a3383440408db0..c1d4543d12058c 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -141,35 +141,36 @@ extern "C" {
 #define CALL_NO_KW_BUILTIN_FAST          41
 #define CALL_NO_KW_LEN                   42
 #define CALL_NO_KW_ISINSTANCE            43
-#define CALL_NO_KW_PY_SIMPLE             44
-#define CALL_NO_KW_LIST_APPEND           45
-#define CALL_NO_KW_METHOD_DESCRIPTOR_O   46
-#define CALL_NO_KW_TYPE_1                47
-#define CALL_NO_KW_BUILTIN_CLASS_1       48
-#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  55
-#define JUMP_ABSOLUTE_QUICK              56
-#define LOAD_ATTR_ADAPTIVE               57
-#define LOAD_ATTR_INSTANCE_VALUE         58
-#define LOAD_ATTR_WITH_HINT              59
-#define LOAD_ATTR_SLOT                   62
-#define LOAD_ATTR_MODULE                 63
-#define LOAD_GLOBAL_ADAPTIVE             64
-#define LOAD_GLOBAL_MODULE               65
-#define LOAD_GLOBAL_BUILTIN              66
-#define LOAD_METHOD_ADAPTIVE             67
-#define LOAD_METHOD_CACHED               72
-#define LOAD_METHOD_CLASS                75
-#define LOAD_METHOD_MODULE               76
-#define LOAD_METHOD_NO_DICT              77
-#define STORE_ATTR_ADAPTIVE              78
-#define STORE_ATTR_INSTANCE_VALUE        79
-#define STORE_ATTR_SLOT                  80
-#define STORE_ATTR_WITH_HINT             81
-#define LOAD_FAST__LOAD_FAST             87
-#define STORE_FAST__LOAD_FAST           131
-#define LOAD_FAST__LOAD_CONST           134
-#define LOAD_CONST__LOAD_FAST           140
-#define STORE_FAST__STORE_FAST          141
+#define CALL_PY_EXACT_ARGS               44
+#define CALL_PY_WITH_DEFAULTS            45
+#define CALL_NO_KW_LIST_APPEND           46
+#define CALL_NO_KW_METHOD_DESCRIPTOR_O   47
+#define CALL_NO_KW_TYPE_1                48
+#define CALL_NO_KW_BUILTIN_CLASS_1       55
+#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  56
+#define JUMP_ABSOLUTE_QUICK              57
+#define LOAD_ATTR_ADAPTIVE               58
+#define LOAD_ATTR_INSTANCE_VALUE         59
+#define LOAD_ATTR_WITH_HINT              62
+#define LOAD_ATTR_SLOT                   63
+#define LOAD_ATTR_MODULE                 64
+#define LOAD_GLOBAL_ADAPTIVE             65
+#define LOAD_GLOBAL_MODULE               66
+#define LOAD_GLOBAL_BUILTIN              67
+#define LOAD_METHOD_ADAPTIVE             72
+#define LOAD_METHOD_CACHED               75
+#define LOAD_METHOD_CLASS                76
+#define LOAD_METHOD_MODULE               77
+#define LOAD_METHOD_NO_DICT              78
+#define STORE_ATTR_ADAPTIVE              79
+#define STORE_ATTR_INSTANCE_VALUE        80
+#define STORE_ATTR_SLOT                  81
+#define STORE_ATTR_WITH_HINT             87
+#define LOAD_FAST__LOAD_FAST            131
+#define STORE_FAST__LOAD_FAST           134
+#define LOAD_FAST__LOAD_CONST           140
+#define LOAD_CONST__LOAD_FAST           141
+#define STORE_FAST__STORE_FAST          143
 #define DO_TRACING                      255
 #ifdef NEED_OPCODE_JUMP_TABLES
 static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 7b808b1b15c5e9..beda06bb6d39db 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -256,7 +256,8 @@ def jabs_op(name, op):
     "CALL_NO_KW_BUILTIN_FAST",
     "CALL_NO_KW_LEN",
     "CALL_NO_KW_ISINSTANCE",
-    "CALL_NO_KW_PY_SIMPLE",
+    "CALL_PY_EXACT_ARGS",
+    "CALL_PY_WITH_DEFAULTS",
     "CALL_NO_KW_LIST_APPEND",
     "CALL_NO_KW_METHOD_DESCRIPTOR_O",
     "CALL_NO_KW_TYPE_1",
diff --git a/Python/ceval.c b/Python/ceval.c
index c68ca7f561db25..11e875bb777452 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4711,8 +4711,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             if (cache->adaptive.counter == 0) {
                 next_instr--;
                 int nargs = call_shape.positional_args;
-                if (_Py_Specialize_CallNoKw(
-                    call_shape.callable, next_instr, nargs, cache, BUILTINS()) < 0) {
+                int err = _Py_Specialize_CallNoKw(
+                    call_shape.callable, next_instr, nargs,
+                    call_shape.kwnames, cache, BUILTINS());
+                if (err < 0) {
                     goto error;
                 }
                 DISPATCH();
@@ -4725,38 +4727,60 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             }
         }
 
-        TARGET(CALL_NO_KW_PY_SIMPLE) {
+        TARGET(CALL_PY_EXACT_ARGS) {
             SpecializedCacheEntry *caches = GET_CACHE();
-            _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
             int argcount = call_shape.positional_args;
-            DEOPT_IF(argcount != cache0->index, CALL);
+            DEOPT_IF(!PyFunction_Check(call_shape.callable), CALL);
             _PyCallCache *cache1 = &caches[-1].call;
-            PyObject *callable = PEEK(argcount+1);
-            DEOPT_IF(!PyFunction_Check(callable), CALL);
-            PyFunctionObject *func = (PyFunctionObject *)callable;
+            PyFunctionObject *func = (PyFunctionObject *)call_shape.callable;
             DEOPT_IF(func->func_version != cache1->func_version, CALL);
-            /* PEP 523 */
-            DEOPT_IF(tstate->interp->eval_frame != NULL, CALL);
-            STAT_INC(CALL, hit);
             PyCodeObject *code = (PyCodeObject *)func->func_code;
-            size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE;
-            InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
+            DEOPT_IF(code->co_argcount != argcount, CALL);
+            InterpreterFrame *new_frame = _PyFrame_Push(tstate, func);
+            if (new_frame == NULL) {
+                goto error;
+            }
+            STACK_SHRINK(argcount);
+            for (int i = 0; i < argcount; i++) {
+                new_frame->localsplus[i] = stack_pointer[i];
+            }
+            for (int i = argcount; i < code->co_nlocalsplus; i++) {
+                new_frame->localsplus[i] = NULL;
+            }
+            STACK_SHRINK(call_shape.postcall_shrink);
+            Py_DECREF(func);
+            _PyFrame_SetStackPointer(frame, stack_pointer);
+            new_frame->previous = frame;
+            frame = cframe.current_frame = new_frame;
+            goto start_frame;
+        }
+
+        TARGET(CALL_PY_WITH_DEFAULTS) {
+            SpecializedCacheEntry *caches = GET_CACHE();
+            int argcount = call_shape.positional_args;
+            DEOPT_IF(!PyFunction_Check(call_shape.callable), CALL);
+            _PyCallCache *cache1 = &caches[-1].call;
+            PyFunctionObject *func = (PyFunctionObject *)call_shape.callable;
+            DEOPT_IF(func->func_version != cache1->func_version, CALL);
+            PyCodeObject *code = (PyCodeObject *)func->func_code;
+            DEOPT_IF(argcount > code->co_argcount, CALL);
+            int minargs = cache1->min_args;
+            DEOPT_IF(argcount < minargs, CALL);
+            InterpreterFrame *new_frame = _PyFrame_Push(tstate, func);
             if (new_frame == NULL) {
                 goto error;
             }
-            _PyFrame_InitializeSpecials(new_frame, func,
-                                        NULL, code->co_nlocalsplus);
             STACK_SHRINK(argcount);
             for (int i = 0; i < argcount; i++) {
                 new_frame->localsplus[i] = stack_pointer[i];
             }
-            int deflen = cache1->defaults_len;
-            for (int i = 0; i < deflen; i++) {
-                PyObject *def = PyTuple_GET_ITEM(func->func_defaults, cache1->defaults_start+i);
+            int def_offset = cache1->defaults_len - code->co_argcount;
+            for (int i = argcount; i < code->co_argcount; i++) {
+                PyObject *def = PyTuple_GET_ITEM(func->func_defaults, i + def_offset);
                 Py_INCREF(def);
-                new_frame->localsplus[argcount+i] = def;
+                new_frame->localsplus[i] = def;
             }
-            for (int i = argcount+deflen; i < code->co_nlocalsplus; i++) {
+            for (int i = code->co_argcount; i < code->co_nlocalsplus; i++) {
                 new_frame->localsplus[i] = NULL;
             }
             STACK_SHRINK(call_shape.postcall_shrink);
@@ -4768,15 +4792,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_TYPE_1) {
-            assert(call_shape.positional_args = 1);
-            assert(GET_CACHE()->adaptive.original_oparg == 0);
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            assert(call_shape.kwnames == NULL);
             PyObject *obj = TOP();
             PyObject *callable = SECOND();
             DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL);
             PyObject *res = Py_NewRef(Py_TYPE(obj));
-            STACK_SHRINK(1);
             Py_DECREF(callable);
             Py_DECREF(obj);
+            STACK_SHRINK(call_shape.postcall_shrink);
             SET_TOP(res);
             DISPATCH();
         }
@@ -4784,17 +4808,18 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_BUILTIN_CLASS_1) {
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            assert(cache0->original_oparg == 1);
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            assert(call_shape.kwnames == NULL);
             PyObject *callable = SECOND();
             PyObject *arg = TOP();
             DEOPT_IF(!PyType_Check(callable), CALL);
             PyTypeObject *tp = (PyTypeObject *)callable;
             DEOPT_IF(tp->tp_version_tag != cache0->version, CALL);
-            STACK_SHRINK(1);
-            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer, 1, NULL);
-            SET_TOP(res);
+            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer-1, 1, NULL);
             Py_DECREF(tp);
             Py_DECREF(arg);
+            STACK_SHRINK(call_shape.postcall_shrink);
+            SET_TOP(res);
             if (res == NULL) {
                 goto error;
             }
@@ -4861,6 +4886,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             }
             STACK_SHRINK(call_shape.postcall_shrink);
             PUSH(res);
+            Py_DECREF(callable);
             if (res == NULL) {
                 /* Not deopting because this doesn't mean our optimization was
                    wrong. `res` can be NULL for valid reasons. Eg. getattr(x,
@@ -4905,6 +4931,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_ISINSTANCE) {
             assert(cframe.use_tracing == 0);
+            assert(call_shape.kwnames == NULL);
             /* isinstance(o, o2) */
             SpecializedCacheEntry *caches = GET_CACHE();
             assert(caches[0].adaptive.original_oparg == 0);
@@ -4935,10 +4962,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_LIST_APPEND) {
-            assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
-            assert(GET_CACHE()->adaptive.original_oparg == 1);
-            DEOPT_IF(call_shape.positional_args == oparg, CALL);
-            assert(call_shape.positional_args == oparg+1);
+            assert(call_shape.kwnames == NULL);
+            SpecializedCacheEntry *caches = GET_CACHE();
+            _PyObjectCache *cache1 = &caches[-1].obj;
+            DEOPT_IF(call_shape.positional_args != 2, CALL);
+            DEOPT_IF(call_shape.callable != cache1->obj, CALL);
             PyObject *list = SECOND();
             DEOPT_IF(!PyList_CheckExact(list), CALL);
             STAT_INC(CALL, hit);
@@ -4947,40 +4975,38 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             if (err) {
                 goto error;
             }
-            PyObject *callable = THIRD();
             Py_DECREF(arg);
             Py_DECREF(list);
+            STACK_SHRINK(call_shape.postcall_shrink+1);
             Py_INCREF(Py_None);
-            STACK_SHRINK(2);
             SET_TOP(Py_None);
-            Py_DECREF(callable);
+            Py_DECREF(call_shape.callable);
             DISPATCH();
         }
 
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
-            assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
-            assert(GET_CACHE()->adaptive.original_oparg == 1);
-            DEOPT_IF(call_shape.positional_args == oparg, CALL);
-            assert(call_shape.positional_args == oparg+1);
-            PyObject *callable = THIRD();
-            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
-            DEOPT_IF(((PyMethodDescrObject *)callable)->d_method->ml_flags != METH_O, CALL);
-            STAT_INC(CALL_NO_KW, hit);
-            PyCFunction cfunc = ((PyMethodDescrObject *)callable)->d_method->ml_meth;
+            assert(call_shape.kwnames == NULL);
+            DEOPT_IF(call_shape.positional_args != 2, CALL);
+            DEOPT_IF(!Py_IS_TYPE(call_shape.callable, &PyMethodDescr_Type), CALL);
+            PyMethodDef *meth = ((PyMethodDescrObject *)call_shape.callable)->d_method;
+            DEOPT_IF(meth->ml_flags != METH_O, CALL);
+            STAT_INC(CALL, hit);
+            PyCFunction cfunc = meth->ml_meth;
             // This is slower but CPython promises to check all non-vectorcall
             // function calls.
             if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
                 goto error;
             }
-            PyObject *arg = POP();
-            PyObject *self = POP();
+            PyObject *arg = TOP();
+            PyObject *self = SECOND();
             PyObject *res = cfunc(self, arg);
             _Py_LeaveRecursiveCall(tstate);
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
             Py_DECREF(self);
             Py_DECREF(arg);
+            STACK_SHRINK(call_shape.postcall_shrink+1);
             SET_TOP(res);
-            Py_DECREF(callable);
+            Py_DECREF(call_shape.callable);
             if (res == NULL) {
                 goto error;
             }
@@ -4988,29 +5014,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
-            assert(_Py_OPCODE(next_instr[-2]) == PRECALL_METHOD);
+            assert(call_shape.kwnames == NULL);
             /* Builtin METH_FASTCALL methods, without keywords */
-            SpecializedCacheEntry *caches = GET_CACHE();
-            _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            DEOPT_IF(call_shape.positional_args == oparg, CALL);
-            assert(call_shape.positional_args == oparg+1);
-            int nargs = cache0->original_oparg;
-            PyObject *callable = PEEK(nargs + 2);
-            DEOPT_IF(!Py_IS_TYPE(callable, &PyMethodDescr_Type), CALL);
-            PyMethodDef *meth = ((PyMethodDescrObject *)callable)->d_method;
+            DEOPT_IF(!Py_IS_TYPE(call_shape.callable, &PyMethodDescr_Type), CALL);
+            PyMethodDef *meth = ((PyMethodDescrObject *)call_shape.callable)->d_method;
             DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
             STAT_INC(CALL, hit);
             _PyCFunctionFast cfunc = (_PyCFunctionFast)(void(*)(void))meth->ml_meth;
-            PyObject *self = PEEK(nargs+1);
-            PyObject *res = cfunc(self, &PEEK(nargs), nargs);
+            int nargs = call_shape.positional_args-1;
+            STACK_SHRINK(nargs);
+            PyObject *self = TOP();
+            PyObject *res = cfunc(self, stack_pointer, nargs);
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
             /* Clear the stack of the arguments. */
-            STACK_SHRINK(nargs+1);
-            for (int i = 0; i <= nargs; i++) {
+            for (int i = 0; i < nargs; i++) {
                 Py_DECREF(stack_pointer[i]);
             }
+            Py_DECREF(self);
+            STACK_SHRINK(call_shape.postcall_shrink);
             SET_TOP(res);
-            Py_DECREF(callable);
+            Py_DECREF(call_shape.callable);
             if (res == NULL) {
                 goto error;
             }
diff --git a/Python/frame.c b/Python/frame.c
index da2c1c4aec075e..a3e94eada44d45 100644
--- a/Python/frame.c
+++ b/Python/frame.c
@@ -91,7 +91,7 @@ take_ownership(PyFrameObject *f, InterpreterFrame *frame)
 }
 
 void
-_PyFrame_Clear(InterpreterFrame * frame)
+_PyFrame_Clear(InterpreterFrame *frame)
 {
     /* It is the responsibility of the owning generator/coroutine
      * to have cleared the generator pointer */
@@ -112,3 +112,16 @@ _PyFrame_Clear(InterpreterFrame * frame)
     }
     clear_specials(frame);
 }
+
+InterpreterFrame *
+_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func)
+{
+    PyCodeObject *code = (PyCodeObject *)func->func_code;
+    size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE;
+    InterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size);
+    if (new_frame == NULL) {
+        return NULL;
+    }
+    _PyFrame_InitializeSpecials(new_frame, func, NULL, code->co_nlocalsplus);
+    return new_frame;
+}
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 7af828aaad66c9..5cb6a95f39aaf5 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -43,50 +43,50 @@ static void *opcode_targets[256] = {
     &&TARGET_CALL_NO_KW_BUILTIN_FAST,
     &&TARGET_CALL_NO_KW_LEN,
     &&TARGET_CALL_NO_KW_ISINSTANCE,
-    &&TARGET_CALL_NO_KW_PY_SIMPLE,
+    &&TARGET_CALL_PY_EXACT_ARGS,
+    &&TARGET_CALL_PY_WITH_DEFAULTS,
     &&TARGET_CALL_NO_KW_LIST_APPEND,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
     &&TARGET_CALL_NO_KW_TYPE_1,
-    &&TARGET_CALL_NO_KW_BUILTIN_CLASS_1,
     &&TARGET_WITH_EXCEPT_START,
     &&TARGET_GET_AITER,
     &&TARGET_GET_ANEXT,
     &&TARGET_BEFORE_ASYNC_WITH,
     &&TARGET_BEFORE_WITH,
     &&TARGET_END_ASYNC_FOR,
+    &&TARGET_CALL_NO_KW_BUILTIN_CLASS_1,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
     &&TARGET_JUMP_ABSOLUTE_QUICK,
     &&TARGET_LOAD_ATTR_ADAPTIVE,
     &&TARGET_LOAD_ATTR_INSTANCE_VALUE,
-    &&TARGET_LOAD_ATTR_WITH_HINT,
     &&TARGET_STORE_SUBSCR,
     &&TARGET_DELETE_SUBSCR,
+    &&TARGET_LOAD_ATTR_WITH_HINT,
     &&TARGET_LOAD_ATTR_SLOT,
     &&TARGET_LOAD_ATTR_MODULE,
     &&TARGET_LOAD_GLOBAL_ADAPTIVE,
     &&TARGET_LOAD_GLOBAL_MODULE,
     &&TARGET_LOAD_GLOBAL_BUILTIN,
-    &&TARGET_LOAD_METHOD_ADAPTIVE,
     &&TARGET_GET_ITER,
     &&TARGET_GET_YIELD_FROM_ITER,
     &&TARGET_PRINT_EXPR,
     &&TARGET_LOAD_BUILD_CLASS,
-    &&TARGET_LOAD_METHOD_CACHED,
+    &&TARGET_LOAD_METHOD_ADAPTIVE,
     &&TARGET_GET_AWAITABLE,
     &&TARGET_LOAD_ASSERTION_ERROR,
+    &&TARGET_LOAD_METHOD_CACHED,
     &&TARGET_LOAD_METHOD_CLASS,
     &&TARGET_LOAD_METHOD_MODULE,
     &&TARGET_LOAD_METHOD_NO_DICT,
     &&TARGET_STORE_ATTR_ADAPTIVE,
     &&TARGET_STORE_ATTR_INSTANCE_VALUE,
     &&TARGET_STORE_ATTR_SLOT,
-    &&TARGET_STORE_ATTR_WITH_HINT,
     &&TARGET_LIST_TO_TUPLE,
     &&TARGET_RETURN_VALUE,
     &&TARGET_IMPORT_STAR,
     &&TARGET_SETUP_ANNOTATIONS,
     &&TARGET_YIELD_VALUE,
-    &&TARGET_LOAD_FAST__LOAD_FAST,
+    &&TARGET_STORE_ATTR_WITH_HINT,
     &&TARGET_PREP_RERAISE_STAR,
     &&TARGET_POP_EXCEPT,
     &&TARGET_STORE_NAME,
@@ -130,19 +130,19 @@ static void *opcode_targets[256] = {
     &&TARGET_POP_JUMP_IF_NOT_NONE,
     &&TARGET_POP_JUMP_IF_NONE,
     &&TARGET_RAISE_VARARGS,
-    &&TARGET_STORE_FAST__LOAD_FAST,
+    &&TARGET_LOAD_FAST__LOAD_FAST,
     &&TARGET_MAKE_FUNCTION,
     &&TARGET_BUILD_SLICE,
-    &&TARGET_LOAD_FAST__LOAD_CONST,
+    &&TARGET_STORE_FAST__LOAD_FAST,
     &&TARGET_MAKE_CELL,
     &&TARGET_LOAD_CLOSURE,
     &&TARGET_LOAD_DEREF,
     &&TARGET_STORE_DEREF,
     &&TARGET_DELETE_DEREF,
+    &&TARGET_LOAD_FAST__LOAD_CONST,
     &&TARGET_LOAD_CONST__LOAD_FAST,
-    &&TARGET_STORE_FAST__STORE_FAST,
     &&TARGET_CALL_FUNCTION_EX,
-    &&_unknown_opcode,
+    &&TARGET_STORE_FAST__STORE_FAST,
     &&TARGET_EXTENDED_ARG,
     &&TARGET_LIST_APPEND,
     &&TARGET_SET_ADD,
diff --git a/Python/specialize.c b/Python/specialize.c
index 4ed557b335acde..c8a1fd46211ce6 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -124,7 +124,7 @@ _Py_GetSpecializationStats(void) {
     err += add_stat_dict(stats, BINARY_SUBSCR, "binary_subscr");
     err += add_stat_dict(stats, STORE_SUBSCR, "store_subscr");
     err += add_stat_dict(stats, STORE_ATTR, "store_attr");
-    err += add_stat_dict(stats, CALL_NO_KW, "call_no_kw");
+    err += add_stat_dict(stats, CALL, "call");
     err += add_stat_dict(stats, BINARY_OP, "binary_op");
     err += add_stat_dict(stats, COMPARE_OP, "compare_op");
     if (err < 0) {
@@ -1341,16 +1341,20 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins
 static int
 specialize_class_call(
     PyObject *callable, _Py_CODEUNIT *instr,
-    int nargs, SpecializedCacheEntry *cache)
+    int nargs, PyObject *kwnames, SpecializedCacheEntry *cache)
 {
     assert(PyType_Check(callable));
     PyTypeObject *tp = (PyTypeObject *)callable;
+    if (kwnames) {
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
+        return -1;
+    }
     if (_Py_OPCODE(instr[-1]) == PRECALL_METHOD) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_METHOD_CALL_CLASS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_METHOD_CALL_CLASS);
         return -1;
     }
     if (tp->tp_new == PyBaseObject_Type.tp_new) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_PYTHON_CLASS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_PYTHON_CLASS);
         return -1;
     }
     if (nargs == 1) {
@@ -1364,7 +1368,7 @@ specialize_class_call(
             return 0;
         }
     }
-    SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_CLASS);
+    SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS);
     return -1;
 }
 
@@ -1374,18 +1378,19 @@ _Py_IDENTIFIER(append);
 static int
 specialize_method_descriptor(
     PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
-    int nargs, SpecializedCacheEntry *cache)
+    int nargs, PyObject *kwnames, SpecializedCacheEntry *cache)
 {
-    int oparg = cache->adaptive.original_oparg;
-    if (nargs - oparg != 1) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_METHDESCR_NON_METHOD);
+    if (kwnames) {
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
         return -1;
     }
     if (_list_append == NULL) {
         _list_append = (PyMethodDescrObject *)_PyType_LookupId(&PyList_Type, &PyId_append);
     }
-    if (oparg == 1 && descr == _list_append) {
+    assert(_list_append != NULL);
+    if (nargs == 2 && descr == _list_append) {
         assert(_Py_OPCODE(instr[-1]) == PRECALL_METHOD);
+        cache[-1].obj.obj = (PyObject *)_list_append;
         *instr = _Py_MAKECODEUNIT(CALL_NO_KW_LIST_APPEND, _Py_OPARG(*instr));
         return 0;
     }
@@ -1394,8 +1399,8 @@ specialize_method_descriptor(
         (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
         METH_KEYWORDS | METH_METHOD)) {
         case METH_O: {
-            if (oparg != 1) {
-                SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_OUT_OF_RANGE);
+            if (nargs != 1) {
+                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_RANGE);
                 return 1;
             }
             *instr = _Py_MAKECODEUNIT(CALL_NO_KW_METHOD_DESCRIPTOR_O,
@@ -1408,53 +1413,60 @@ specialize_method_descriptor(
             return 0;
         }
     }
-    SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_OTHER);
+    SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OTHER);
     return -1;
 }
 
 static int
 specialize_py_call(
     PyFunctionObject *func, _Py_CODEUNIT *instr,
-    int nargs, SpecializedCacheEntry *cache)
+    int nargs, PyObject *kwnames, SpecializedCacheEntry *cache)
 {
     _PyCallCache *cache1 = &cache[-1].call;
     PyCodeObject *code = (PyCodeObject *)func->func_code;
     int kind = function_kind(code);
+    if (kwnames) {
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
+        return -1;
+    }
     if (kind != SIMPLE_FUNCTION) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, kind);
+        SPECIALIZATION_FAIL(CALL, kind);
         return -1;
     }
     int argcount = code->co_argcount;
     if (argcount > 0xffff) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_OUT_OF_RANGE);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_RANGE);
         return -1;
     }
     int defcount = func->func_defaults == NULL ? 0 : (int)PyTuple_GET_SIZE(func->func_defaults);
     assert(defcount <= argcount);
     int min_args = argcount-defcount;
     if (nargs > argcount || nargs < min_args) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
         return -1;
     }
     assert(nargs <= argcount && nargs >= min_args);
-    int defstart = nargs - min_args;
-    int deflen = argcount - nargs;
-    assert(defstart >= 0 && deflen >= 0);
-    assert(deflen == 0 || func->func_defaults != NULL);
-    if (defstart > 0xffff || deflen > 0xffff) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_OUT_OF_RANGE);
+    assert(min_args >= 0 && defcount >= 0);
+    assert(defcount == 0 || func->func_defaults != NULL);
+    if (min_args > 0xffff || defcount > 0xffff) {
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_RANGE);
         return -1;
     }
     int version = _PyFunction_GetVersionForCurrentState(func);
     if (version == 0) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_OUT_OF_VERSIONS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_VERSIONS);
         return -1;
     }
     cache[0].adaptive.index = nargs;
     cache1->func_version = version;
-    cache1->defaults_start = defstart;
-    cache1->defaults_len = deflen;
-    *instr = _Py_MAKECODEUNIT(CALL_NO_KW_PY_SIMPLE, _Py_OPARG(*instr));
+    cache1->min_args = min_args;
+    cache1->defaults_len = defcount;
+    if (argcount == nargs) {
+        *instr = _Py_MAKECODEUNIT(CALL_PY_EXACT_ARGS, _Py_OPARG(*instr));
+    }
+    else {
+        *instr = _Py_MAKECODEUNIT(CALL_PY_WITH_DEFAULTS, _Py_OPARG(*instr));
+    }
     return 0;
 }
 
@@ -1484,11 +1496,11 @@ builtin_call_fail_kind(int ml_flags)
 
 static int
 specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
-    SpecializedCacheEntry *cache, PyObject *builtins)
+    PyObject *kwnames, SpecializedCacheEntry *cache, PyObject *builtins)
 {
     _PyObjectCache *cache1 = &cache[-1].obj;
-    if (_Py_OPCODE(instr[-1]) == KW_NAMES) {
-        SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_COMPLEX_PARAMETERS);
+    if (kwnames) {
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
         return -1;
     }
     if (PyCFunction_GET_FUNCTION(callable) == NULL) {
@@ -1499,7 +1511,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
         METH_KEYWORDS | METH_METHOD)) {
         case METH_O: {
             if (nargs != 1) {
-                SPECIALIZATION_FAIL(CALL_NO_KW, SPEC_FAIL_OUT_OF_RANGE);
+                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_RANGE);
                 return 1;
             }
             /* len(o) */
@@ -1531,7 +1543,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
             return 0;
         }
         default:
-            SPECIALIZATION_FAIL(CALL_NO_KW,
+            SPECIALIZATION_FAIL(CALL,
                 builtin_call_fail_kind(PyCFunction_GET_FLAGS(callable)));
             return 1;
     }
@@ -1564,38 +1576,35 @@ call_fail_kind(PyObject *callable)
 int
 _Py_Specialize_CallNoKw(
     PyObject *callable, _Py_CODEUNIT *instr,
-    int nargs, SpecializedCacheEntry *cache,
-    PyObject *builtins)
+    int nargs, PyObject *kwnames,
+    SpecializedCacheEntry *cache, PyObject *builtins)
 {
+    _PyAdaptiveEntry *cache0 = &cache->adaptive;
     int fail;
     if (PyCFunction_CheckExact(callable)) {
-        fail = specialize_c_call(callable, instr, nargs, cache, builtins);
+        fail = specialize_c_call(callable, instr, nargs, kwnames, cache, builtins);
+    }
+    else if (PyFunction_Check(callable)) {
+        fail = specialize_py_call((PyFunctionObject *)callable, instr, nargs, kwnames, cache);
+    }
+    else if (PyType_Check(callable)) {
+        fail = specialize_class_call(callable, instr, nargs, kwnames, cache);
+    }
+    else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
+        fail = specialize_method_descriptor(
+            (PyMethodDescrObject *)callable, instr, nargs, kwnames, cache);
     }
     else {
+        SPECIALIZATION_FAIL(CALL, call_fail_kind(callable));
         fail = -1;
     }
-//     else if (PyFunction_Check(callable)) {
-//         fail = specialize_py_call((PyFunctionObject *)callable, instr, nargs, cache);
-//     }
-//     else if (PyType_Check(callable)) {
-//         fail = specialize_class_call(callable, instr, nargs, cache);
-//     }
-//     else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
-//         fail = specialize_method_descriptor(
-//             (PyMethodDescrObject *)callable, instr, nargs, cache);
-//     }
-//     else {
-//         SPECIALIZATION_FAIL(CALL_NO_KW, call_fail_kind(callable));
-//         fail = -1;
-//     }
-    _PyAdaptiveEntry *cache0 = &cache->adaptive;
     if (fail) {
-        STAT_INC(CALL_NO_KW, failure);
+        STAT_INC(CALL, failure);
         assert(!PyErr_Occurred());
         cache_backoff(cache0);
     }
     else {
-        STAT_INC(CALL_NO_KW, success);
+        STAT_INC(CALL, success);
         assert(!PyErr_Occurred());
         cache0->counter = initial_counter_value();
     }

From 6785a3b55499809f45212a30f59197844dd9ba45 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Tue, 11 Jan 2022 15:55:05 +0000
Subject: [PATCH 09/34] Fix test_dis

---
 Lib/test/test_dis.py | 405 +++++++++++++++++++++++--------------------
 1 file changed, 216 insertions(+), 189 deletions(-)

diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index c4473a4c261ad0..66112acd7577de 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -104,11 +104,12 @@ def _f(a):
 
 %3d           2 LOAD_GLOBAL              0 (print)
               4 LOAD_FAST                0 (a)
-              6 CALL_NO_KW               1
-              8 POP_TOP
+              6 PRECALL_FUNCTION         1
+              8 CALL                     0
+             10 POP_TOP
 
-%3d          10 LOAD_CONST               1 (1)
-             12 RETURN_VALUE
+%3d          12 LOAD_CONST               1 (1)
+             14 RETURN_VALUE
 """ % (_f.__code__.co_firstlineno,
        _f.__code__.co_firstlineno + 1,
        _f.__code__.co_firstlineno + 2)
@@ -118,10 +119,11 @@ def _f(a):
           0 RESUME                   0
           2 LOAD_GLOBAL              0
           4 LOAD_FAST                0
-          6 CALL_NO_KW               1
-          8 POP_TOP
-         10 LOAD_CONST               1
-         12 RETURN_VALUE
+          6 PRECALL_FUNCTION         1
+          8 CALL                     0
+         10 POP_TOP
+         12 LOAD_CONST               1
+         14 RETURN_VALUE
 """
 
 
@@ -138,15 +140,16 @@ def bug708901():
 
 %3d           6 LOAD_CONST               2 (10)
 
-%3d           8 CALL_NO_KW               2
-             10 GET_ITER
-        >>   12 FOR_ITER                 2 (to 18)
-             14 STORE_FAST               0 (res)
+%3d           8 PRECALL_FUNCTION         2
+             10 CALL                     0
+             12 GET_ITER
+        >>   14 FOR_ITER                 2 (to 20)
+             16 STORE_FAST               0 (res)
 
-%3d          16 JUMP_ABSOLUTE            6 (to 12)
+%3d          18 JUMP_ABSOLUTE            7 (to 14)
 
-%3d     >>   18 LOAD_CONST               0 (None)
-             20 RETURN_VALUE
+%3d     >>   20 LOAD_CONST               0 (None)
+             22 RETURN_VALUE
 """ % (bug708901.__code__.co_firstlineno,
        bug708901.__code__.co_firstlineno + 1,
        bug708901.__code__.co_firstlineno + 2,
@@ -168,13 +171,15 @@ def bug1333982(x=[]):
               6 MAKE_FUNCTION            0
               8 LOAD_FAST                0 (x)
              10 GET_ITER
-             12 CALL_NO_KW               1
+             12 PRECALL_FUNCTION         1
+             14 CALL                     0
 
-%3d          14 LOAD_CONST               3 (1)
+%3d          16 LOAD_CONST               3 (1)
 
-%3d          16 BINARY_OP                0 (+)
-             18 CALL_NO_KW               1
-             20 RAISE_VARARGS            1
+%3d          18 BINARY_OP                0 (+)
+             20 PRECALL_FUNCTION         1
+             22 CALL                     0
+             24 RAISE_VARARGS            1
 """ % (bug1333982.__code__.co_firstlineno,
        bug1333982.__code__.co_firstlineno + 1,
        __file__,
@@ -290,21 +295,23 @@ def bug42562():
 
   3          16 LOAD_NAME                3 (fun)
              18 LOAD_CONST               0 (1)
-             20 CALL_NO_KW               1
-             22 LOAD_NAME                2 (__annotations__)
-             24 LOAD_CONST               2 ('y')
-             26 STORE_SUBSCR
-
-  4          28 LOAD_CONST               0 (1)
-             30 LOAD_NAME                4 (lst)
-             32 LOAD_NAME                3 (fun)
-             34 LOAD_CONST               3 (0)
-             36 CALL_NO_KW               1
-             38 STORE_SUBSCR
-             40 LOAD_NAME                1 (int)
-             42 POP_TOP
-             44 LOAD_CONST               4 (None)
-             46 RETURN_VALUE
+             20 PRECALL_FUNCTION         1
+             22 CALL                     0
+             24 LOAD_NAME                2 (__annotations__)
+             26 LOAD_CONST               2 ('y')
+             28 STORE_SUBSCR
+
+  4          30 LOAD_CONST               0 (1)
+             32 LOAD_NAME                4 (lst)
+             34 LOAD_NAME                3 (fun)
+             36 LOAD_CONST               3 (0)
+             38 PRECALL_FUNCTION         1
+             40 CALL                     0
+             42 STORE_SUBSCR
+             44 LOAD_NAME                1 (int)
+             46 POP_TOP
+             48 LOAD_CONST               4 (None)
+             50 RETURN_VALUE
 """
 
 compound_stmt_str = """\
@@ -423,20 +430,22 @@ def _tryfinallyconst(b):
 %3d           4 LOAD_FAST                0 (a)
 
 %3d           6 LOAD_FAST                1 (b)
-              8 CALL_NO_KW               0
-             10 POP_TOP
-             12 RETURN_VALUE
-        >>   14 PUSH_EXC_INFO
-             16 LOAD_FAST                1 (b)
-             18 CALL_NO_KW               0
-             20 POP_TOP
-             22 RERAISE                  0
-        >>   24 COPY                     3
-             26 POP_EXCEPT
-             28 RERAISE                  1
+              8 PRECALL_FUNCTION         0
+             10 CALL                     0
+             12 POP_TOP
+             14 RETURN_VALUE
+        >>   16 PUSH_EXC_INFO
+             18 LOAD_FAST                1 (b)
+             20 PRECALL_FUNCTION         0
+             22 CALL                     0
+             24 POP_TOP
+             26 RERAISE                  0
+        >>   28 COPY                     3
+             30 POP_EXCEPT
+             32 RERAISE                  1
 ExceptionTable:
-  4 to 4 -> 14 [0]
-  14 to 22 -> 24 [1] lasti
+  4 to 4 -> 16 [0]
+  16 to 26 -> 28 [1] lasti
 """ % (_tryfinally.__code__.co_firstlineno,
        _tryfinally.__code__.co_firstlineno + 1,
        _tryfinally.__code__.co_firstlineno + 2,
@@ -451,20 +460,22 @@ def _tryfinallyconst(b):
 %3d           4 NOP
 
 %3d           6 LOAD_FAST                0 (b)
-              8 CALL_NO_KW               0
-             10 POP_TOP
-             12 LOAD_CONST               1 (1)
-             14 RETURN_VALUE
-             16 PUSH_EXC_INFO
-             18 LOAD_FAST                0 (b)
-             20 CALL_NO_KW               0
-             22 POP_TOP
-             24 RERAISE                  0
-        >>   26 COPY                     3
-             28 POP_EXCEPT
-             30 RERAISE                  1
+              8 PRECALL_FUNCTION         0
+             10 CALL                     0
+             12 POP_TOP
+             14 LOAD_CONST               1 (1)
+             16 RETURN_VALUE
+             18 PUSH_EXC_INFO
+             20 LOAD_FAST                0 (b)
+             22 PRECALL_FUNCTION         0
+             24 CALL                     0
+             26 POP_TOP
+             28 RERAISE                  0
+        >>   30 COPY                     3
+             32 POP_EXCEPT
+             34 RERAISE                  1
 ExceptionTable:
-  16 to 24 -> 26 [1] lasti
+  18 to 28 -> 30 [1] lasti
 """ % (_tryfinallyconst.__code__.co_firstlineno,
        _tryfinallyconst.__code__.co_firstlineno + 1,
        _tryfinallyconst.__code__.co_firstlineno + 2,
@@ -520,8 +531,9 @@ def foo(x):
              12 MAKE_FUNCTION            8 (closure)
              14 LOAD_DEREF               1 (y)
              16 GET_ITER
-             18 CALL_NO_KW               1
-             20 RETURN_VALUE
+             18 PRECALL_FUNCTION         1
+             20 CALL                     0
+             22 RETURN_VALUE
 """ % (dis_nested_0,
        __file__,
        _h.__code__.co_firstlineno + 1,
@@ -1066,10 +1078,11 @@ def _prepare_test_cases():
   Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=30, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offset=32, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Hello world!', argrepr="'Hello world!'", offset=34, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=7, argval=7, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=40, starts_line=8, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=42, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=7, argval=7, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=42, starts_line=8, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=44, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 expected_opinfo_f = [
@@ -1091,10 +1104,11 @@ def _prepare_test_cases():
   Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=30, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=32, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=34, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=4, argval=4, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=40, starts_line=6, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=42, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=4, argval=4, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=42, starts_line=6, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=44, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 expected_opinfo_inner = [
@@ -1107,132 +1121,144 @@ def _prepare_test_cases():
   Instruction(opname='LOAD_DEREF', opcode=137, arg=5, argval='d', argrepr='d', offset=12, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', offset=14, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', offset=16, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=6, argval=6, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=22, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=24, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=6, argval=6, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=22, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=24, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=26, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 expected_opinfo_jumpy = [
   Instruction(opname='RESUME', opcode=151, arg=0, argval=0, argrepr='', offset=0, starts_line=1, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='range', argrepr='range', offset=2, starts_line=3, is_jump_target=False, positions=None),
   Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=10, argrepr='10', offset=4, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=6, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='GET_ITER', opcode=68, arg=None, argval=None, argrepr='', offset=8, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='FOR_ITER', opcode=93, arg=17, argval=46, argrepr='to 46', offset=10, starts_line=None, is_jump_target=True, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=12, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=14, starts_line=4, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=16, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=18, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=22, starts_line=5, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=24, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=26, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=16, argval=32, argrepr='to 32', offset=28, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=5, argval=10, argrepr='to 10', offset=30, starts_line=6, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=32, starts_line=7, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=34, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=36, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=22, argval=44, argrepr='to 44', offset=38, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=40, starts_line=8, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=5, argval=54, argrepr='to 54', offset=42, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=5, argval=10, argrepr='to 10', offset=44, starts_line=7, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=46, starts_line=10, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=48, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=50, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=52, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=54, starts_line=11, is_jump_target=True, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=49, argval=98, argrepr='to 98', offset=56, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=58, starts_line=12, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=60, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=62, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=64, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=66, starts_line=13, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=68, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='BINARY_OP', opcode=122, arg=23, argval=23, argrepr='-=', offset=70, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=72, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=74, starts_line=14, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=76, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=78, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=42, argval=84, argrepr='to 84', offset=80, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=27, argval=54, argrepr='to 54', offset=82, starts_line=15, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=84, starts_line=16, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=86, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=88, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=47, argval=94, argrepr='to 94', offset=90, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=6, argval=106, argrepr='to 106', offset=92, starts_line=17, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=94, starts_line=11, is_jump_target=True, positions=None),
-  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=29, argval=58, argrepr='to 58', offset=96, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=98, starts_line=19, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=100, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=102, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=104, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=106, starts_line=20, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=108, starts_line=21, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=110, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='BINARY_OP', opcode=122, arg=11, argval=11, argrepr='/', offset=112, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=6, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=8, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='GET_ITER', opcode=68, arg=None, argval=None, argrepr='', offset=10, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='FOR_ITER', opcode=93, arg=18, argval=50, argrepr='to 50', offset=12, starts_line=None, is_jump_target=True, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=14, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=16, starts_line=4, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=18, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=20, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=22, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=24, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=26, starts_line=5, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=28, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=30, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=18, argval=36, argrepr='to 36', offset=32, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=6, argval=12, argrepr='to 12', offset=34, starts_line=6, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=36, starts_line=7, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=38, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=40, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=24, argval=48, argrepr='to 48', offset=42, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=44, starts_line=8, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=6, argval=60, argrepr='to 60', offset=46, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=6, argval=12, argrepr='to 12', offset=48, starts_line=7, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=50, starts_line=10, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=52, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=54, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=56, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=58, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=60, starts_line=11, is_jump_target=True, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=53, argval=106, argrepr='to 106', offset=62, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=64, starts_line=12, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=66, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=68, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=70, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=72, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=74, starts_line=13, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=76, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='BINARY_OP', opcode=122, arg=23, argval=23, argrepr='-=', offset=78, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=80, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=82, starts_line=14, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=84, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=86, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=46, argval=92, argrepr='to 92', offset=88, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=30, argval=60, argrepr='to 60', offset=90, starts_line=15, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=92, starts_line=16, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=94, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=96, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=51, argval=102, argrepr='to 102', offset=98, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=7, argval=116, argrepr='to 116', offset=100, starts_line=17, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=102, starts_line=11, is_jump_target=True, positions=None),
+  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=32, argval=64, argrepr='to 64', offset=104, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=106, starts_line=19, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=108, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=110, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=112, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=114, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=14, argval=146, argrepr='to 146', offset=116, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=118, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=120, starts_line=22, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=69, argval=138, argrepr='to 138', offset=122, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=116, starts_line=20, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=118, starts_line=21, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=120, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='BINARY_OP', opcode=122, arg=11, argval=11, argrepr='/', offset=122, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=124, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=126, starts_line=23, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=128, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=130, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=132, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=134, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=34, argval=206, argrepr='to 206', offset=136, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=138, starts_line=22, is_jump_target=True, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=144, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=146, starts_line=25, is_jump_target=True, positions=None),
-  Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=148, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=150, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=152, starts_line=26, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=154, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=160, starts_line=25, is_jump_target=False, positions=None),
-  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=164, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=3, argval=3, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=194, argrepr='to 194', offset=170, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=174, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=93, argval=186, argrepr='to 186', offset=176, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=178, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=184, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=True, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=192, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=194, starts_line=28, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=196, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=198, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=200, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=202, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=206, starts_line=23, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=208, starts_line=28, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=210, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=212, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=214, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=216, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=220, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=222, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=224, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=226, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=228, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=236, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=15, argval=158, argrepr='to 158', offset=126, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=128, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=130, starts_line=22, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=75, argval=150, argrepr='to 150', offset=132, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=134, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=136, starts_line=23, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=138, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=144, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=146, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=37, argval=224, argrepr='to 224', offset=148, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=150, starts_line=22, is_jump_target=True, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=152, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=154, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=158, starts_line=25, is_jump_target=True, positions=None),
+  Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=160, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=162, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=164, starts_line=26, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=166, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=170, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=174, starts_line=25, is_jump_target=False, positions=None),
+  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=176, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=178, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=3, argval=3, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=210, argrepr='to 210', offset=186, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=101, argval=202, argrepr='to 202', offset=192, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=194, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=196, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=198, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=200, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=202, starts_line=None, is_jump_target=True, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=206, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=208, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=210, starts_line=28, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=212, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=214, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=220, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=222, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=224, starts_line=23, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=226, starts_line=28, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=228, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=236, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=238, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=240, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=242, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=244, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=246, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=248, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=250, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=252, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=254, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=256, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=258, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 # One last piece of inspect fodder to check the default line number handling
@@ -1301,6 +1327,7 @@ def test_co_positions(self):
             (1, 3, 0, 1),
             (1, 3, 0, 1),
             (1, 3, 0, 1),
+            (1, 3, 0, 1),
             (1, 3, 0, 1)
         ]
         self.assertEqual(positions, expected)

From 5935a5c38e364859d3a47874fc7d966095e8e3d0 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Tue, 11 Jan 2022 16:02:07 +0000
Subject: [PATCH 10/34] Fix a couple of compiler warnings.

---
 Python/ceval.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 11e875bb777452..b5f71c4dd28780 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1681,8 +1681,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     CFrame cframe;
     CallShape call_shape;
     call_shape.kwnames = NULL;
-    call_shape.postcall_shrink = 1;
+    call_shape.postcall_shrink = 0;
     call_shape.positional_args = 0;
+    call_shape.callable = NULL;
 
     /* WARNING: Because the CFrame lives on the C stack,
      * but can be accessed from a heap allocated object (tstate)
@@ -4860,9 +4861,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_BUILTIN_FAST) {
             assert(cframe.use_tracing == 0);
             /* Builtin METH_FASTCALL functions, without keywords */
-            SpecializedCacheEntry *caches = GET_CACHE();
-            _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            assert(cache0->original_oparg == 0);
+            assert(call_shape.kwnames == NULL);
             PyObject *callable = call_shape.callable;
             assert(call_shape.kwnames == NULL);
             int nargs = call_shape.positional_args;

From e39432f60417c08755385c90614bc9264bbaae97 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Wed, 12 Jan 2022 11:07:21 +0000
Subject: [PATCH 11/34] Specialize for calls to builtin types with any number
 of arguments.

---
 Include/opcode.h        |  2 +-
 Lib/opcode.py           |  2 +-
 Python/ceval.c          | 28 +++++++++++++++-------------
 Python/opcode_targets.h |  2 +-
 Python/specialize.c     | 17 +++++++----------
 5 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index c1d4543d12058c..3cb3aeba361b36 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -146,7 +146,7 @@ extern "C" {
 #define CALL_NO_KW_LIST_APPEND           46
 #define CALL_NO_KW_METHOD_DESCRIPTOR_O   47
 #define CALL_NO_KW_TYPE_1                48
-#define CALL_NO_KW_BUILTIN_CLASS_1       55
+#define CALL_NO_KW_BUILTIN_CLASS         55
 #define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  56
 #define JUMP_ABSOLUTE_QUICK              57
 #define LOAD_ATTR_ADAPTIVE               58
diff --git a/Lib/opcode.py b/Lib/opcode.py
index beda06bb6d39db..6dae12e400f857 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -261,7 +261,7 @@ def jabs_op(name, op):
     "CALL_NO_KW_LIST_APPEND",
     "CALL_NO_KW_METHOD_DESCRIPTOR_O",
     "CALL_NO_KW_TYPE_1",
-    "CALL_NO_KW_BUILTIN_CLASS_1",
+    "CALL_NO_KW_BUILTIN_CLASS",
     "CALL_NO_KW_METHOD_DESCRIPTOR_FAST",
     "JUMP_ABSOLUTE_QUICK",
     "LOAD_ATTR_ADAPTIVE",
diff --git a/Python/ceval.c b/Python/ceval.c
index b5f71c4dd28780..aa753bf8b08e7f 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4806,20 +4806,22 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
-        TARGET(CALL_NO_KW_BUILTIN_CLASS_1) {
-            SpecializedCacheEntry *caches = GET_CACHE();
-            _PyAdaptiveEntry *cache0 = &caches[0].adaptive;
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+        TARGET(CALL_NO_KW_BUILTIN_CLASS) {
             assert(call_shape.kwnames == NULL);
-            PyObject *callable = SECOND();
-            PyObject *arg = TOP();
-            DEOPT_IF(!PyType_Check(callable), CALL);
-            PyTypeObject *tp = (PyTypeObject *)callable;
-            DEOPT_IF(tp->tp_version_tag != cache0->version, CALL);
-            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer-1, 1, NULL);
+            DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
+            PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
+            DEOPT_IF(tp->tp_vectorcall == NULL, CALL);
+            STAT_INC(CALL, hit);
+
+            int nargs = call_shape.positional_args;
+            STACK_SHRINK(nargs);
+            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer, nargs, NULL);
+            /* Free the arguments. */
+            for (int i = 0; i < nargs; i++) {
+                Py_DECREF(stack_pointer[i]);
+            }
             Py_DECREF(tp);
-            Py_DECREF(arg);
-            STACK_SHRINK(call_shape.postcall_shrink);
+            STACK_SHRINK(call_shape.postcall_shrink-1);
             SET_TOP(res);
             if (res == NULL) {
                 goto error;
@@ -4864,12 +4866,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(call_shape.kwnames == NULL);
             PyObject *callable = call_shape.callable;
             assert(call_shape.kwnames == NULL);
-            int nargs = call_shape.positional_args;
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_FASTCALL,
                 CALL);
             STAT_INC(CALL, hit);
 
+            int nargs = call_shape.positional_args;
             PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
             STACK_SHRINK(nargs);
             /* res = func(self, args, nargs) */
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 5cb6a95f39aaf5..4bb3eee51c7cde 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -54,7 +54,7 @@ static void *opcode_targets[256] = {
     &&TARGET_BEFORE_ASYNC_WITH,
     &&TARGET_BEFORE_WITH,
     &&TARGET_END_ASYNC_FOR,
-    &&TARGET_CALL_NO_KW_BUILTIN_CLASS_1,
+    &&TARGET_CALL_NO_KW_BUILTIN_CLASS,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
     &&TARGET_JUMP_ABSOLUTE_QUICK,
     &&TARGET_LOAD_ATTR_ADAPTIVE,
diff --git a/Python/specialize.c b/Python/specialize.c
index c8a1fd46211ce6..cc5500eef2a50e 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1357,16 +1357,13 @@ specialize_class_call(
         SPECIALIZATION_FAIL(CALL, SPEC_FAIL_PYTHON_CLASS);
         return -1;
     }
-    if (nargs == 1) {
-        if (tp == &PyType_Type) {
-            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TYPE_1, _Py_OPARG(*instr));
-            return 0;
-        }
-        if ((tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) && tp->tp_vectorcall != NULL) {
-            cache->adaptive.version = tp->tp_version_tag;
-            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_BUILTIN_CLASS_1, _Py_OPARG(*instr));
-            return 0;
-        }
+    if (tp == &PyType_Type && nargs == 1) {
+        *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TYPE_1, _Py_OPARG(*instr));
+        return 0;
+    }
+    if ((tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) && tp->tp_vectorcall != NULL) {
+        *instr = _Py_MAKECODEUNIT(CALL_NO_KW_BUILTIN_CLASS, _Py_OPARG(*instr));
+        return 0;
     }
     SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS);
     return -1;

From 637f5e01dbd73836975f368afb1bd9522484bb12 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Wed, 12 Jan 2022 11:24:45 +0000
Subject: [PATCH 12/34] Refine fail stats for calls to classes.

---
 Python/specialize.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Python/specialize.c b/Python/specialize.c
index cc5500eef2a50e..aa346fe51e1650 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -515,6 +515,8 @@ initial_counter_value(void) {
 #define SPEC_FAIL_C_METHOD_CALL 20
 #define SPEC_FAIL_METHDESCR_NON_METHOD 21
 #define SPEC_FAIL_METHOD_CALL_CLASS 22
+#define SPEC_FAIL_CLASS_NO_VECTORCALL 23
+#define SPEC_FAIL_CLASS_MUTABLE 24
 
 /* COMPARE_OP */
 #define SPEC_FAIL_STRING_COMPARE 13
@@ -1361,11 +1363,15 @@ specialize_class_call(
         *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TYPE_1, _Py_OPARG(*instr));
         return 0;
     }
-    if ((tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) && tp->tp_vectorcall != NULL) {
-        *instr = _Py_MAKECODEUNIT(CALL_NO_KW_BUILTIN_CLASS, _Py_OPARG(*instr));
-        return 0;
+    if (tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {
+        if (tp->tp_vectorcall != NULL) {
+            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_BUILTIN_CLASS, _Py_OPARG(*instr));
+            return 0;
+        }
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS_NO_VECTORCALL);
+        return -1;
     }
-    SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS);
+    SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS_MUTABLE);
     return -1;
 }
 

From 28663f4dd9343d9f053bdf9f9e48b4f3d29d4ee2 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Wed, 12 Jan 2022 11:47:05 +0000
Subject: [PATCH 13/34] Refine fail stats for calls.

---
 Python/specialize.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/Python/specialize.c b/Python/specialize.c
index aa346fe51e1650..14ab2b78ea49a4 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -517,6 +517,9 @@ initial_counter_value(void) {
 #define SPEC_FAIL_METHOD_CALL_CLASS 22
 #define SPEC_FAIL_CLASS_NO_VECTORCALL 23
 #define SPEC_FAIL_CLASS_MUTABLE 24
+#define SPEC_FAIL_KWNAMES 25
+#define SPEC_FAIL_METHOD_WRAPPER 26
+#define SPEC_FAIL_OPERATOR_WRAPPER 27
 
 /* COMPARE_OP */
 #define SPEC_FAIL_STRING_COMPARE 13
@@ -1429,7 +1432,7 @@ specialize_py_call(
     PyCodeObject *code = (PyCodeObject *)func->func_code;
     int kind = function_kind(code);
     if (kwnames) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
         return -1;
     }
     if (kind != SIMPLE_FUNCTION) {
@@ -1503,7 +1506,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
 {
     _PyObjectCache *cache1 = &cache[-1].obj;
     if (kwnames) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
         return -1;
     }
     if (PyCFunction_GET_FUNCTION(callable) == NULL) {
@@ -1514,7 +1517,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
         METH_KEYWORDS | METH_METHOD)) {
         case METH_O: {
             if (nargs != 1) {
-                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_RANGE);
+                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
                 return 1;
             }
             /* len(o) */
@@ -1569,6 +1572,12 @@ call_fail_kind(PyObject *callable)
     else if (PyType_Check(callable)) {
         return  SPEC_FAIL_CLASS;
     }
+    else if (Py_TYPE(callable) == &PyWrapperDescr_Type) {
+        return SPEC_FAIL_OPERATOR_WRAPPER;
+    }
+    else if (Py_TYPE(callable) == &_PyMethodWrapper_Type) {
+        return SPEC_FAIL_METHOD_WRAPPER;
+    }
     return SPEC_FAIL_OTHER;
 }
 #endif

From 0239c26c387adaf7add12ce5a58cefe71a9092eb Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Wed, 12 Jan 2022 16:28:43 +0000
Subject: [PATCH 14/34] Specialize for calls to method-descriptors of the shape
 obj.meth()

---
 Include/opcode.h        | 53 +++++++++++++++++++++--------------------
 Lib/opcode.py           |  1 +
 Python/ceval.c          | 27 +++++++++++++++++++++
 Python/opcode_targets.h | 22 ++++++++---------
 Python/specialize.c     | 13 ++++++++--
 5 files changed, 77 insertions(+), 39 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index 3cb3aeba361b36..7ca6f24c5683f6 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -145,32 +145,33 @@ extern "C" {
 #define CALL_PY_WITH_DEFAULTS            45
 #define CALL_NO_KW_LIST_APPEND           46
 #define CALL_NO_KW_METHOD_DESCRIPTOR_O   47
-#define CALL_NO_KW_TYPE_1                48
-#define CALL_NO_KW_BUILTIN_CLASS         55
-#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  56
-#define JUMP_ABSOLUTE_QUICK              57
-#define LOAD_ATTR_ADAPTIVE               58
-#define LOAD_ATTR_INSTANCE_VALUE         59
-#define LOAD_ATTR_WITH_HINT              62
-#define LOAD_ATTR_SLOT                   63
-#define LOAD_ATTR_MODULE                 64
-#define LOAD_GLOBAL_ADAPTIVE             65
-#define LOAD_GLOBAL_MODULE               66
-#define LOAD_GLOBAL_BUILTIN              67
-#define LOAD_METHOD_ADAPTIVE             72
-#define LOAD_METHOD_CACHED               75
-#define LOAD_METHOD_CLASS                76
-#define LOAD_METHOD_MODULE               77
-#define LOAD_METHOD_NO_DICT              78
-#define STORE_ATTR_ADAPTIVE              79
-#define STORE_ATTR_INSTANCE_VALUE        80
-#define STORE_ATTR_SLOT                  81
-#define STORE_ATTR_WITH_HINT             87
-#define LOAD_FAST__LOAD_FAST            131
-#define STORE_FAST__LOAD_FAST           134
-#define LOAD_FAST__LOAD_CONST           140
-#define LOAD_CONST__LOAD_FAST           141
-#define STORE_FAST__STORE_FAST          143
+#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS  48
+#define CALL_NO_KW_TYPE_1                55
+#define CALL_NO_KW_BUILTIN_CLASS         56
+#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  57
+#define JUMP_ABSOLUTE_QUICK              58
+#define LOAD_ATTR_ADAPTIVE               59
+#define LOAD_ATTR_INSTANCE_VALUE         62
+#define LOAD_ATTR_WITH_HINT              63
+#define LOAD_ATTR_SLOT                   64
+#define LOAD_ATTR_MODULE                 65
+#define LOAD_GLOBAL_ADAPTIVE             66
+#define LOAD_GLOBAL_MODULE               67
+#define LOAD_GLOBAL_BUILTIN              72
+#define LOAD_METHOD_ADAPTIVE             75
+#define LOAD_METHOD_CACHED               76
+#define LOAD_METHOD_CLASS                77
+#define LOAD_METHOD_MODULE               78
+#define LOAD_METHOD_NO_DICT              79
+#define STORE_ATTR_ADAPTIVE              80
+#define STORE_ATTR_INSTANCE_VALUE        81
+#define STORE_ATTR_SLOT                  87
+#define STORE_ATTR_WITH_HINT            131
+#define LOAD_FAST__LOAD_FAST            134
+#define STORE_FAST__LOAD_FAST           140
+#define LOAD_FAST__LOAD_CONST           141
+#define LOAD_CONST__LOAD_FAST           143
+#define STORE_FAST__STORE_FAST          150
 #define DO_TRACING                      255
 #ifdef NEED_OPCODE_JUMP_TABLES
 static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 6dae12e400f857..52fad480c5a800 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -260,6 +260,7 @@ def jabs_op(name, op):
     "CALL_PY_WITH_DEFAULTS",
     "CALL_NO_KW_LIST_APPEND",
     "CALL_NO_KW_METHOD_DESCRIPTOR_O",
+    "CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS",
     "CALL_NO_KW_TYPE_1",
     "CALL_NO_KW_BUILTIN_CLASS",
     "CALL_NO_KW_METHOD_DESCRIPTOR_FAST",
diff --git a/Python/ceval.c b/Python/ceval.c
index aa753bf8b08e7f..7f6857a8dee378 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5014,6 +5014,33 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
+        TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
+            assert(call_shape.kwnames == NULL);
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(!Py_IS_TYPE(call_shape.callable, &PyMethodDescr_Type), CALL);
+            PyMethodDef *meth = ((PyMethodDescrObject *)call_shape.callable)->d_method;
+            DEOPT_IF(meth->ml_flags != METH_NOARGS, CALL);
+            STAT_INC(CALL, hit);
+            PyCFunction cfunc = meth->ml_meth;
+            // This is slower but CPython promises to check all non-vectorcall
+            // function calls.
+            if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
+                goto error;
+            }
+            PyObject *self = TOP();
+            PyObject *res = cfunc(self, NULL);
+            _Py_LeaveRecursiveCall(tstate);
+            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
+            Py_DECREF(self);
+            STACK_SHRINK(call_shape.postcall_shrink);
+            SET_TOP(res);
+            Py_DECREF(call_shape.callable);
+            if (res == NULL) {
+                goto error;
+            }
+            DISPATCH();
+        }
+
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
             assert(call_shape.kwnames == NULL);
             /* Builtin METH_FASTCALL methods, without keywords */
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 4bb3eee51c7cde..7c1b3d63d914de 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -47,46 +47,46 @@ static void *opcode_targets[256] = {
     &&TARGET_CALL_PY_WITH_DEFAULTS,
     &&TARGET_CALL_NO_KW_LIST_APPEND,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
-    &&TARGET_CALL_NO_KW_TYPE_1,
+    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
     &&TARGET_WITH_EXCEPT_START,
     &&TARGET_GET_AITER,
     &&TARGET_GET_ANEXT,
     &&TARGET_BEFORE_ASYNC_WITH,
     &&TARGET_BEFORE_WITH,
     &&TARGET_END_ASYNC_FOR,
+    &&TARGET_CALL_NO_KW_TYPE_1,
     &&TARGET_CALL_NO_KW_BUILTIN_CLASS,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
     &&TARGET_JUMP_ABSOLUTE_QUICK,
     &&TARGET_LOAD_ATTR_ADAPTIVE,
-    &&TARGET_LOAD_ATTR_INSTANCE_VALUE,
     &&TARGET_STORE_SUBSCR,
     &&TARGET_DELETE_SUBSCR,
+    &&TARGET_LOAD_ATTR_INSTANCE_VALUE,
     &&TARGET_LOAD_ATTR_WITH_HINT,
     &&TARGET_LOAD_ATTR_SLOT,
     &&TARGET_LOAD_ATTR_MODULE,
     &&TARGET_LOAD_GLOBAL_ADAPTIVE,
     &&TARGET_LOAD_GLOBAL_MODULE,
-    &&TARGET_LOAD_GLOBAL_BUILTIN,
     &&TARGET_GET_ITER,
     &&TARGET_GET_YIELD_FROM_ITER,
     &&TARGET_PRINT_EXPR,
     &&TARGET_LOAD_BUILD_CLASS,
-    &&TARGET_LOAD_METHOD_ADAPTIVE,
+    &&TARGET_LOAD_GLOBAL_BUILTIN,
     &&TARGET_GET_AWAITABLE,
     &&TARGET_LOAD_ASSERTION_ERROR,
+    &&TARGET_LOAD_METHOD_ADAPTIVE,
     &&TARGET_LOAD_METHOD_CACHED,
     &&TARGET_LOAD_METHOD_CLASS,
     &&TARGET_LOAD_METHOD_MODULE,
     &&TARGET_LOAD_METHOD_NO_DICT,
     &&TARGET_STORE_ATTR_ADAPTIVE,
     &&TARGET_STORE_ATTR_INSTANCE_VALUE,
-    &&TARGET_STORE_ATTR_SLOT,
     &&TARGET_LIST_TO_TUPLE,
     &&TARGET_RETURN_VALUE,
     &&TARGET_IMPORT_STAR,
     &&TARGET_SETUP_ANNOTATIONS,
     &&TARGET_YIELD_VALUE,
-    &&TARGET_STORE_ATTR_WITH_HINT,
+    &&TARGET_STORE_ATTR_SLOT,
     &&TARGET_PREP_RERAISE_STAR,
     &&TARGET_POP_EXCEPT,
     &&TARGET_STORE_NAME,
@@ -130,26 +130,26 @@ static void *opcode_targets[256] = {
     &&TARGET_POP_JUMP_IF_NOT_NONE,
     &&TARGET_POP_JUMP_IF_NONE,
     &&TARGET_RAISE_VARARGS,
-    &&TARGET_LOAD_FAST__LOAD_FAST,
+    &&TARGET_STORE_ATTR_WITH_HINT,
     &&TARGET_MAKE_FUNCTION,
     &&TARGET_BUILD_SLICE,
-    &&TARGET_STORE_FAST__LOAD_FAST,
+    &&TARGET_LOAD_FAST__LOAD_FAST,
     &&TARGET_MAKE_CELL,
     &&TARGET_LOAD_CLOSURE,
     &&TARGET_LOAD_DEREF,
     &&TARGET_STORE_DEREF,
     &&TARGET_DELETE_DEREF,
+    &&TARGET_STORE_FAST__LOAD_FAST,
     &&TARGET_LOAD_FAST__LOAD_CONST,
-    &&TARGET_LOAD_CONST__LOAD_FAST,
     &&TARGET_CALL_FUNCTION_EX,
-    &&TARGET_STORE_FAST__STORE_FAST,
+    &&TARGET_LOAD_CONST__LOAD_FAST,
     &&TARGET_EXTENDED_ARG,
     &&TARGET_LIST_APPEND,
     &&TARGET_SET_ADD,
     &&TARGET_MAP_ADD,
     &&TARGET_LOAD_CLASSDEREF,
     &&TARGET_COPY_FREE_VARS,
-    &&_unknown_opcode,
+    &&TARGET_STORE_FAST__STORE_FAST,
     &&TARGET_RESUME,
     &&TARGET_MATCH_CLASS,
     &&_unknown_opcode,
diff --git a/Python/specialize.c b/Python/specialize.c
index 14ab2b78ea49a4..f6b5cce64e56ff 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1404,10 +1404,19 @@ specialize_method_descriptor(
     switch (descr->d_method->ml_flags &
         (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
         METH_KEYWORDS | METH_METHOD)) {
-        case METH_O: {
+        case METH_NOARGS: {
             if (nargs != 1) {
+                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
+                return -1;
+            }
+            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_METHOD_DESCRIPTOR_O,
+                _Py_OPARG(*instr));
+            return 0;
+        }
+        case METH_O: {
+            if (nargs != 2) {
                 SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OUT_OF_RANGE);
-                return 1;
+                return -1;
             }
             *instr = _Py_MAKECODEUNIT(CALL_NO_KW_METHOD_DESCRIPTOR_O,
                 _Py_OPARG(*instr));

From e07629769fc3befaf6e8de5350339139e336eed4 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Wed, 12 Jan 2022 11:47:05 +0000
Subject: [PATCH 15/34] Refine fail stats for calls.

---
 Python/specialize.c | 58 +++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/Python/specialize.c b/Python/specialize.c
index f6b5cce64e56ff..d8be60119aa5f3 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -520,6 +520,7 @@ initial_counter_value(void) {
 #define SPEC_FAIL_KWNAMES 25
 #define SPEC_FAIL_METHOD_WRAPPER 26
 #define SPEC_FAIL_OPERATOR_WRAPPER 27
+#define SPEC_FAIL_CALL_STR 28
 
 /* COMPARE_OP */
 #define SPEC_FAIL_STRING_COMPARE 13
@@ -1351,7 +1352,7 @@ specialize_class_call(
     assert(PyType_Check(callable));
     PyTypeObject *tp = (PyTypeObject *)callable;
     if (kwnames) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
         return -1;
     }
     if (_Py_OPCODE(instr[-1]) == PRECALL_METHOD) {
@@ -1371,13 +1372,38 @@ specialize_class_call(
             *instr = _Py_MAKECODEUNIT(CALL_NO_KW_BUILTIN_CLASS, _Py_OPARG(*instr));
             return 0;
         }
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS_NO_VECTORCALL);
+        SPECIALIZATION_FAIL(CALL, tp == &PyUnicode_Type ?
+            SPEC_FAIL_CALL_STR : SPEC_FAIL_CLASS_NO_VECTORCALL);
         return -1;
     }
     SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CLASS_MUTABLE);
     return -1;
 }
 
+#ifdef Py_STATS
+static int
+builtin_call_fail_kind(int ml_flags)
+{
+    switch (ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
+        METH_KEYWORDS | METH_METHOD)) {
+        case METH_VARARGS:
+            return SPEC_FAIL_PYCFUNCTION;
+        case METH_VARARGS | METH_KEYWORDS:
+            return SPEC_FAIL_PYCFUNCTION_WITH_KEYWORDS;
+        case METH_FASTCALL | METH_KEYWORDS:
+            return SPEC_FAIL_PYCFUNCTION_FAST_WITH_KEYWORDS;
+        case METH_NOARGS:
+            return SPEC_FAIL_PYCFUNCTION_NOARGS;
+        /* This case should never happen with PyCFunctionObject -- only
+            PyMethodObject. See zlib.compressobj()'s methods for an example.
+        */
+        case METH_METHOD | METH_FASTCALL | METH_KEYWORDS:
+        default:
+            return SPEC_FAIL_BAD_CALL_FLAGS;
+    }
+}
+#endif
+
 static PyMethodDescrObject *_list_append = NULL;
 _Py_IDENTIFIER(append);
 
@@ -1387,7 +1413,7 @@ specialize_method_descriptor(
     int nargs, PyObject *kwnames, SpecializedCacheEntry *cache)
 {
     if (kwnames) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_COMPLEX_PARAMETERS);
+        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
         return -1;
     }
     if (_list_append == NULL) {
@@ -1428,7 +1454,7 @@ specialize_method_descriptor(
             return 0;
         }
     }
-    SPECIALIZATION_FAIL(CALL, SPEC_FAIL_OTHER);
+    SPECIALIZATION_FAIL(CALL, builtin_call_fail_kind(descr->d_method->ml_flags));
     return -1;
 }
 
@@ -1485,30 +1511,6 @@ specialize_py_call(
     return 0;
 }
 
-#ifdef Py_STATS
-static int
-builtin_call_fail_kind(int ml_flags)
-{
-    switch (ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
-        METH_KEYWORDS | METH_METHOD)) {
-        case METH_VARARGS:
-            return SPEC_FAIL_PYCFUNCTION;
-        case METH_VARARGS | METH_KEYWORDS:
-            return SPEC_FAIL_PYCFUNCTION_WITH_KEYWORDS;
-        case METH_FASTCALL | METH_KEYWORDS:
-            return SPEC_FAIL_PYCFUNCTION_FAST_WITH_KEYWORDS;
-        case METH_NOARGS:
-            return SPEC_FAIL_PYCFUNCTION_NOARGS;
-        /* This case should never happen with PyCFunctionObject -- only
-            PyMethodObject. See zlib.compressobj()'s methods for an example.
-        */
-        case METH_METHOD | METH_FASTCALL | METH_KEYWORDS:
-        default:
-            return SPEC_FAIL_BAD_CALL_FLAGS;
-    }
-}
-#endif
-
 static int
 specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
     PyObject *kwnames, SpecializedCacheEntry *cache, PyObject *builtins)

From d74939c98e4ddd5234c4ec0644e61a848f9b26e6 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 13 Jan 2022 13:24:30 +0000
Subject: [PATCH 16/34] Factor out bound-method handling code.

---
 Python/ceval.c      | 37 +++++++++++++++++--------------------
 Python/specialize.c | 12 +++++-------
 2 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 7f6857a8dee378..ae61ed0afe7b80 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4573,16 +4573,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.positional_args = oparg;
             call_shape.kwnames = NULL;
             if (Py_TYPE(call_shape.callable) == &PyMethod_Type) {
-                PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
-                PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
-                Py_INCREF(meth);
-                Py_INCREF(self);
-                PEEK(oparg + 1) = self;
-                Py_DECREF(call_shape.callable);
-                call_shape.callable = meth;
-                call_shape.positional_args++;
-                assert(call_shape.postcall_shrink >= 1);
-                call_shape.postcall_shrink--;
+                goto precall_bound_method;
             }
             DISPATCH();
         }
@@ -4621,20 +4612,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.postcall_shrink = 2-is_method;
             call_shape.kwnames = NULL;
             if (Py_TYPE(call_shape.callable) == &PyMethod_Type) {
-                PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
-                PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
-                Py_INCREF(meth);
-                Py_INCREF(self);
-                PEEK(nargs + 1) = self;
-                Py_DECREF(call_shape.callable);
-                call_shape.callable = meth;
-                call_shape.positional_args++;
-                assert(call_shape.postcall_shrink >= 1);
-                call_shape.postcall_shrink--;
+                goto precall_bound_method;
             }
             DISPATCH();
         }
 
+    precall_bound_method:
+        {
+            PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
+            PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
+            Py_INCREF(meth);
+            Py_INCREF(self);
+            PEEK(call_shape.positional_args + 1) = self;
+            Py_DECREF(call_shape.callable);
+            call_shape.callable = meth;
+            call_shape.positional_args++;
+            assert(call_shape.postcall_shrink >= 1);
+            call_shape.postcall_shrink--;
+            DISPATCH();
+        }
+
         TARGET(KW_NAMES) {
             assert(call_shape.kwnames == NULL);
             assert(oparg < PyTuple_GET_SIZE(consts));
diff --git a/Python/specialize.c b/Python/specialize.c
index d8be60119aa5f3..8c6bccd7235805 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -513,14 +513,13 @@ initial_counter_value(void) {
 #define SPEC_FAIL_CLASS 18
 #define SPEC_FAIL_PYTHON_CLASS 19
 #define SPEC_FAIL_C_METHOD_CALL 20
-#define SPEC_FAIL_METHDESCR_NON_METHOD 21
-#define SPEC_FAIL_METHOD_CALL_CLASS 22
+#define SPEC_FAIL_BOUND_METHOD 21
+#define SPEC_FAIL_CALL_STR 22
 #define SPEC_FAIL_CLASS_NO_VECTORCALL 23
 #define SPEC_FAIL_CLASS_MUTABLE 24
 #define SPEC_FAIL_KWNAMES 25
 #define SPEC_FAIL_METHOD_WRAPPER 26
 #define SPEC_FAIL_OPERATOR_WRAPPER 27
-#define SPEC_FAIL_CALL_STR 28
 
 /* COMPARE_OP */
 #define SPEC_FAIL_STRING_COMPARE 13
@@ -1355,10 +1354,6 @@ specialize_class_call(
         SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
         return -1;
     }
-    if (_Py_OPCODE(instr[-1]) == PRECALL_METHOD) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_METHOD_CALL_CLASS);
-        return -1;
-    }
     if (tp->tp_new == PyBaseObject_Type.tp_new) {
         SPECIALIZATION_FAIL(CALL, SPEC_FAIL_PYTHON_CLASS);
         return -1;
@@ -1589,6 +1584,9 @@ call_fail_kind(PyObject *callable)
     else if (Py_TYPE(callable) == &_PyMethodWrapper_Type) {
         return SPEC_FAIL_METHOD_WRAPPER;
     }
+    else if (Py_TYPE(callable) == &PyMethod_Type) {
+        return SPEC_FAIL_BOUND_METHOD;
+    }
     return SPEC_FAIL_OTHER;
 }
 #endif

From 3323b3b15eefc9d59ad6377509b9efbfe0b50c49 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 13 Jan 2022 14:38:48 +0000
Subject: [PATCH 17/34] Specialize for builtin methods taking using the
 METH_FASTCALL | METH_KEYWORDS protocol.

---
 Include/opcode.h        | 67 +++++++++++++++++++++--------------------
 Lib/opcode.py           |  1 +
 Python/ceval.c          | 42 ++++++++++++++++++++++++++
 Python/opcode_targets.h | 24 +++++++--------
 Python/specialize.c     |  5 +++
 5 files changed, 94 insertions(+), 45 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index 7ca6f24c5683f6..f4c420eab355c4 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -139,39 +139,40 @@ extern "C" {
 #define CALL_ADAPTIVE                    39
 #define CALL_NO_KW_BUILTIN_O             40
 #define CALL_NO_KW_BUILTIN_FAST          41
-#define CALL_NO_KW_LEN                   42
-#define CALL_NO_KW_ISINSTANCE            43
-#define CALL_PY_EXACT_ARGS               44
-#define CALL_PY_WITH_DEFAULTS            45
-#define CALL_NO_KW_LIST_APPEND           46
-#define CALL_NO_KW_METHOD_DESCRIPTOR_O   47
-#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS  48
-#define CALL_NO_KW_TYPE_1                55
-#define CALL_NO_KW_BUILTIN_CLASS         56
-#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  57
-#define JUMP_ABSOLUTE_QUICK              58
-#define LOAD_ATTR_ADAPTIVE               59
-#define LOAD_ATTR_INSTANCE_VALUE         62
-#define LOAD_ATTR_WITH_HINT              63
-#define LOAD_ATTR_SLOT                   64
-#define LOAD_ATTR_MODULE                 65
-#define LOAD_GLOBAL_ADAPTIVE             66
-#define LOAD_GLOBAL_MODULE               67
-#define LOAD_GLOBAL_BUILTIN              72
-#define LOAD_METHOD_ADAPTIVE             75
-#define LOAD_METHOD_CACHED               76
-#define LOAD_METHOD_CLASS                77
-#define LOAD_METHOD_MODULE               78
-#define LOAD_METHOD_NO_DICT              79
-#define STORE_ATTR_ADAPTIVE              80
-#define STORE_ATTR_INSTANCE_VALUE        81
-#define STORE_ATTR_SLOT                  87
-#define STORE_ATTR_WITH_HINT            131
-#define LOAD_FAST__LOAD_FAST            134
-#define STORE_FAST__LOAD_FAST           140
-#define LOAD_FAST__LOAD_CONST           141
-#define LOAD_CONST__LOAD_FAST           143
-#define STORE_FAST__STORE_FAST          150
+#define CALL_BUILTIN_FAST_WITH_KEYWORDS  42
+#define CALL_NO_KW_LEN                   43
+#define CALL_NO_KW_ISINSTANCE            44
+#define CALL_PY_EXACT_ARGS               45
+#define CALL_PY_WITH_DEFAULTS            46
+#define CALL_NO_KW_LIST_APPEND           47
+#define CALL_NO_KW_METHOD_DESCRIPTOR_O   48
+#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS  55
+#define CALL_NO_KW_TYPE_1                56
+#define CALL_NO_KW_BUILTIN_CLASS         57
+#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  58
+#define JUMP_ABSOLUTE_QUICK              59
+#define LOAD_ATTR_ADAPTIVE               62
+#define LOAD_ATTR_INSTANCE_VALUE         63
+#define LOAD_ATTR_WITH_HINT              64
+#define LOAD_ATTR_SLOT                   65
+#define LOAD_ATTR_MODULE                 66
+#define LOAD_GLOBAL_ADAPTIVE             67
+#define LOAD_GLOBAL_MODULE               72
+#define LOAD_GLOBAL_BUILTIN              75
+#define LOAD_METHOD_ADAPTIVE             76
+#define LOAD_METHOD_CACHED               77
+#define LOAD_METHOD_CLASS                78
+#define LOAD_METHOD_MODULE               79
+#define LOAD_METHOD_NO_DICT              80
+#define STORE_ATTR_ADAPTIVE              81
+#define STORE_ATTR_INSTANCE_VALUE        87
+#define STORE_ATTR_SLOT                 131
+#define STORE_ATTR_WITH_HINT            134
+#define LOAD_FAST__LOAD_FAST            140
+#define STORE_FAST__LOAD_FAST           141
+#define LOAD_FAST__LOAD_CONST           143
+#define LOAD_CONST__LOAD_FAST           150
+#define STORE_FAST__STORE_FAST          153
 #define DO_TRACING                      255
 #ifdef NEED_OPCODE_JUMP_TABLES
 static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 52fad480c5a800..02508d7a2a2e9e 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -254,6 +254,7 @@ def jabs_op(name, op):
     "CALL_ADAPTIVE",
     "CALL_NO_KW_BUILTIN_O",
     "CALL_NO_KW_BUILTIN_FAST",
+    "CALL_BUILTIN_FAST_WITH_KEYWORDS",
     "CALL_NO_KW_LEN",
     "CALL_NO_KW_ISINSTANCE",
     "CALL_PY_EXACT_ARGS",
diff --git a/Python/ceval.c b/Python/ceval.c
index 6d53382b2862eb..02f64e7971f52c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4896,6 +4896,48 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
+        TARGET(CALL_BUILTIN_FAST_WITH_KEYWORDS) {
+            assert(cframe.use_tracing == 0);
+            /* Builtin METH_FASTCALL functions, without keywords */
+            PyObject *callable = call_shape.callable;
+            assert(call_shape.kwnames == NULL);
+            DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
+            DEOPT_IF(PyCFunction_GET_FLAGS(callable) !=
+                (METH_FASTCALL | METH_KEYWORDS), CALL);
+            STAT_INC(CALL, hit);
+            int kwnames_len = GET_CACHE()->adaptive.original_oparg;
+            assert(
+                (call_shape.kwnames == NULL && kwnames_len == 0) ||
+                (call_shape.kwnames != NULL &&
+                 PyTuple_GET_SIZE(call_shape.kwnames) == kwnames_len)
+            );
+            int nargs = call_shape.positional_args - kwnames_len;
+            STACK_SHRINK(call_shape.positional_args);
+            /* res = func(self, args, nargs, kwnames) */
+            _PyCFunctionFastWithKeywords cfunc =
+                (_PyCFunctionFastWithKeywords)(void(*)(void))
+                PyCFunction_GET_FUNCTION(callable);
+            PyObject *res = cfunc(
+                PyCFunction_GET_SELF(callable),
+                stack_pointer,
+                nargs,
+                call_shape.kwnames
+            );
+            assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
+
+            /* Free the arguments. */
+            for (int i = 0; i < call_shape.positional_args; i++) {
+                Py_DECREF(stack_pointer[i]);
+            }
+            STACK_SHRINK(call_shape.postcall_shrink);
+            PUSH(res);
+            Py_DECREF(callable);
+            if (res == NULL) {
+                goto error;
+            }
+            DISPATCH();
+        }
+
         TARGET(CALL_NO_KW_LEN) {
             assert(cframe.use_tracing == 0);
             assert(call_shape.kwnames == NULL);
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 7c1b3d63d914de..4530d0d53b179a 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -41,52 +41,52 @@ static void *opcode_targets[256] = {
     &&TARGET_CALL_ADAPTIVE,
     &&TARGET_CALL_NO_KW_BUILTIN_O,
     &&TARGET_CALL_NO_KW_BUILTIN_FAST,
+    &&TARGET_CALL_BUILTIN_FAST_WITH_KEYWORDS,
     &&TARGET_CALL_NO_KW_LEN,
     &&TARGET_CALL_NO_KW_ISINSTANCE,
     &&TARGET_CALL_PY_EXACT_ARGS,
     &&TARGET_CALL_PY_WITH_DEFAULTS,
     &&TARGET_CALL_NO_KW_LIST_APPEND,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
-    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
     &&TARGET_WITH_EXCEPT_START,
     &&TARGET_GET_AITER,
     &&TARGET_GET_ANEXT,
     &&TARGET_BEFORE_ASYNC_WITH,
     &&TARGET_BEFORE_WITH,
     &&TARGET_END_ASYNC_FOR,
+    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
     &&TARGET_CALL_NO_KW_TYPE_1,
     &&TARGET_CALL_NO_KW_BUILTIN_CLASS,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
     &&TARGET_JUMP_ABSOLUTE_QUICK,
-    &&TARGET_LOAD_ATTR_ADAPTIVE,
     &&TARGET_STORE_SUBSCR,
     &&TARGET_DELETE_SUBSCR,
+    &&TARGET_LOAD_ATTR_ADAPTIVE,
     &&TARGET_LOAD_ATTR_INSTANCE_VALUE,
     &&TARGET_LOAD_ATTR_WITH_HINT,
     &&TARGET_LOAD_ATTR_SLOT,
     &&TARGET_LOAD_ATTR_MODULE,
     &&TARGET_LOAD_GLOBAL_ADAPTIVE,
-    &&TARGET_LOAD_GLOBAL_MODULE,
     &&TARGET_GET_ITER,
     &&TARGET_GET_YIELD_FROM_ITER,
     &&TARGET_PRINT_EXPR,
     &&TARGET_LOAD_BUILD_CLASS,
-    &&TARGET_LOAD_GLOBAL_BUILTIN,
+    &&TARGET_LOAD_GLOBAL_MODULE,
     &&TARGET_GET_AWAITABLE,
     &&TARGET_LOAD_ASSERTION_ERROR,
+    &&TARGET_LOAD_GLOBAL_BUILTIN,
     &&TARGET_LOAD_METHOD_ADAPTIVE,
     &&TARGET_LOAD_METHOD_CACHED,
     &&TARGET_LOAD_METHOD_CLASS,
     &&TARGET_LOAD_METHOD_MODULE,
     &&TARGET_LOAD_METHOD_NO_DICT,
     &&TARGET_STORE_ATTR_ADAPTIVE,
-    &&TARGET_STORE_ATTR_INSTANCE_VALUE,
     &&TARGET_LIST_TO_TUPLE,
     &&TARGET_RETURN_VALUE,
     &&TARGET_IMPORT_STAR,
     &&TARGET_SETUP_ANNOTATIONS,
     &&TARGET_YIELD_VALUE,
-    &&TARGET_STORE_ATTR_SLOT,
+    &&TARGET_STORE_ATTR_INSTANCE_VALUE,
     &&TARGET_PREP_RERAISE_STAR,
     &&TARGET_POP_EXCEPT,
     &&TARGET_STORE_NAME,
@@ -130,29 +130,29 @@ static void *opcode_targets[256] = {
     &&TARGET_POP_JUMP_IF_NOT_NONE,
     &&TARGET_POP_JUMP_IF_NONE,
     &&TARGET_RAISE_VARARGS,
-    &&TARGET_STORE_ATTR_WITH_HINT,
+    &&TARGET_STORE_ATTR_SLOT,
     &&TARGET_MAKE_FUNCTION,
     &&TARGET_BUILD_SLICE,
-    &&TARGET_LOAD_FAST__LOAD_FAST,
+    &&TARGET_STORE_ATTR_WITH_HINT,
     &&TARGET_MAKE_CELL,
     &&TARGET_LOAD_CLOSURE,
     &&TARGET_LOAD_DEREF,
     &&TARGET_STORE_DEREF,
     &&TARGET_DELETE_DEREF,
+    &&TARGET_LOAD_FAST__LOAD_FAST,
     &&TARGET_STORE_FAST__LOAD_FAST,
-    &&TARGET_LOAD_FAST__LOAD_CONST,
     &&TARGET_CALL_FUNCTION_EX,
-    &&TARGET_LOAD_CONST__LOAD_FAST,
+    &&TARGET_LOAD_FAST__LOAD_CONST,
     &&TARGET_EXTENDED_ARG,
     &&TARGET_LIST_APPEND,
     &&TARGET_SET_ADD,
     &&TARGET_MAP_ADD,
     &&TARGET_LOAD_CLASSDEREF,
     &&TARGET_COPY_FREE_VARS,
-    &&TARGET_STORE_FAST__STORE_FAST,
+    &&TARGET_LOAD_CONST__LOAD_FAST,
     &&TARGET_RESUME,
     &&TARGET_MATCH_CLASS,
-    &&_unknown_opcode,
+    &&TARGET_STORE_FAST__STORE_FAST,
     &&_unknown_opcode,
     &&TARGET_FORMAT_VALUE,
     &&TARGET_BUILD_CONST_KEY_MAP,
diff --git a/Python/specialize.c b/Python/specialize.c
index 8c6bccd7235805..4ca0c230d89936 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1554,6 +1554,11 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
                 _Py_OPARG(*instr));
             return 0;
         }
+        case METH_FASTCALL | METH_KEYWORDS: {
+            *instr = _Py_MAKECODEUNIT(CALL_BUILTIN_FAST_WITH_KEYWORDS,
+                _Py_OPARG(*instr));
+            return 0;
+        }
         default:
             SPECIALIZATION_FAIL(CALL,
                 builtin_call_fail_kind(PyCFunction_GET_FLAGS(callable)));

From 32dbf1a41c9cca323483e6d2de9a5642b0bf4f1c Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 13 Jan 2022 19:09:06 +0000
Subject: [PATCH 18/34] Allow kwnames for specialized calls to builtin types.

---
 Include/opcode.h        | 24 ++++++++++++------------
 Lib/opcode.py           |  2 +-
 Python/ceval.c          | 13 ++++++-------
 Python/opcode_targets.h |  4 ++--
 Python/specialize.c     | 22 +++++++++++++---------
 5 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index f4c420eab355c4..b688f3f24b3619 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -137,18 +137,18 @@ extern "C" {
 #define STORE_SUBSCR_LIST_INT            37
 #define STORE_SUBSCR_DICT                38
 #define CALL_ADAPTIVE                    39
-#define CALL_NO_KW_BUILTIN_O             40
-#define CALL_NO_KW_BUILTIN_FAST          41
-#define CALL_BUILTIN_FAST_WITH_KEYWORDS  42
-#define CALL_NO_KW_LEN                   43
-#define CALL_NO_KW_ISINSTANCE            44
-#define CALL_PY_EXACT_ARGS               45
-#define CALL_PY_WITH_DEFAULTS            46
-#define CALL_NO_KW_LIST_APPEND           47
-#define CALL_NO_KW_METHOD_DESCRIPTOR_O   48
-#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS  55
-#define CALL_NO_KW_TYPE_1                56
-#define CALL_NO_KW_BUILTIN_CLASS         57
+#define CALL_BUILTIN_CLASS               40
+#define CALL_NO_KW_BUILTIN_O             41
+#define CALL_NO_KW_BUILTIN_FAST          42
+#define CALL_BUILTIN_FAST_WITH_KEYWORDS  43
+#define CALL_NO_KW_LEN                   44
+#define CALL_NO_KW_ISINSTANCE            45
+#define CALL_PY_EXACT_ARGS               46
+#define CALL_PY_WITH_DEFAULTS            47
+#define CALL_NO_KW_LIST_APPEND           48
+#define CALL_NO_KW_METHOD_DESCRIPTOR_O   55
+#define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS  56
+#define CALL_NO_KW_TYPE_1                57
 #define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  58
 #define JUMP_ABSOLUTE_QUICK              59
 #define LOAD_ATTR_ADAPTIVE               62
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 02508d7a2a2e9e..f8a3d6bfb5d14a 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -252,6 +252,7 @@ def jabs_op(name, op):
     "STORE_SUBSCR_LIST_INT",
     "STORE_SUBSCR_DICT",
     "CALL_ADAPTIVE",
+    "CALL_BUILTIN_CLASS",
     "CALL_NO_KW_BUILTIN_O",
     "CALL_NO_KW_BUILTIN_FAST",
     "CALL_BUILTIN_FAST_WITH_KEYWORDS",
@@ -263,7 +264,6 @@ def jabs_op(name, op):
     "CALL_NO_KW_METHOD_DESCRIPTOR_O",
     "CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS",
     "CALL_NO_KW_TYPE_1",
-    "CALL_NO_KW_BUILTIN_CLASS",
     "CALL_NO_KW_METHOD_DESCRIPTOR_FAST",
     "JUMP_ABSOLUTE_QUICK",
     "LOAD_ATTR_ADAPTIVE",
diff --git a/Python/ceval.c b/Python/ceval.c
index 02f64e7971f52c..410fa74ee257b2 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4803,18 +4803,18 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
-        TARGET(CALL_NO_KW_BUILTIN_CLASS) {
-            assert(call_shape.kwnames == NULL);
+        TARGET(CALL_BUILTIN_CLASS) {
             DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
             PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
             DEOPT_IF(tp->tp_vectorcall == NULL, CALL);
             STAT_INC(CALL, hit);
+            int kwnames_len = GET_CACHE()->adaptive.original_oparg;
 
-            int nargs = call_shape.positional_args;
-            STACK_SHRINK(nargs);
-            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer, nargs, NULL);
+            int nargs = call_shape.positional_args - kwnames_len;
+            STACK_SHRINK(call_shape.positional_args);
+            PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer, nargs, call_shape.kwnames);
             /* Free the arguments. */
-            for (int i = 0; i < nargs; i++) {
+            for (int i = 0; i < call_shape.positional_args; i++) {
                 Py_DECREF(stack_pointer[i]);
             }
             Py_DECREF(tp);
@@ -4900,7 +4900,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(cframe.use_tracing == 0);
             /* Builtin METH_FASTCALL functions, without keywords */
             PyObject *callable = call_shape.callable;
-            assert(call_shape.kwnames == NULL);
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) !=
                 (METH_FASTCALL | METH_KEYWORDS), CALL);
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 4530d0d53b179a..54c1350a8dfda0 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -39,6 +39,7 @@ static void *opcode_targets[256] = {
     &&TARGET_STORE_SUBSCR_LIST_INT,
     &&TARGET_STORE_SUBSCR_DICT,
     &&TARGET_CALL_ADAPTIVE,
+    &&TARGET_CALL_BUILTIN_CLASS,
     &&TARGET_CALL_NO_KW_BUILTIN_O,
     &&TARGET_CALL_NO_KW_BUILTIN_FAST,
     &&TARGET_CALL_BUILTIN_FAST_WITH_KEYWORDS,
@@ -47,16 +48,15 @@ static void *opcode_targets[256] = {
     &&TARGET_CALL_PY_EXACT_ARGS,
     &&TARGET_CALL_PY_WITH_DEFAULTS,
     &&TARGET_CALL_NO_KW_LIST_APPEND,
-    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
     &&TARGET_WITH_EXCEPT_START,
     &&TARGET_GET_AITER,
     &&TARGET_GET_ANEXT,
     &&TARGET_BEFORE_ASYNC_WITH,
     &&TARGET_BEFORE_WITH,
     &&TARGET_END_ASYNC_FOR,
+    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
     &&TARGET_CALL_NO_KW_TYPE_1,
-    &&TARGET_CALL_NO_KW_BUILTIN_CLASS,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
     &&TARGET_JUMP_ABSOLUTE_QUICK,
     &&TARGET_STORE_SUBSCR,
diff --git a/Python/specialize.c b/Python/specialize.c
index 4ca0c230d89936..0f26ac46714014 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1350,21 +1350,21 @@ specialize_class_call(
 {
     assert(PyType_Check(callable));
     PyTypeObject *tp = (PyTypeObject *)callable;
-    if (kwnames) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
-        return -1;
-    }
     if (tp->tp_new == PyBaseObject_Type.tp_new) {
         SPECIALIZATION_FAIL(CALL, SPEC_FAIL_PYTHON_CLASS);
         return -1;
     }
     if (tp == &PyType_Type && nargs == 1) {
+        if (kwnames) {
+            SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
+            return -1;
+        }
         *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TYPE_1, _Py_OPARG(*instr));
         return 0;
     }
     if (tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {
         if (tp->tp_vectorcall != NULL) {
-            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_BUILTIN_CLASS, _Py_OPARG(*instr));
+            *instr = _Py_MAKECODEUNIT(CALL_BUILTIN_CLASS, _Py_OPARG(*instr));
             return 0;
         }
         SPECIALIZATION_FAIL(CALL, tp == &PyUnicode_Type ?
@@ -1511,10 +1511,6 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
     PyObject *kwnames, SpecializedCacheEntry *cache, PyObject *builtins)
 {
     _PyObjectCache *cache1 = &cache[-1].obj;
-    if (kwnames) {
-        SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
-        return -1;
-    }
     if (PyCFunction_GET_FUNCTION(callable) == NULL) {
         return 1;
     }
@@ -1522,6 +1518,10 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
         (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
         METH_KEYWORDS | METH_METHOD)) {
         case METH_O: {
+            if (kwnames) {
+                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
+                return -1;
+            }
             if (nargs != 1) {
                 SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
                 return 1;
@@ -1539,6 +1539,10 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
             return 0;
         }
         case METH_FASTCALL: {
+            if (kwnames) {
+                SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
+                return -1;
+            }
             if (nargs == 2) {
                 /* isinstance(o1, o2) */
                 PyObject *builtin_isinstance = PyDict_GetItemString(

From bdf9f1546c6ee1bccc0d0ba1ecf2bd303bf09a3c Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 14 Jan 2022 10:33:06 +0000
Subject: [PATCH 19/34] Specialize calls to tuple() and str().

---
 Include/opcode.h        | 52 +++++++++++++++++++++--------------------
 Lib/opcode.py           |  2 ++
 Python/ceval.c          | 38 ++++++++++++++++++++++++++++++
 Python/opcode_targets.h | 34 +++++++++++++--------------
 Python/specialize.c     | 22 ++++++++++-------
 5 files changed, 98 insertions(+), 50 deletions(-)

diff --git a/Include/opcode.h b/Include/opcode.h
index b688f3f24b3619..e741ec24240538 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -148,31 +148,33 @@ extern "C" {
 #define CALL_NO_KW_LIST_APPEND           48
 #define CALL_NO_KW_METHOD_DESCRIPTOR_O   55
 #define CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS  56
-#define CALL_NO_KW_TYPE_1                57
-#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  58
-#define JUMP_ABSOLUTE_QUICK              59
-#define LOAD_ATTR_ADAPTIVE               62
-#define LOAD_ATTR_INSTANCE_VALUE         63
-#define LOAD_ATTR_WITH_HINT              64
-#define LOAD_ATTR_SLOT                   65
-#define LOAD_ATTR_MODULE                 66
-#define LOAD_GLOBAL_ADAPTIVE             67
-#define LOAD_GLOBAL_MODULE               72
-#define LOAD_GLOBAL_BUILTIN              75
-#define LOAD_METHOD_ADAPTIVE             76
-#define LOAD_METHOD_CACHED               77
-#define LOAD_METHOD_CLASS                78
-#define LOAD_METHOD_MODULE               79
-#define LOAD_METHOD_NO_DICT              80
-#define STORE_ATTR_ADAPTIVE              81
-#define STORE_ATTR_INSTANCE_VALUE        87
-#define STORE_ATTR_SLOT                 131
-#define STORE_ATTR_WITH_HINT            134
-#define LOAD_FAST__LOAD_FAST            140
-#define STORE_FAST__LOAD_FAST           141
-#define LOAD_FAST__LOAD_CONST           143
-#define LOAD_CONST__LOAD_FAST           150
-#define STORE_FAST__STORE_FAST          153
+#define CALL_NO_KW_STR_1                 57
+#define CALL_NO_KW_TUPLE_1               58
+#define CALL_NO_KW_TYPE_1                59
+#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST  62
+#define JUMP_ABSOLUTE_QUICK              63
+#define LOAD_ATTR_ADAPTIVE               64
+#define LOAD_ATTR_INSTANCE_VALUE         65
+#define LOAD_ATTR_WITH_HINT              66
+#define LOAD_ATTR_SLOT                   67
+#define LOAD_ATTR_MODULE                 72
+#define LOAD_GLOBAL_ADAPTIVE             75
+#define LOAD_GLOBAL_MODULE               76
+#define LOAD_GLOBAL_BUILTIN              77
+#define LOAD_METHOD_ADAPTIVE             78
+#define LOAD_METHOD_CACHED               79
+#define LOAD_METHOD_CLASS                80
+#define LOAD_METHOD_MODULE               81
+#define LOAD_METHOD_NO_DICT              87
+#define STORE_ATTR_ADAPTIVE             131
+#define STORE_ATTR_INSTANCE_VALUE       134
+#define STORE_ATTR_SLOT                 140
+#define STORE_ATTR_WITH_HINT            141
+#define LOAD_FAST__LOAD_FAST            143
+#define STORE_FAST__LOAD_FAST           150
+#define LOAD_FAST__LOAD_CONST           153
+#define LOAD_CONST__LOAD_FAST           154
+#define STORE_FAST__STORE_FAST          158
 #define DO_TRACING                      255
 #ifdef NEED_OPCODE_JUMP_TABLES
 static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/opcode.py b/Lib/opcode.py
index f8a3d6bfb5d14a..2985c4dc2c0bfd 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -263,6 +263,8 @@ def jabs_op(name, op):
     "CALL_NO_KW_LIST_APPEND",
     "CALL_NO_KW_METHOD_DESCRIPTOR_O",
     "CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS",
+    "CALL_NO_KW_STR_1",
+    "CALL_NO_KW_TUPLE_1",
     "CALL_NO_KW_TYPE_1",
     "CALL_NO_KW_METHOD_DESCRIPTOR_FAST",
     "JUMP_ABSOLUTE_QUICK",
diff --git a/Python/ceval.c b/Python/ceval.c
index 410fa74ee257b2..5b6d6eddbaaa16 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4803,6 +4803,44 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DISPATCH();
         }
 
+        TARGET(CALL_NO_KW_STR_1) {
+            DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
+            PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(tp != &PyUnicode_Type, CALL);
+            STAT_INC(CALL, hit);
+            assert(call_shape.kwnames == NULL);
+            PyObject *arg = TOP();
+            PyObject *res = PyObject_Str(arg);
+            Py_DECREF(arg);
+            Py_DECREF(&PyUnicode_Type);
+            STACK_SHRINK(call_shape.postcall_shrink);
+            SET_TOP(res);
+            if (res == NULL) {
+                goto error;
+            }
+            DISPATCH();
+        }
+
+        TARGET(CALL_NO_KW_TUPLE_1) {
+            DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
+            PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
+            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(tp != &PyTuple_Type, CALL);
+            STAT_INC(CALL, hit);
+            assert(call_shape.kwnames == NULL);
+            PyObject *arg = TOP();
+            PyObject *res = PySequence_Tuple(arg);
+            Py_DECREF(arg);
+            Py_DECREF(&PyTuple_Type);
+            STACK_SHRINK(call_shape.postcall_shrink);
+            SET_TOP(res);
+            if (res == NULL) {
+                goto error;
+            }
+            DISPATCH();
+        }
+
         TARGET(CALL_BUILTIN_CLASS) {
             DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
             PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 54c1350a8dfda0..8b7746ac220ce2 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -56,37 +56,37 @@ static void *opcode_targets[256] = {
     &&TARGET_END_ASYNC_FOR,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
     &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
+    &&TARGET_CALL_NO_KW_STR_1,
+    &&TARGET_CALL_NO_KW_TUPLE_1,
     &&TARGET_CALL_NO_KW_TYPE_1,
-    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
-    &&TARGET_JUMP_ABSOLUTE_QUICK,
     &&TARGET_STORE_SUBSCR,
     &&TARGET_DELETE_SUBSCR,
+    &&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
+    &&TARGET_JUMP_ABSOLUTE_QUICK,
     &&TARGET_LOAD_ATTR_ADAPTIVE,
     &&TARGET_LOAD_ATTR_INSTANCE_VALUE,
     &&TARGET_LOAD_ATTR_WITH_HINT,
     &&TARGET_LOAD_ATTR_SLOT,
-    &&TARGET_LOAD_ATTR_MODULE,
-    &&TARGET_LOAD_GLOBAL_ADAPTIVE,
     &&TARGET_GET_ITER,
     &&TARGET_GET_YIELD_FROM_ITER,
     &&TARGET_PRINT_EXPR,
     &&TARGET_LOAD_BUILD_CLASS,
-    &&TARGET_LOAD_GLOBAL_MODULE,
+    &&TARGET_LOAD_ATTR_MODULE,
     &&TARGET_GET_AWAITABLE,
     &&TARGET_LOAD_ASSERTION_ERROR,
+    &&TARGET_LOAD_GLOBAL_ADAPTIVE,
+    &&TARGET_LOAD_GLOBAL_MODULE,
     &&TARGET_LOAD_GLOBAL_BUILTIN,
     &&TARGET_LOAD_METHOD_ADAPTIVE,
     &&TARGET_LOAD_METHOD_CACHED,
     &&TARGET_LOAD_METHOD_CLASS,
     &&TARGET_LOAD_METHOD_MODULE,
-    &&TARGET_LOAD_METHOD_NO_DICT,
-    &&TARGET_STORE_ATTR_ADAPTIVE,
     &&TARGET_LIST_TO_TUPLE,
     &&TARGET_RETURN_VALUE,
     &&TARGET_IMPORT_STAR,
     &&TARGET_SETUP_ANNOTATIONS,
     &&TARGET_YIELD_VALUE,
-    &&TARGET_STORE_ATTR_INSTANCE_VALUE,
+    &&TARGET_LOAD_METHOD_NO_DICT,
     &&TARGET_PREP_RERAISE_STAR,
     &&TARGET_POP_EXCEPT,
     &&TARGET_STORE_NAME,
@@ -130,34 +130,34 @@ static void *opcode_targets[256] = {
     &&TARGET_POP_JUMP_IF_NOT_NONE,
     &&TARGET_POP_JUMP_IF_NONE,
     &&TARGET_RAISE_VARARGS,
-    &&TARGET_STORE_ATTR_SLOT,
+    &&TARGET_STORE_ATTR_ADAPTIVE,
     &&TARGET_MAKE_FUNCTION,
     &&TARGET_BUILD_SLICE,
-    &&TARGET_STORE_ATTR_WITH_HINT,
+    &&TARGET_STORE_ATTR_INSTANCE_VALUE,
     &&TARGET_MAKE_CELL,
     &&TARGET_LOAD_CLOSURE,
     &&TARGET_LOAD_DEREF,
     &&TARGET_STORE_DEREF,
     &&TARGET_DELETE_DEREF,
-    &&TARGET_LOAD_FAST__LOAD_FAST,
-    &&TARGET_STORE_FAST__LOAD_FAST,
+    &&TARGET_STORE_ATTR_SLOT,
+    &&TARGET_STORE_ATTR_WITH_HINT,
     &&TARGET_CALL_FUNCTION_EX,
-    &&TARGET_LOAD_FAST__LOAD_CONST,
+    &&TARGET_LOAD_FAST__LOAD_FAST,
     &&TARGET_EXTENDED_ARG,
     &&TARGET_LIST_APPEND,
     &&TARGET_SET_ADD,
     &&TARGET_MAP_ADD,
     &&TARGET_LOAD_CLASSDEREF,
     &&TARGET_COPY_FREE_VARS,
-    &&TARGET_LOAD_CONST__LOAD_FAST,
+    &&TARGET_STORE_FAST__LOAD_FAST,
     &&TARGET_RESUME,
     &&TARGET_MATCH_CLASS,
-    &&TARGET_STORE_FAST__STORE_FAST,
-    &&_unknown_opcode,
+    &&TARGET_LOAD_FAST__LOAD_CONST,
+    &&TARGET_LOAD_CONST__LOAD_FAST,
     &&TARGET_FORMAT_VALUE,
     &&TARGET_BUILD_CONST_KEY_MAP,
     &&TARGET_BUILD_STRING,
-    &&_unknown_opcode,
+    &&TARGET_STORE_FAST__STORE_FAST,
     &&_unknown_opcode,
     &&TARGET_LOAD_METHOD,
     &&_unknown_opcode,
diff --git a/Python/specialize.c b/Python/specialize.c
index 0f26ac46714014..13e55add35f0d2 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1354,15 +1354,21 @@ specialize_class_call(
         SPECIALIZATION_FAIL(CALL, SPEC_FAIL_PYTHON_CLASS);
         return -1;
     }
-    if (tp == &PyType_Type && nargs == 1) {
-        if (kwnames) {
-            SPECIALIZATION_FAIL(CALL, SPEC_FAIL_KWNAMES);
-            return -1;
-        }
-        *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TYPE_1, _Py_OPARG(*instr));
-        return 0;
-    }
     if (tp->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {
+        if (nargs == 1 && kwnames == NULL) {
+            if (tp == &PyUnicode_Type) {
+                *instr = _Py_MAKECODEUNIT(CALL_NO_KW_STR_1, _Py_OPARG(*instr));
+                return 0;
+            }
+            else if (tp == &PyType_Type) {
+                *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TYPE_1, _Py_OPARG(*instr));
+                return 0;
+            }
+            else if (tp == &PyTuple_Type) {
+                *instr = _Py_MAKECODEUNIT(CALL_NO_KW_TUPLE_1, _Py_OPARG(*instr));
+                return 0;
+            }
+        }
         if (tp->tp_vectorcall != NULL) {
             *instr = _Py_MAKECODEUNIT(CALL_BUILTIN_CLASS, _Py_OPARG(*instr));
             return 0;

From 100a5f69941bf4264c22f981e96f1375f6afe6e3 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Mon, 24 Jan 2022 11:19:51 +0000
Subject: [PATCH 20/34] Fix test_dis

---
 Lib/test/test_dis.py | 63 +++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 9ee0067da2841f..e5f79981a1ac76 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1203,7 +1203,7 @@ def _prepare_test_cases():
   Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=144, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=146, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=37, argval=224, argrepr='to 224', offset=148, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=38, argval=226, argrepr='to 226', offset=148, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=150, starts_line=22, is_jump_target=True, positions=None),
   Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=152, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=154, starts_line=None, is_jump_target=False, positions=None),
@@ -1222,7 +1222,7 @@ def _prepare_test_cases():
   Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=3, argval=3, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=210, argrepr='to 210', offset=186, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=27, argval=242, argrepr='to 242', offset=186, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=101, argval=202, argrepr='to 202', offset=192, starts_line=None, is_jump_target=False, positions=None),
@@ -1234,31 +1234,40 @@ def _prepare_test_cases():
   Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=206, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=208, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=210, starts_line=28, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=212, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=214, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=220, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=222, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=224, starts_line=23, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=226, starts_line=28, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=228, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=236, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=238, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=240, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=242, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=244, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=246, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=248, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=250, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=252, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=254, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=256, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=258, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=210, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=212, starts_line=28, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=214, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=220, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=222, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=224, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=226, starts_line=23, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=228, starts_line=28, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=230, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=236, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=238, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=240, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=242, starts_line=25, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=244, starts_line=28, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=246, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=248, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=250, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=252, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=254, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=256, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=258, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=260, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=262, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=264, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=266, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=268, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=270, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=272, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=274, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=276, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 # One last piece of inspect fodder to check the default line number handling

From 4c2da8b97647747b424eef8ba944a30714054631 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Mon, 24 Jan 2022 12:44:06 +0000
Subject: [PATCH 21/34] Fix specialization of method descriptors.

---
 Python/specialize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Python/specialize.c b/Python/specialize.c
index 625484450885a0..a69b73cff3e403 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1431,7 +1431,7 @@ specialize_method_descriptor(
                 SPECIALIZATION_FAIL(CALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
                 return -1;
             }
-            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_METHOD_DESCRIPTOR_O,
+            *instr = _Py_MAKECODEUNIT(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
                 _Py_OPARG(*instr));
             return 0;
         }

From a7d7b1e2a209a535fddd1560f82b82ce9c688027 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Mon, 24 Jan 2022 13:34:27 +0000
Subject: [PATCH 22/34] Move check for bound-methods from PRECALL opcodes back
 to CALL opcode.

---
 Python/ceval.c | 39 +++++++++++++++------------------------
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index e03060d1b4baee..4af42253544f34 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4539,9 +4539,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.postcall_shrink = 1;
             call_shape.positional_args = oparg;
             call_shape.kwnames = NULL;
-            if (Py_TYPE(call_shape.callable) == &PyMethod_Type) {
-                goto precall_bound_method;
-            }
             DISPATCH();
         }
 
@@ -4578,24 +4575,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             call_shape.positional_args = nargs;
             call_shape.postcall_shrink = 2-is_method;
             call_shape.kwnames = NULL;
-            if (Py_TYPE(call_shape.callable) == &PyMethod_Type) {
-                goto precall_bound_method;
-            }
-            DISPATCH();
-        }
-
-    precall_bound_method:
-        {
-            PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
-            PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
-            Py_INCREF(meth);
-            Py_INCREF(self);
-            PEEK(call_shape.positional_args + 1) = self;
-            Py_DECREF(call_shape.callable);
-            call_shape.callable = meth;
-            call_shape.positional_args++;
-            assert(call_shape.postcall_shrink >= 1);
-            call_shape.postcall_shrink--;
             DISPATCH();
         }
 
@@ -4607,14 +4586,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL) {
-            int total_args;
             PREDICTED(CALL);
+            PyObject *function;
             assert((oparg == 0 && call_shape.kwnames == NULL)
                 || (oparg != 0 && oparg == PyTuple_GET_SIZE(call_shape.kwnames)));
         call_function:
-            total_args = call_shape.positional_args;
+            function = call_shape.callable;
+            if (Py_TYPE(function) == &PyMethod_Type) {
+                PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
+                PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
+                Py_INCREF(meth);
+                Py_INCREF(self);
+                PEEK(call_shape.positional_args + 1) = self;
+                Py_DECREF(function);
+                function = meth;
+                call_shape.positional_args++;
+                assert(call_shape.postcall_shrink >= 1);
+                call_shape.postcall_shrink--;
+            }
+            int total_args = call_shape.positional_args;
             call_shape.positional_args -= oparg;
-            PyObject *function = call_shape.callable;
             // Check if the call can be inlined or not
             if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
                 int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;

From 43fdcdf022495f75141716032e3e4d2d2b154841 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Mon, 24 Jan 2022 16:16:09 +0000
Subject: [PATCH 23/34] Relax check in CALL_NO_KW_LIST_APPEND to any list
 subclass.

---
 Python/ceval.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 4af42253544f34..f1b4db2da55274 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5000,7 +5000,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DEOPT_IF(call_shape.positional_args != 2, CALL);
             DEOPT_IF(call_shape.callable != cache1->obj, CALL);
             PyObject *list = SECOND();
-            DEOPT_IF(!PyList_CheckExact(list), CALL);
+            DEOPT_IF(!PyList_Check(list), CALL);
             STAT_INC(CALL, hit);
             PyObject *arg = TOP();
             int err = PyList_Append(list, arg);

From 5d35ce3d27e282023b9fb917f77419a876f598c8 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Mon, 24 Jan 2022 16:53:28 +0000
Subject: [PATCH 24/34] Correct name of CallShape field.

---
 Python/ceval.c | 62 +++++++++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index f1b4db2da55274..97f276cbc1efb8 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1644,7 +1644,7 @@ pop_frame(PyThreadState *tstate, InterpreterFrame *frame)
 typedef struct {
     PyObject *callable;
     PyObject *kwnames;
-    int positional_args;
+    int total_args;
     int postcall_shrink;
 } CallShape;
 
@@ -1670,7 +1670,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     CallShape call_shape;
     call_shape.kwnames = NULL;
     call_shape.postcall_shrink = 0;
-    call_shape.positional_args = 0;
+    call_shape.total_args = 0;
     call_shape.callable = NULL;
 
     /* WARNING: Because the CFrame lives on the C stack,
@@ -4537,7 +4537,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(PRECALL_FUNCTION) {
             call_shape.callable = PEEK(oparg + 1);
             call_shape.postcall_shrink = 1;
-            call_shape.positional_args = oparg;
+            call_shape.total_args = oparg;
             call_shape.kwnames = NULL;
             DISPATCH();
         }
@@ -4572,7 +4572,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             int is_method = (PEEK(oparg + 2) != NULL);
             int nargs = oparg + is_method;
             call_shape.callable = PEEK(nargs + 1);
-            call_shape.positional_args = nargs;
+            call_shape.total_args = nargs;
             call_shape.postcall_shrink = 2-is_method;
             call_shape.kwnames = NULL;
             DISPATCH();
@@ -4597,15 +4597,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
                 Py_INCREF(meth);
                 Py_INCREF(self);
-                PEEK(call_shape.positional_args + 1) = self;
+                PEEK(call_shape.total_args + 1) = self;
                 Py_DECREF(function);
                 function = meth;
-                call_shape.positional_args++;
+                call_shape.total_args++;
                 assert(call_shape.postcall_shrink >= 1);
                 call_shape.postcall_shrink--;
             }
-            int total_args = call_shape.positional_args;
-            call_shape.positional_args -= oparg;
+            int total_args = call_shape.total_args;
+            int positional_args = total_args - oparg;
             // Check if the call can be inlined or not
             if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
                 int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
@@ -4613,7 +4613,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 STACK_SHRINK(total_args);
                 InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
                     tstate, (PyFunctionObject *)function, locals,
-                        stack_pointer, call_shape.positional_args, call_shape.kwnames
+                        stack_pointer, positional_args, call_shape.kwnames
                 );
                 STACK_SHRINK(call_shape.postcall_shrink);
                 // The frame has stolen all the arguments from the stack,
@@ -4632,12 +4632,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             if (cframe.use_tracing) {
                 res = trace_call_function(
                     tstate, function, stack_pointer-total_args,
-                    call_shape.positional_args, call_shape.kwnames);
+                    positional_args, call_shape.kwnames);
             }
             else {
                 res = PyObject_Vectorcall(
                     function, stack_pointer-total_args,
-                    call_shape.positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
+                    positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
                     call_shape.kwnames);
             }
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
@@ -4663,7 +4663,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 || (named_args != 0 && named_args == PyTuple_GET_SIZE(call_shape.kwnames)));
             if (cache->adaptive.counter == 0) {
                 next_instr--;
-                int nargs = call_shape.positional_args;
+                int nargs = call_shape.total_args;
                 int err = _Py_Specialize_CallNoKw(
                     call_shape.callable, next_instr, nargs,
                     call_shape.kwnames, cache, BUILTINS());
@@ -4682,7 +4682,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_PY_EXACT_ARGS) {
             SpecializedCacheEntry *caches = GET_CACHE();
-            int argcount = call_shape.positional_args;
+            int argcount = call_shape.total_args;
             DEOPT_IF(!PyFunction_Check(call_shape.callable), CALL);
             _PyCallCache *cache1 = &caches[-1].call;
             PyFunctionObject *func = (PyFunctionObject *)call_shape.callable;
@@ -4710,7 +4710,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_PY_WITH_DEFAULTS) {
             SpecializedCacheEntry *caches = GET_CACHE();
-            int argcount = call_shape.positional_args;
+            int argcount = call_shape.total_args;
             DEOPT_IF(!PyFunction_Check(call_shape.callable), CALL);
             _PyCallCache *cache1 = &caches[-1].call;
             PyFunctionObject *func = (PyFunctionObject *)call_shape.callable;
@@ -4745,7 +4745,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(CALL_NO_KW_TYPE_1) {
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(call_shape.total_args != 1, CALL);
             assert(call_shape.kwnames == NULL);
             PyObject *obj = TOP();
             PyObject *callable = SECOND();
@@ -4761,7 +4761,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_STR_1) {
             DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
             PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(call_shape.total_args != 1, CALL);
             DEOPT_IF(tp != &PyUnicode_Type, CALL);
             STAT_INC(CALL, hit);
             assert(call_shape.kwnames == NULL);
@@ -4780,7 +4780,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         TARGET(CALL_NO_KW_TUPLE_1) {
             DEOPT_IF(!PyType_Check(call_shape.callable), CALL);
             PyTypeObject *tp = (PyTypeObject *)call_shape.callable;
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(call_shape.total_args != 1, CALL);
             DEOPT_IF(tp != &PyTuple_Type, CALL);
             STAT_INC(CALL, hit);
             assert(call_shape.kwnames == NULL);
@@ -4803,11 +4803,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             STAT_INC(CALL, hit);
             int kwnames_len = GET_CACHE()->adaptive.original_oparg;
 
-            int nargs = call_shape.positional_args - kwnames_len;
-            STACK_SHRINK(call_shape.positional_args);
+            int nargs = call_shape.total_args - kwnames_len;
+            STACK_SHRINK(call_shape.total_args);
             PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer, nargs, call_shape.kwnames);
             /* Free the arguments. */
-            for (int i = 0; i < call_shape.positional_args; i++) {
+            for (int i = 0; i < call_shape.total_args; i++) {
                 Py_DECREF(stack_pointer[i]);
             }
             Py_DECREF(tp);
@@ -4823,7 +4823,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(cframe.use_tracing == 0);
             /* Builtin METH_O functions */
             assert(call_shape.kwnames == NULL);
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(call_shape.total_args != 1, CALL);
             PyObject *callable = call_shape.callable;
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_O, CALL);
@@ -4861,7 +4861,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 CALL);
             STAT_INC(CALL, hit);
 
-            int nargs = call_shape.positional_args;
+            int nargs = call_shape.total_args;
             PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
             STACK_SHRINK(nargs);
             /* res = func(self, args, nargs) */
@@ -4903,8 +4903,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 (call_shape.kwnames != NULL &&
                  PyTuple_GET_SIZE(call_shape.kwnames) == kwnames_len)
             );
-            int nargs = call_shape.positional_args - kwnames_len;
-            STACK_SHRINK(call_shape.positional_args);
+            int nargs = call_shape.total_args - kwnames_len;
+            STACK_SHRINK(call_shape.total_args);
             /* res = func(self, args, nargs, kwnames) */
             _PyCFunctionFastWithKeywords cfunc =
                 (_PyCFunctionFastWithKeywords)(void(*)(void))
@@ -4918,7 +4918,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
 
             /* Free the arguments. */
-            for (int i = 0; i < call_shape.positional_args; i++) {
+            for (int i = 0; i < call_shape.total_args; i++) {
                 Py_DECREF(stack_pointer[i]);
             }
             STACK_SHRINK(call_shape.postcall_shrink);
@@ -4935,7 +4935,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(call_shape.kwnames == NULL);
             /* len(o) */
             SpecializedCacheEntry *caches = GET_CACHE();
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(call_shape.total_args != 1, CALL);
             assert(caches[0].adaptive.original_oparg == 0);
             _PyObjectCache *cache1 = &caches[-1].obj;
 
@@ -4967,7 +4967,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             /* isinstance(o, o2) */
             SpecializedCacheEntry *caches = GET_CACHE();
             assert(caches[0].adaptive.original_oparg == 0);
-            DEOPT_IF(call_shape.positional_args != 2, CALL);
+            DEOPT_IF(call_shape.total_args != 2, CALL);
             _PyObjectCache *cache1 = &caches[-1].obj;
 
             DEOPT_IF(call_shape.callable != cache1->obj, CALL);
@@ -4997,7 +4997,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             assert(call_shape.kwnames == NULL);
             SpecializedCacheEntry *caches = GET_CACHE();
             _PyObjectCache *cache1 = &caches[-1].obj;
-            DEOPT_IF(call_shape.positional_args != 2, CALL);
+            DEOPT_IF(call_shape.total_args != 2, CALL);
             DEOPT_IF(call_shape.callable != cache1->obj, CALL);
             PyObject *list = SECOND();
             DEOPT_IF(!PyList_Check(list), CALL);
@@ -5018,7 +5018,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
             assert(call_shape.kwnames == NULL);
-            DEOPT_IF(call_shape.positional_args != 2, CALL);
+            DEOPT_IF(call_shape.total_args != 2, CALL);
             DEOPT_IF(!Py_IS_TYPE(call_shape.callable, &PyMethodDescr_Type), CALL);
             PyMethodDef *meth = ((PyMethodDescrObject *)call_shape.callable)->d_method;
             DEOPT_IF(meth->ml_flags != METH_O, CALL);
@@ -5047,7 +5047,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
             assert(call_shape.kwnames == NULL);
-            DEOPT_IF(call_shape.positional_args != 1, CALL);
+            DEOPT_IF(call_shape.total_args != 1, CALL);
             DEOPT_IF(!Py_IS_TYPE(call_shape.callable, &PyMethodDescr_Type), CALL);
             PyMethodDef *meth = ((PyMethodDescrObject *)call_shape.callable)->d_method;
             DEOPT_IF(meth->ml_flags != METH_NOARGS, CALL);
@@ -5080,7 +5080,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             DEOPT_IF(meth->ml_flags != METH_FASTCALL, CALL);
             STAT_INC(CALL, hit);
             _PyCFunctionFast cfunc = (_PyCFunctionFast)(void(*)(void))meth->ml_meth;
-            int nargs = call_shape.positional_args-1;
+            int nargs = call_shape.total_args-1;
             STACK_SHRINK(nargs);
             PyObject *self = TOP();
             PyObject *res = cfunc(self, stack_pointer, nargs);

From 639adb8f85533ddea2020b6c89a418bd8e70c13a Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Tue, 25 Jan 2022 11:44:28 +0000
Subject: [PATCH 25/34] Add news item.

---
 .../2022-01-25-11-44-17.bpo-46329.SEhynE.rst         | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst
new file mode 100644
index 00000000000000..ead71855ae578f
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst	
@@ -0,0 +1,12 @@
+Use two or three bytecodes to implement most calls.
+
+Calls without named arguments are implemented as a sequenceof two
+instructions:  ``PRECALL; CALL`` Calls with named arguments are implemented
+as a sequence of three instructions: ``PRECALL; KW_NAMES; CALL``. There are
+two different ``PRECALL`` instructions: ``PRECALL_FUNTION`` and
+``PRECALL_METHOD`` which pairs with ``LOAD_METHOD``.
+
+This partition into pre-call and call allows better specialization, and thus
+better performance ultimately.
+
+There is no change in semantics.

From 6914240a525d3b28e895fb33d6dfc196351b4184 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Tue, 25 Jan 2022 12:20:46 +0000
Subject: [PATCH 26/34] Minor tidy ups.

---
 Python/ceval.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 97f276cbc1efb8..0fc64653d5c2e9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1638,8 +1638,8 @@ pop_frame(PyThreadState *tstate, InterpreterFrame *frame)
     return prev_frame;
 }
 
-/* It is only between a PRECALL_METHOD/FUNCTION instruction and the following instruction,
- * that these two values have any meaning.
+/* It is only between a PRECALL_METHOD/FUNCTION instruction and the following CALL,
+ * that these values have any meaning.
  */
 typedef struct {
     PyObject *callable;
@@ -4613,7 +4613,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
                 STACK_SHRINK(total_args);
                 InterpreterFrame *new_frame = _PyEvalFramePushAndInit(
                     tstate, (PyFunctionObject *)function, locals,
-                        stack_pointer, positional_args, call_shape.kwnames
+                    stack_pointer, positional_args, call_shape.kwnames
                 );
                 STACK_SHRINK(call_shape.postcall_shrink);
                 // The frame has stolen all the arguments from the stack,
@@ -4855,7 +4855,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             /* Builtin METH_FASTCALL functions, without keywords */
             assert(call_shape.kwnames == NULL);
             PyObject *callable = call_shape.callable;
-            assert(call_shape.kwnames == NULL);
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) != METH_FASTCALL,
                 CALL);

From 2cb70adf900000062625bf0a6d73d6a5432048d7 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 27 Jan 2022 11:08:05 +0000
Subject: [PATCH 27/34] Fix typos in news item.

---
 .../2022-01-25-11-44-17.bpo-46329.SEhynE.rst                  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst
index ead71855ae578f..1670a3830d081d 100644
--- a/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst	
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst	
@@ -1,7 +1,7 @@
 Use two or three bytecodes to implement most calls.
 
-Calls without named arguments are implemented as a sequenceof two
-instructions:  ``PRECALL; CALL`` Calls with named arguments are implemented
+Calls without named arguments are implemented as a sequence of two
+instructions: ``PRECALL; CALL``. Calls with named arguments are implemented
 as a sequence of three instructions: ``PRECALL; KW_NAMES; CALL``. There are
 two different ``PRECALL`` instructions: ``PRECALL_FUNTION`` and
 ``PRECALL_METHOD`` which pairs with ``LOAD_METHOD``.

From 61ef1b43e084764c150a80ca86ecd97278aca96a Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 27 Jan 2022 11:20:14 +0000
Subject: [PATCH 28/34] Address review comments.

---
 Lib/opcode.py  | 1 +
 Python/ceval.c | 8 ++++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Lib/opcode.py b/Lib/opcode.py
index 0733149d96b2ff..47fd2009869d48 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -198,6 +198,7 @@ def jabs_op(name, op):
 
 def_op('CALL', 171)
 def_op('KW_NAMES', 172)
+hasconst.append(172)
 
 del def_op, name_op, jrel_op, jabs_op
 
diff --git a/Python/ceval.c b/Python/ceval.c
index 66adbe26af54c2..ecc851ef090075 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1668,10 +1668,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
     CFrame cframe;
     CallShape call_shape;
-    call_shape.kwnames = NULL;
+    call_shape.kwnames = NULL; // Borrowed reference
     call_shape.postcall_shrink = 0;
     call_shape.total_args = 0;
-    call_shape.callable = NULL;
+    call_shape.callable = NULL; // Borrowed reference
 
     /* WARNING: Because the CFrame lives on the C stack,
      * but can be accessed from a heap allocated object (tstate)
@@ -4607,8 +4607,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         call_function:
             function = call_shape.callable;
             if (Py_TYPE(function) == &PyMethod_Type) {
-                PyObject *meth = ((PyMethodObject *)call_shape.callable)->im_func;
-                PyObject *self = ((PyMethodObject *)call_shape.callable)->im_self;
+                PyObject *meth = ((PyMethodObject *)function)->im_func;
+                PyObject *self = ((PyMethodObject *)function)->im_self;
                 Py_INCREF(meth);
                 Py_INCREF(self);
                 PEEK(call_shape.total_args + 1) = self;

From 38ebe7c4865fbcd0e3dac231b29d6b47c2446f05 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 27 Jan 2022 12:20:10 +0000
Subject: [PATCH 29/34] Update docs for new opcodes.

---
 Doc/library/dis.rst   | 71 +++++++++++++++++++++++++------------------
 Doc/whatsnew/3.11.rst |  3 +-
 2 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index d59680919716e5..9d223f7644966e 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -34,10 +34,13 @@ the following command can be used to display the disassembly of
 :func:`myfunc`::
 
    >>> dis.dis(myfunc)
-     2           0 LOAD_GLOBAL              0 (len)
-                 2 LOAD_FAST                0 (alist)
-                 4 CALL_NO_KW               1
-                 6 RETURN_VALUE
+    1           0 RESUME                   0
+
+    2           2 LOAD_GLOBAL              0 (len)
+                4 LOAD_FAST                0 (alist)
+                6 PRECALL_FUNCTION         1
+                8 CALL                     0
+               10 RETURN_VALUE
 
 (The "2" is a line number).
 
@@ -102,9 +105,11 @@ Example::
     >>> for instr in bytecode:
     ...     print(instr.opname)
     ...
+    RESUME
     LOAD_GLOBAL
     LOAD_FAST
-    CALL_NO_KW
+    PRECALL_FUNCTION
+    CALL
     RETURN_VALUE
 
 
@@ -617,7 +622,7 @@ iterations of the loop.
 .. opcode:: LOAD_BUILD_CLASS
 
    Pushes :func:`builtins.__build_class__` onto the stack.  It is later called
-   by :opcode:`CALL_NO_KW` to construct a class.
+   to construct a class.
 
 
 .. opcode:: BEFORE_WITH (delta)
@@ -1058,30 +1063,19 @@ iterations of the loop.
      with ``__cause__`` set to ``TOS``)
 
 
-.. opcode:: CALL_NO_KW (argc)
+.. opcode:: CALL (named)
 
-   Calls a callable object with positional arguments.
-   *argc* indicates the number of positional arguments.
-   The top of the stack contains positional arguments, with the right-most
-   argument on top.  Below the arguments is a callable object to call.
-   ``CALL_NO_KW`` pops all arguments and the callable object off the stack,
-   calls the callable object with those arguments, and pushes the return value
-   returned by the callable object.
-
-   .. versionadded:: 3.11
+   Calls a callable object with the number of positional arguments specified by
+   the preceding :opcode:`PRECALL_FUNCTION` or :opcode:`PRECALL_METHOD` and
+   the named arguments specified by the preceding :opcode:`KW_NAMES`, if any.
+   *named* indicates the number of named arguments.
+   On the stack are (in ascending order):
 
+   * The callable
+   * The positional arguments
+   * The named arguments
 
-.. opcode:: CALL_KW (argc)
-
-   Calls a callable object with positional (if any) and keyword arguments.
-   *argc* indicates the total number of positional and keyword arguments.
-   The top element on the stack contains a tuple with the names of the
-   keyword arguments, which must be strings.
-   Below that are the values for the keyword arguments,
-   in the order corresponding to the tuple.
-   Below that are positional arguments, with the right-most parameter on
-   top.  Below the arguments is a callable object to call.
-   ``CALL_KW`` pops all arguments and the callable object off the stack,
+   ``CALL`` pops all arguments and the callable object off the stack,
    calls the callable object with those arguments, and pushes the return value
    returned by the callable object.
 
@@ -1108,7 +1102,7 @@ iterations of the loop.
    Loads a method named ``co_names[namei]`` from the TOS object. TOS is popped.
    This bytecode distinguishes two cases: if TOS has a method with the correct
    name, the bytecode pushes the unbound method and TOS. TOS will be used as
-   the first argument (``self``) by :opcode:`CALL_METHOD` when calling the
+   the first argument (``self``) by :opcode:`PRECALL_METHOD` when calling the
    unbound method. Otherwise, ``NULL`` and the object return by the attribute
    lookup are pushed.
 
@@ -1117,14 +1111,31 @@ iterations of the loop.
 
 .. opcode:: PRECALL_METHOD (argc)
 
-   Prefixes either :opcode:`CALL_NO_KW` or :opcode:`CALL_KW`.
+   Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
    This opcode is designed to be used with :opcode:`LOAD_METHOD`.
-   Sets internal variables, so that :opcode:`CALL_NO_KW` or :opcode:`CALL_KW`
+   Sets internal variables, so that :opcode:`CALL`
    clean up after :opcode:`LOAD_METHOD` correctly.
 
    .. versionadded:: 3.11
 
 
+.. opcode:: PRECALL_FUNCTION (args)
+
+   Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
+   Sets internal variables, so that :opcode:`CALL`
+   clean up after :opcode:`LOAD_METHOD` correctly.
+
+   .. versionadded:: 3.11
+
+
+..opcode:: KW_NAMES (i)
+
+   Stores a reference to ``co_consts[consti]`` into an internal variable
+   for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.
+
+   .. versionadded:: 3.11
+
+
 .. opcode:: MAKE_FUNCTION (flags)
 
    Pushes a new function object on the stack.  From bottom to top, the consumed
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index adf38b6b0145c2..795ff316fbabd7 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -400,7 +400,8 @@ CPython bytecode changes
 
 * Replaced the three call instructions: :opcode:`CALL_FUNCTION`,
   :opcode:`CALL_FUNCTION_KW` and :opcode:`CALL_METHOD` with
-  :opcode:`CALL_NO_KW`, :opcode:`CALL_KW` and :opcode:`PRECALL_METHOD`.
+  :opcode:`PRECALL_FUNCTION`, :opcode:`PRECALL_METHOD`, :opcode:`CALL`,
+  and :opcode:`KW_NAMES`.
   This decouples the argument shifting for methods from the handling of
   keyword arguments and allows better specialization of calls.
 

From ddc2f57603f7cbdcea986f4abaaac3acc86fec23 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 27 Jan 2022 12:33:15 +0000
Subject: [PATCH 30/34] Fix up formatting

---
 Doc/library/dis.rst | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 9d223f7644966e..037bb6a57d8e0d 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -34,13 +34,13 @@ the following command can be used to display the disassembly of
 :func:`myfunc`::
 
    >>> dis.dis(myfunc)
-    1           0 RESUME                   0
+     1           0 RESUME                   0
 
-    2           2 LOAD_GLOBAL              0 (len)
-                4 LOAD_FAST                0 (alist)
-                6 PRECALL_FUNCTION         1
-                8 CALL                     0
-               10 RETURN_VALUE
+     2           2 LOAD_GLOBAL              0 (len)
+                 4 LOAD_FAST                0 (alist)
+                 6 PRECALL_FUNCTION         1
+                 8 CALL                     0
+                10 RETURN_VALUE
 
 (The "2" is a line number).
 
@@ -1128,7 +1128,7 @@ iterations of the loop.
    .. versionadded:: 3.11
 
 
-..opcode:: KW_NAMES (i)
+.. opcode:: KW_NAMES (i)
 
    Stores a reference to ``co_consts[consti]`` into an internal variable
    for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.

From d4f710cb2a0d458509b62d9124a20ed3390b39b5 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 27 Jan 2022 14:41:31 +0000
Subject: [PATCH 31/34] Fix up test_dis

---
 Lib/test/test_dis.py | 141 ++++++++++++++++++++-----------------------
 1 file changed, 66 insertions(+), 75 deletions(-)

diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index ab57a21ee9c855..29da5701cdaa30 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1192,82 +1192,73 @@ def _prepare_test_cases():
   Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=120, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='BINARY_OP', opcode=122, arg=11, argval=11, argrepr='/', offset=122, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=124, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=15, argval=158, argrepr='to 158', offset=126, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=128, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=130, starts_line=22, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=75, argval=150, argrepr='to 150', offset=132, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=134, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=136, starts_line=23, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=138, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=144, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=146, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=38, argval=226, argrepr='to 226', offset=148, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=150, starts_line=22, is_jump_target=True, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=152, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=154, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=158, starts_line=25, is_jump_target=True, positions=None),
-  Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=160, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=162, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=164, starts_line=26, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=166, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=170, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=174, starts_line=25, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=176, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=178, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=3, argval=3, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='JUMP_FORWARD', opcode=110, arg=27, argval=242, argrepr='to 242', offset=186, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=101, argval=202, argrepr='to 202', offset=192, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=194, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=196, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=126, starts_line=25, is_jump_target=False, positions=None),
+  Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=128, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=130, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=132, starts_line=26, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Never reach this', argrepr="'Never reach this'", offset=134, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=136, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=138, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=142, starts_line=25, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=144, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=146, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=3, argval=3, argrepr='', offset=148, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=150, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=152, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=178, argrepr='to 178', offset=154, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=85, argval=170, argrepr='to 170', offset=160, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=162, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=164, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=170, starts_line=None, is_jump_target=True, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=174, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=176, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=15, argval=210, argrepr='to 210', offset=178, starts_line=None, is_jump_target=True, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=182, starts_line=22, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=101, argval=202, argrepr='to 202', offset=184, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=188, starts_line=23, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=190, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=192, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=194, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=196, starts_line=None, is_jump_target=False, positions=None),
   Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=198, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=200, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=202, starts_line=None, is_jump_target=True, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=206, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=208, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=210, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=212, starts_line=28, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=214, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=220, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=222, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=224, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=226, starts_line=23, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=228, starts_line=28, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=230, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=236, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=238, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=240, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=242, starts_line=25, is_jump_target=True, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=244, starts_line=28, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=246, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=248, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=250, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=252, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=254, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=256, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=258, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=260, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=262, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=264, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=266, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=268, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=270, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=272, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=274, starts_line=None, is_jump_target=False, positions=None),
-  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=276, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=224, argrepr='to 224', offset=200, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=202, starts_line=22, is_jump_target=True, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=206, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=208, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=210, starts_line=28, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=212, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=214, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=220, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=222, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=224, starts_line=23, is_jump_target=True, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=226, starts_line=28, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=228, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=236, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=238, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=240, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=242, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=244, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='PRECALL_FUNCTION', opcode=167, arg=1, argval=1, argrepr='', offset=246, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='CALL', opcode=171, arg=0, argval=0, argrepr='', offset=248, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=250, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=252, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=254, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=256, starts_line=None, is_jump_target=False, positions=None),
+  Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=258, starts_line=None, is_jump_target=False, positions=None),
 ]
 
 # One last piece of inspect fodder to check the default line number handling

From 2fa70a0c19568dc1364c3b757da6e0f0102bc746 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Thu, 27 Jan 2022 14:44:55 +0000
Subject: [PATCH 32/34] Address review comments.

---
 Doc/library/dis.rst                                            | 3 +--
 .../Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 037bb6a57d8e0d..ef64f75ce9f83f 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -1122,8 +1122,7 @@ iterations of the loop.
 .. opcode:: PRECALL_FUNCTION (args)
 
    Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
-   Sets internal variables, so that :opcode:`CALL`
-   clean up after :opcode:`LOAD_METHOD` correctly.
+   Sets internal variables, so that :opcode:`CALL` can execute correctly.
 
    .. versionadded:: 3.11
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst
index 1670a3830d081d..43332975dc0421 100644
--- a/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst	
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-01-25-11-44-17.bpo-46329.SEhynE.rst	
@@ -4,7 +4,7 @@ Calls without named arguments are implemented as a sequence of two
 instructions: ``PRECALL; CALL``. Calls with named arguments are implemented
 as a sequence of three instructions: ``PRECALL; KW_NAMES; CALL``. There are
 two different ``PRECALL`` instructions: ``PRECALL_FUNTION`` and
-``PRECALL_METHOD`` which pairs with ``LOAD_METHOD``.
+``PRECALL_METHOD``. The latter pairs with ``LOAD_METHOD``.
 
 This partition into pre-call and call allows better specialization, and thus
 better performance ultimately.

From bd77c5d2f56f52f96e9505a78c762612d944dac8 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 28 Jan 2022 11:52:31 +0000
Subject: [PATCH 33/34] Clarify ownership of callable in CallShape.

---
 Python/ceval.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index 9ebd1d4701db68..f2e6a1cb58d9da 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1669,7 +1669,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
     call_shape.kwnames = NULL; // Borrowed reference
     call_shape.postcall_shrink = 0;
     call_shape.total_args = 0;
-    call_shape.callable = NULL; // Borrowed reference
+    call_shape.callable = NULL; // Strong reference
 
     /* WARNING: Because the CFrame lives on the C stack,
      * but can be accessed from a heap allocated object (tstate)
@@ -4494,8 +4494,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
         }
 
         TARGET(PRECALL_FUNCTION) {
+            /* Move ownership of reference from stack to call_shape */
             call_shape.callable = PEEK(oparg + 1);
             call_shape.postcall_shrink = 1;
+
             call_shape.total_args = oparg;
             call_shape.kwnames = NULL;
             DISPATCH();
@@ -4530,9 +4532,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             */
             int is_method = (PEEK(oparg + 2) != NULL);
             int nargs = oparg + is_method;
+            /* Move ownership of reference from stack to call_shape
+             * and make sure that NULL is cleared from stack */
             call_shape.callable = PEEK(nargs + 1);
-            call_shape.total_args = nargs;
             call_shape.postcall_shrink = 2-is_method;
+
+            call_shape.total_args = nargs;
             call_shape.kwnames = NULL;
             DISPATCH();
         }

From 3ac2ed84fa233d10ff2938d2d8ac9720d862fe34 Mon Sep 17 00:00:00 2001
From: Mark Shannon <mark@hotpy.org>
Date: Fri, 28 Jan 2022 11:57:18 +0000
Subject: [PATCH 34/34] Fix comment.

---
 Python/ceval.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Python/ceval.c b/Python/ceval.c
index f2e6a1cb58d9da..cd05780b16eccf 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4856,7 +4856,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
 
         TARGET(CALL_BUILTIN_FAST_WITH_KEYWORDS) {
             assert(cframe.use_tracing == 0);
-            /* Builtin METH_FASTCALL functions, without keywords */
+            /* Builtin METH_FASTCALL | METH_KEYWORDS functions */
             PyObject *callable = call_shape.callable;
             DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
             DEOPT_IF(PyCFunction_GET_FLAGS(callable) !=