FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-46329: Split calls into precall and call instructions. by markshannon · Pull Request #30855 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bd00f82
Add PRECALL_FUNCTION opcode.
markshannon Jan 5, 2022
78e6da5
Move all call-shape variables into a struct.
markshannon Jan 6, 2022
42c0460
Move 'call shape' varaibles into struct.
markshannon Jan 7, 2022
a947bf1
Replace CALL_NO_KW and CALL_KW with KW_NAMES and CALL instructions.
markshannon Jan 7, 2022
dbab710
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 7, 2022
f47f8a1
Remove named_args from call_shape struct.
markshannon Jan 7, 2022
7ea553f
Handle bound-methods in PRECALL instructions.
markshannon Jan 7, 2022
0b52de2
Restore specialization of calls to builtin functions.
markshannon Jan 10, 2022
d2e5834
Get specialized versions of CALL working again.
markshannon Jan 11, 2022
6785a3b
Fix test_dis
markshannon Jan 11, 2022
5935a5c
Fix a couple of compiler warnings.
markshannon Jan 11, 2022
e39432f
Specialize for calls to builtin types with any number of arguments.
markshannon Jan 12, 2022
637f5e0
Refine fail stats for calls to classes.
markshannon Jan 12, 2022
28663f4
Refine fail stats for calls.
markshannon Jan 12, 2022
0239c26
Specialize for calls to method-descriptors of the shape obj.meth()
markshannon Jan 12, 2022
e076297
Refine fail stats for calls.
markshannon Jan 12, 2022
d74939c
Factor out bound-method handling code.
markshannon Jan 13, 2022
1294c5e
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 13, 2022
3323b3b
Specialize for builtin methods taking using the METH_FASTCALL | METH_…
markshannon Jan 13, 2022
32dbf1a
Allow kwnames for specialized calls to builtin types.
markshannon Jan 13, 2022
bdf9f15
Specialize calls to tuple() and str().
markshannon Jan 14, 2022
c285be8
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 21, 2022
918b390
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 21, 2022
a77e63e
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 22, 2022
cb5301d
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 24, 2022
100a5f6
Fix test_dis
markshannon Jan 24, 2022
4c2da8b
Fix specialization of method descriptors.
markshannon Jan 24, 2022
a7d7b1e
Move check for bound-methods from PRECALL opcodes back to CALL opcode.
markshannon Jan 24, 2022
43fdcdf
Relax check in CALL_NO_KW_LIST_APPEND to any list subclass.
markshannon Jan 24, 2022
5d35ce3
Correct name of CallShape field.
markshannon Jan 24, 2022
639adb8
Add news item.
markshannon Jan 25, 2022
6914240
Minor tidy ups.
markshannon Jan 25, 2022
3478c55
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 25, 2022
2cb70ad
Fix typos in news item.
markshannon Jan 27, 2022
61ef1b4
Address review comments.
markshannon Jan 27, 2022
4035699
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 27, 2022
38ebe7c
Update docs for new opcodes.
markshannon Jan 27, 2022
ddc2f57
Fix up formatting
markshannon Jan 27, 2022
28a810d
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 27, 2022
d4f710c
Fix up test_dis
markshannon Jan 27, 2022
2fa70a0
Address review comments.
markshannon Jan 27, 2022
2b59fc9
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 27, 2022
5cb8d58
Merge branch 'main' into split-calls-into-precall-and-call-part-2
markshannon Jan 27, 2022
bd77c5d
Clarify ownership of callable in CallShape.
markshannon Jan 28, 2022
3ac2ed8
Fix comment.
markshannon Jan 28, 2022
File filter

Filter by extension

Filter by extension .c  (2) .h  (3) .py  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Next Next commit
Add PRECALL_FUNCTION opcode.
  • Loading branch information
markshannon committed Jan 5, 2022
commit bd00f828b0091b71f23de067426b9c3df0b95dba
1 change: 1 addition & 0 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Lib/opcode.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
61 changes: 31 additions & 30 deletions Programs/test_frozenmain.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 14 additions & 17 deletions Python/ceval.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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]));
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions Python/compile.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Python/opcode_targets.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


Back | FazBrowse Home | New Git URL