Skip to content

Commit 2613ac4

Browse files
committed
Modernize CALL_BOUND_METHOD_EXACT_ARGS
1 parent 12c0806 commit 2613ac4

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

Python/bytecodes.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,17 +2469,18 @@ dummy_func(
24692469
CHECK_EVAL_BREAKER();
24702470
}
24712471

2472-
// stack effect: (__0, __array[oparg] -- )
2473-
inst(CALL_BOUND_METHOD_EXACT_ARGS) {
2474-
DEOPT_IF(is_method(stack_pointer, oparg), CALL);
2475-
PyObject *function = PEEK(oparg + 1);
2476-
DEOPT_IF(Py_TYPE(function) != &PyMethod_Type, CALL);
2472+
// Start out with [NULL, method, arg1, arg2, ...]
2473+
// Transform to [func, self, arg1, arg2, ...]
2474+
// Then fall through to CALL_PY_EXACT_ARGS
2475+
inst(CALL_BOUND_METHOD_EXACT_ARGS, (unused/1, unused/2, unused/1, thing1, thing2, unused[oparg] -- unused)) {
2476+
DEOPT_IF(thing1 != NULL, CALL);
2477+
DEOPT_IF(Py_TYPE(thing2) != &PyMethod_Type, CALL);
24772478
STAT_INC(CALL, hit);
2478-
PyObject *self = ((PyMethodObject *)function)->im_self;
2479-
PEEK(oparg + 1) = Py_NewRef(self);
2480-
PyObject *meth = ((PyMethodObject *)function)->im_func;
2481-
PEEK(oparg + 2) = Py_NewRef(meth);
2482-
Py_DECREF(function);
2479+
PyObject *self = ((PyMethodObject *)thing2)->im_self;
2480+
PEEK(oparg + 1) = Py_NewRef(self); // thing2
2481+
PyObject *meth = ((PyMethodObject *)thing2)->im_func;
2482+
PEEK(oparg + 2) = Py_NewRef(meth); // thing1
2483+
Py_DECREF(thing2);
24832484
GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS);
24842485
}
24852486

Python/generated_cases.c.h

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
289289
case CALL:
290290
return -1;
291291
case CALL_BOUND_METHOD_EXACT_ARGS:
292-
return -1;
292+
return oparg + 2;
293293
case CALL_PY_EXACT_ARGS:
294294
return -1;
295295
case CALL_PY_WITH_DEFAULTS:
@@ -635,7 +635,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
635635
case CALL:
636636
return -1;
637637
case CALL_BOUND_METHOD_EXACT_ARGS:
638-
return -1;
638+
return 1;
639639
case CALL_PY_EXACT_ARGS:
640640
return -1;
641641
case CALL_PY_WITH_DEFAULTS:
@@ -843,7 +843,7 @@ struct opcode_metadata {
843843
[LOAD_ATTR_METHOD_LAZY_DICT] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC00000000 },
844844
[KW_NAMES] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
845845
[CALL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
846-
[CALL_BOUND_METHOD_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
846+
[CALL_BOUND_METHOD_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
847847
[CALL_PY_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
848848
[CALL_PY_WITH_DEFAULTS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
849849
[CALL_NO_KW_TYPE_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
 (0)