Skip to content

Commit 410e297

Browse files
committed
Revert "gh-153486: Specialize negative list int subscripts"
This reverts commit 7b711cc.
1 parent ea05f8d commit 410e297

6 files changed

Lines changed: 23 additions & 27 deletions

File tree

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_testinternalcapi/test_cases.c.h

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

Python/bytecodes.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,8 @@ dummy_func(
11341134
macro(STORE_SLICE) = _SPECIALIZE_STORE_SLICE + _STORE_SLICE;
11351135

11361136
macro(BINARY_OP_SUBSCR_LIST_INT) =
1137-
_GUARD_TOS_INT + _GUARD_NOS_LIST + unused/5 +
1138-
_BINARY_OP_SUBSCR_LIST_INT + _POP_TOP_INT + POP_TOP;
1137+
_GUARD_TOS_NON_NEGATIVE_COMPACT_INT + _GUARD_NOS_LIST +
1138+
unused/5 + _BINARY_OP_SUBSCR_LIST_INT + _POP_TOP_INT + POP_TOP;
11391139

11401140
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res, ls, ss)) {
11411141
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
@@ -1145,9 +1145,6 @@ dummy_func(
11451145
assert(PyList_CheckExact(list));
11461146

11471147
Py_ssize_t index = _PyLong_CompactValue((PyLongObject *)sub);
1148-
if (index < 0) {
1149-
index += PyList_GET_SIZE(list);
1150-
}
11511148
#ifdef Py_GIL_DISABLED
11521149
PyObject *res_o = _PyList_GetItemRef((PyListObject*)list, index);
11531150
EXIT_IF(res_o == NULL);

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/specialize.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,9 +2015,7 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
20152015
return SPEC_FAIL_BINARY_OP_XOR;
20162016
case NB_SUBSCR:
20172017
if (PyList_CheckExact(lhs)) {
2018-
if (PyLong_CheckExact(rhs) &&
2019-
!_PyLong_CheckExactAndCompact(rhs))
2020-
{
2018+
if (PyLong_CheckExact(rhs) && !_PyLong_IsNonNegativeCompact((PyLongObject *)rhs)) {
20212019
return SPEC_FAIL_OUT_OF_RANGE;
20222020
}
20232021
if (PySlice_Check(rhs)) {
@@ -2400,16 +2398,16 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
24002398
}
24012399
break;
24022400
case NB_SUBSCR:
2403-
if (_PyLong_CheckExactAndCompact(rhs) && PyList_CheckExact(lhs)) {
2404-
specialize(instr, BINARY_OP_SUBSCR_LIST_INT);
2405-
return;
2406-
}
24072401
if (PyLong_CheckExact(rhs) && _PyLong_IsNonNegativeCompact((PyLongObject *)rhs)) {
2402+
if (PyList_CheckExact(lhs)) {
2403+
specialize(instr, BINARY_OP_SUBSCR_LIST_INT);
2404+
return;
2405+
}
24082406
if (PyTuple_CheckExact(lhs)) {
24092407
specialize(instr, BINARY_OP_SUBSCR_TUPLE_INT);
24102408
return;
24112409
}
2412-
if (PyUnicode_CheckExact(lhs)) {
2410+
if (PyUnicode_CheckExact(lhs) && _PyLong_IsNonNegativeCompact((PyLongObject*)rhs)) {
24132411
if (PyUnicode_IS_COMPACT_ASCII(lhs)) {
24142412
specialize(instr, BINARY_OP_SUBSCR_STR_INT);
24152413
return;

0 commit comments

Comments
 (0)