Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reduced to _UNPACK_SEQUENCE_TWO_TUPLE
  • Loading branch information
cocolato committed Jan 2, 2026
commit 80a6ead496b1b64012607279a4e8fc9c9b304e6e
6 changes: 3 additions & 3 deletions Include/internal/pycore_opcode_metadata.h

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

9 changes: 5 additions & 4 deletions Include/internal/pycore_uop_ids.h

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

22 changes: 11 additions & 11 deletions Include/internal/pycore_uop_metadata.h

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

51 changes: 0 additions & 51 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,23 +440,6 @@ def testfunc(n, m):
uops = get_opnames(ex)
self.assertIn("_FOR_ITER_TIER_TWO", uops)

def test_unpack_sequence_generic(self):
def testfunc(x):
i = 0
while i < x:
i += 1
# Use an iterator to force generic UNPACK_SEQUENCE
a, b = iter((1, 2))
return a, b

res = testfunc(TIER2_THRESHOLD)
self.assertEqual(res, (1, 2))

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_UNPACK_SEQUENCE", uops)

def test_unpack_sequence_two_tuple(self):
def testfunc(x):
i = 0
Expand All @@ -475,40 +458,6 @@ def testfunc(x):
self.assertIn("_UNPACK_SEQUENCE_TWO_TUPLE", uops)
self.assertNotIn("_POP_TOP", uops)

def test_unpack_sequence_tuple(self):
def testfunc(x):
i = 0
while i < x:
i += 1
t = (i, i, i)
a, b, c = t
return a, b, c

res = testfunc(TIER2_THRESHOLD)
self.assertEqual(res, (TIER2_THRESHOLD, TIER2_THRESHOLD, TIER2_THRESHOLD))

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_UNPACK_SEQUENCE_TUPLE", uops)
self.assertNotIn("_POP_TOP", uops)

def test_unpack_sequence_list(self):
def testfunc(x):
i = 0
while i < x:
i += 1
a, b = [1, 2]
return a, b

res = testfunc(TIER2_THRESHOLD)
self.assertEqual(res, (1, 2))

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_UNPACK_SEQUENCE_LIST", uops)


@requires_specialization
@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
Expand Down
30 changes: 12 additions & 18 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1588,18 +1588,14 @@ dummy_func(
(void)counter;
}

op(_UNPACK_SEQUENCE, (seq -- unused[oparg], top[0], s)) {
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
op(_UNPACK_SEQUENCE, (seq -- unused[oparg], top[0])) {
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg, -1, top);
if (res == 0) {
PyStackRef_CLOSE(seq);
ERROR_IF(1);
}
s = seq;
INPUTS_DEAD();
Py_DECREF(seq_o);
ERROR_IF(res == 0);
}

macro(UNPACK_SEQUENCE) = _SPECIALIZE_UNPACK_SEQUENCE + _UNPACK_SEQUENCE + POP_TOP;
macro(UNPACK_SEQUENCE) = _SPECIALIZE_UNPACK_SEQUENCE + _UNPACK_SEQUENCE;

macro(UNPACK_SEQUENCE_TWO_TUPLE) =
_GUARD_TOS_TUPLE + unused/1 + _UNPACK_SEQUENCE_TWO_TUPLE + POP_TOP;
Expand All @@ -1616,10 +1612,10 @@ dummy_func(
INPUTS_DEAD();
}

macro(UNPACK_SEQUENCE_TUPLE) =
_GUARD_TOS_TUPLE + unused/1 + _UNPACK_SEQUENCE_TUPLE + POP_TOP;
macro(UNPACK_SEQUENCE_TUPLE) =
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
_GUARD_TOS_TUPLE + unused/1 + _UNPACK_SEQUENCE_TUPLE;

op(_UNPACK_SEQUENCE_TUPLE, (seq -- values[oparg], s)) {
op(_UNPACK_SEQUENCE_TUPLE, (seq -- values[oparg])) {
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
assert(PyTuple_CheckExact(seq_o));
DEOPT_IF(PyTuple_GET_SIZE(seq_o) != oparg);
Expand All @@ -1628,14 +1624,13 @@ dummy_func(
for (int i = oparg; --i >= 0; ) {
*values++ = PyStackRef_FromPyObjectNew(items[i]);
}
s = seq;
INPUTS_DEAD();
DECREF_INPUTS();
}

macro(UNPACK_SEQUENCE_LIST) =
_GUARD_TOS_LIST + unused/1 + _UNPACK_SEQUENCE_LIST + POP_TOP;
_GUARD_TOS_LIST + unused/1 + _UNPACK_SEQUENCE_LIST;

op(_UNPACK_SEQUENCE_LIST, (seq -- values[oparg], s)) {
op(_UNPACK_SEQUENCE_LIST, (seq -- values[oparg])) {
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
assert(PyList_CheckExact(seq_o));
DEOPT_IF(!LOCK_OBJECT(seq_o));
Expand All @@ -1649,8 +1644,7 @@ dummy_func(
*values++ = PyStackRef_FromPyObjectNew(items[i]);
}
UNLOCK_OBJECT(seq_o);
s = seq;
INPUTS_DEAD();
DECREF_INPUTS();
}

inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8], top[0])) {
Expand Down
47 changes: 22 additions & 25 deletions Python/executor_cases.c.h

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

Loading
Loading