Skip to content

Commit 6860ed7

Browse files
committed
Make BINARY_OP_INPLACE_ADD_UNICODE a legit super instruction
This doesn't really make things much cleaner, but it works.
1 parent acf9184 commit 6860ed7

File tree

2 files changed

+54
-44
lines changed

2 files changed

+54
-44
lines changed

Python/bytecodes.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static PyObject *value, *value1, *value2, *left, *right, *res, *sum, *prod, *sub
8383
static PyObject *container, *start, *stop, *v, *lhs, *rhs;
8484
static PyObject *list, *tuple, *dict;
8585
static PyObject *exit_func, *lasti, *val;
86+
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_1 1
87+
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_2 2
8688

8789
static PyObject *
8890
dummy_func(
@@ -197,7 +199,7 @@ dummy_func(
197199
BINARY_OP_ADD_FLOAT,
198200
BINARY_OP_ADD_INT,
199201
BINARY_OP_ADD_UNICODE,
200-
// BINARY_OP_INPLACE_ADD_UNICODE, // This is an odd duck.
202+
_BINARY_OP_INPLACE_ADD_UNICODE_PART_1,
201203
BINARY_OP_MULTIPLY_FLOAT,
202204
BINARY_OP_MULTIPLY_INT,
203205
BINARY_OP_SUBTRACT_FLOAT,
@@ -263,13 +265,10 @@ dummy_func(
263265
ERROR_IF(res == NULL, error);
264266
}
265267

266-
// This is a subtle one. It's a super-instruction for
267-
// BINARY_OP_ADD_UNICODE followed by STORE_FAST
268-
// where the store goes into the left argument.
269-
// So the inputs are the same as for all BINARY_OP
270-
// specializations, but there is no output.
271-
// At the end we just skip over the STORE_FAST.
272-
inst(BINARY_OP_INPLACE_ADD_UNICODE, (left, right --)) {
268+
// Part 1's output effect is a lie -- it has no result.
269+
// Part 2's input effect is equally a lie, and the two lies
270+
// cancel each other out.
271+
op(_BINARY_OP_INPLACE_ADD_UNICODE_PART_1, (left, right, unused/1 -- unused)) {
273272
assert(cframe.use_tracing == 0);
274273
DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
275274
DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
@@ -295,9 +294,12 @@ dummy_func(
295294
PyUnicode_Append(target_local, right);
296295
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
297296
ERROR_IF(*target_local == NULL, error);
298-
// The STORE_FAST is already done.
299-
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP + 1);
300297
}
298+
op(_BINARY_OP_INPLACE_ADD_UNICODE_PART_2, (unused --)) {
299+
// The STORE_FAST is already done; oparg is dead.
300+
}
301+
super(BINARY_OP_INPLACE_ADD_UNICODE) =
302+
_BINARY_OP_INPLACE_ADD_UNICODE_PART_1 + _BINARY_OP_INPLACE_ADD_UNICODE_PART_2;
301303

302304
inst(BINARY_OP_ADD_FLOAT, (left, right, unused/1 -- sum)) {
303305
assert(cframe.use_tracing == 0);

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)