mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
GH-122160: Remove BUILD_CONST_KEY_MAP opcode. (GH-122164)
This commit is contained in:
parent
9bb2e4623f
commit
2e14a52cce
16 changed files with 306 additions and 478 deletions
|
@ -1882,25 +1882,6 @@ dummy_func(
|
|||
}
|
||||
}
|
||||
|
||||
inst(BUILD_CONST_KEY_MAP, (values[oparg], keys -- map)) {
|
||||
PyObject *keys_o = PyStackRef_AsPyObjectBorrow(keys);
|
||||
|
||||
assert(PyTuple_CheckExact(keys_o));
|
||||
assert(PyTuple_GET_SIZE(keys_o) == (Py_ssize_t)oparg);
|
||||
STACKREFS_TO_PYOBJECTS(values, oparg, values_o);
|
||||
if (CONVERSION_FAILED(values_o)) {
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
PyObject *map_o = _PyDict_FromItems(
|
||||
&PyTuple_GET_ITEM(keys_o, 0), 1,
|
||||
values_o, 1, oparg);
|
||||
STACKREFS_TO_PYOBJECTS_CLEANUP(values_o);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(map_o == NULL, error);
|
||||
map = PyStackRef_FromPyObjectSteal(map_o);
|
||||
}
|
||||
|
||||
inst(DICT_UPDATE, (dict, unused[oparg - 1], update -- dict, unused[oparg - 1])) {
|
||||
PyObject *dict_o = PyStackRef_AsPyObjectBorrow(dict);
|
||||
PyObject *update_o = PyStackRef_AsPyObjectBorrow(update);
|
||||
|
|
|
@ -1759,42 +1759,24 @@ compiler_kwonlydefaults(struct compiler *c, location loc,
|
|||
*/
|
||||
int i;
|
||||
PyObject *keys = NULL;
|
||||
|
||||
int default_count = 0;
|
||||
for (i = 0; i < asdl_seq_LEN(kwonlyargs); i++) {
|
||||
arg_ty arg = asdl_seq_GET(kwonlyargs, i);
|
||||
expr_ty default_ = asdl_seq_GET(kw_defaults, i);
|
||||
if (default_) {
|
||||
default_count++;
|
||||
PyObject *mangled = compiler_maybe_mangle(c, arg->arg);
|
||||
if (!mangled) {
|
||||
goto error;
|
||||
}
|
||||
if (keys == NULL) {
|
||||
keys = PyList_New(1);
|
||||
if (keys == NULL) {
|
||||
Py_DECREF(mangled);
|
||||
return ERROR;
|
||||
}
|
||||
PyList_SET_ITEM(keys, 0, mangled);
|
||||
}
|
||||
else {
|
||||
int res = PyList_Append(keys, mangled);
|
||||
Py_DECREF(mangled);
|
||||
if (res == -1) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
ADDOP_LOAD_CONST_NEW(c, loc, mangled);
|
||||
if (compiler_visit_expr(c, default_) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keys != NULL) {
|
||||
Py_ssize_t default_count = PyList_GET_SIZE(keys);
|
||||
PyObject *keys_tuple = PyList_AsTuple(keys);
|
||||
Py_DECREF(keys);
|
||||
ADDOP_LOAD_CONST_NEW(c, loc, keys_tuple);
|
||||
ADDOP_I(c, loc, BUILD_CONST_KEY_MAP, default_count);
|
||||
assert(default_count > 0);
|
||||
if (default_count) {
|
||||
ADDOP_I(c, loc, BUILD_MAP, default_count);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
@ -4454,25 +4436,8 @@ static int
|
|||
compiler_subdict(struct compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end)
|
||||
{
|
||||
Py_ssize_t i, n = end - begin;
|
||||
PyObject *keys, *key;
|
||||
int big = n*2 > STACK_USE_GUIDELINE;
|
||||
location loc = LOC(e);
|
||||
if (n > 1 && !big && are_all_items_const(e->v.Dict.keys, begin, end)) {
|
||||
for (i = begin; i < end; i++) {
|
||||
VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.values, i));
|
||||
}
|
||||
keys = PyTuple_New(n);
|
||||
if (keys == NULL) {
|
||||
return SUCCESS;
|
||||
}
|
||||
for (i = begin; i < end; i++) {
|
||||
key = ((expr_ty)asdl_seq_GET(e->v.Dict.keys, i))->v.Constant.value;
|
||||
PyTuple_SET_ITEM(keys, i - begin, Py_NewRef(key));
|
||||
}
|
||||
ADDOP_LOAD_CONST_NEW(c, loc, keys);
|
||||
ADDOP_I(c, loc, BUILD_CONST_KEY_MAP, n);
|
||||
return SUCCESS;
|
||||
}
|
||||
if (big) {
|
||||
ADDOP_I(c, loc, BUILD_MAP, 0);
|
||||
}
|
||||
|
@ -5032,26 +4997,8 @@ compiler_subkwargs(struct compiler *c, location loc,
|
|||
{
|
||||
Py_ssize_t i, n = end - begin;
|
||||
keyword_ty kw;
|
||||
PyObject *keys, *key;
|
||||
assert(n > 0);
|
||||
int big = n*2 > STACK_USE_GUIDELINE;
|
||||
if (n > 1 && !big) {
|
||||
for (i = begin; i < end; i++) {
|
||||
kw = asdl_seq_GET(keywords, i);
|
||||
VISIT(c, expr, kw->value);
|
||||
}
|
||||
keys = PyTuple_New(n);
|
||||
if (keys == NULL) {
|
||||
return ERROR;
|
||||
}
|
||||
for (i = begin; i < end; i++) {
|
||||
key = ((keyword_ty) asdl_seq_GET(keywords, i))->arg;
|
||||
PyTuple_SET_ITEM(keys, i - begin, Py_NewRef(key));
|
||||
}
|
||||
ADDOP_LOAD_CONST_NEW(c, loc, keys);
|
||||
ADDOP_I(c, loc, BUILD_CONST_KEY_MAP, n);
|
||||
return SUCCESS;
|
||||
}
|
||||
if (big) {
|
||||
ADDOP_I(c, NO_LOCATION, BUILD_MAP, 0);
|
||||
}
|
||||
|
|
34
Python/executor_cases.c.h
generated
34
Python/executor_cases.c.h
generated
|
@ -2028,40 +2028,6 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _BUILD_CONST_KEY_MAP: {
|
||||
_PyStackRef keys;
|
||||
_PyStackRef *values;
|
||||
_PyStackRef map;
|
||||
oparg = CURRENT_OPARG();
|
||||
keys = stack_pointer[-1];
|
||||
values = &stack_pointer[-1 - oparg];
|
||||
PyObject *keys_o = PyStackRef_AsPyObjectBorrow(keys);
|
||||
assert(PyTuple_CheckExact(keys_o));
|
||||
assert(PyTuple_GET_SIZE(keys_o) == (Py_ssize_t)oparg);
|
||||
STACKREFS_TO_PYOBJECTS(values, oparg, values_o);
|
||||
if (CONVERSION_FAILED(values_o)) {
|
||||
for (int _i = oparg; --_i >= 0;) {
|
||||
PyStackRef_CLOSE(values[_i]);
|
||||
}
|
||||
PyStackRef_CLOSE(keys);
|
||||
if (true) JUMP_TO_ERROR();
|
||||
}
|
||||
PyObject *map_o = _PyDict_FromItems(
|
||||
&PyTuple_GET_ITEM(keys_o, 0), 1,
|
||||
values_o, 1, oparg);
|
||||
STACKREFS_TO_PYOBJECTS_CLEANUP(values_o);
|
||||
for (int _i = oparg; --_i >= 0;) {
|
||||
PyStackRef_CLOSE(values[_i]);
|
||||
}
|
||||
PyStackRef_CLOSE(keys);
|
||||
if (map_o == NULL) JUMP_TO_ERROR();
|
||||
map = PyStackRef_FromPyObjectSteal(map_o);
|
||||
stack_pointer[-1 - oparg] = map;
|
||||
stack_pointer += -oparg;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
break;
|
||||
}
|
||||
|
||||
case _DICT_UPDATE: {
|
||||
_PyStackRef update;
|
||||
_PyStackRef dict;
|
||||
|
|
36
Python/generated_cases.c.h
generated
36
Python/generated_cases.c.h
generated
|
@ -589,42 +589,6 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BUILD_CONST_KEY_MAP) {
|
||||
frame->instr_ptr = next_instr;
|
||||
next_instr += 1;
|
||||
INSTRUCTION_STATS(BUILD_CONST_KEY_MAP);
|
||||
_PyStackRef *values;
|
||||
_PyStackRef keys;
|
||||
_PyStackRef map;
|
||||
keys = stack_pointer[-1];
|
||||
values = &stack_pointer[-1 - oparg];
|
||||
PyObject *keys_o = PyStackRef_AsPyObjectBorrow(keys);
|
||||
assert(PyTuple_CheckExact(keys_o));
|
||||
assert(PyTuple_GET_SIZE(keys_o) == (Py_ssize_t)oparg);
|
||||
STACKREFS_TO_PYOBJECTS(values, oparg, values_o);
|
||||
if (CONVERSION_FAILED(values_o)) {
|
||||
for (int _i = oparg; --_i >= 0;) {
|
||||
PyStackRef_CLOSE(values[_i]);
|
||||
}
|
||||
PyStackRef_CLOSE(keys);
|
||||
if (true) { stack_pointer += -1 - oparg; goto error; }
|
||||
}
|
||||
PyObject *map_o = _PyDict_FromItems(
|
||||
&PyTuple_GET_ITEM(keys_o, 0), 1,
|
||||
values_o, 1, oparg);
|
||||
STACKREFS_TO_PYOBJECTS_CLEANUP(values_o);
|
||||
for (int _i = oparg; --_i >= 0;) {
|
||||
PyStackRef_CLOSE(values[_i]);
|
||||
}
|
||||
PyStackRef_CLOSE(keys);
|
||||
if (map_o == NULL) { stack_pointer += -1 - oparg; goto error; }
|
||||
map = PyStackRef_FromPyObjectSteal(map_o);
|
||||
stack_pointer[-1 - oparg] = map;
|
||||
stack_pointer += -oparg;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BUILD_LIST) {
|
||||
frame->instr_ptr = next_instr;
|
||||
next_instr += 1;
|
||||
|
|
2
Python/opcode_targets.h
generated
2
Python/opcode_targets.h
generated
|
@ -42,7 +42,6 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_UNARY_NOT,
|
||||
&&TARGET_WITH_EXCEPT_START,
|
||||
&&TARGET_BINARY_OP,
|
||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||
&&TARGET_BUILD_LIST,
|
||||
&&TARGET_BUILD_MAP,
|
||||
&&TARGET_BUILD_SET,
|
||||
|
@ -148,6 +147,7 @@ static void *opcode_targets[256] = {
|
|||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_RESUME,
|
||||
&&TARGET_BINARY_OP_ADD_FLOAT,
|
||||
&&TARGET_BINARY_OP_ADD_INT,
|
||||
|
|
9
Python/optimizer_cases.c.h
generated
9
Python/optimizer_cases.c.h
generated
|
@ -943,15 +943,6 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _BUILD_CONST_KEY_MAP: {
|
||||
_Py_UopsSymbol *map;
|
||||
map = sym_new_not_null(ctx);
|
||||
stack_pointer[-1 - oparg] = map;
|
||||
stack_pointer += -oparg;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
break;
|
||||
}
|
||||
|
||||
case _DICT_UPDATE: {
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue