Skip to content

Commit 80a6ead

Browse files
committed
reduced to _UNPACK_SEQUENCE_TWO_TUPLE
1 parent 2b2d04e commit 80a6ead

File tree

9 files changed

+70
-171
lines changed

9 files changed

+70
-171
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_ids.h

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

Include/internal/pycore_uop_metadata.h

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

Lib/test/test_capi/test_opt.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -440,23 +440,6 @@ def testfunc(n, m):
440440
uops = get_opnames(ex)
441441
self.assertIn("_FOR_ITER_TIER_TWO", uops)
442442

443-
def test_unpack_sequence_generic(self):
444-
def testfunc(x):
445-
i = 0
446-
while i < x:
447-
i += 1
448-
# Use an iterator to force generic UNPACK_SEQUENCE
449-
a, b = iter((1, 2))
450-
return a, b
451-
452-
res = testfunc(TIER2_THRESHOLD)
453-
self.assertEqual(res, (1, 2))
454-
455-
ex = get_first_executor(testfunc)
456-
self.assertIsNotNone(ex)
457-
uops = get_opnames(ex)
458-
self.assertIn("_UNPACK_SEQUENCE", uops)
459-
460443
def test_unpack_sequence_two_tuple(self):
461444
def testfunc(x):
462445
i = 0
@@ -475,40 +458,6 @@ def testfunc(x):
475458
self.assertIn("_UNPACK_SEQUENCE_TWO_TUPLE", uops)
476459
self.assertNotIn("_POP_TOP", uops)
477460

478-
def test_unpack_sequence_tuple(self):
479-
def testfunc(x):
480-
i = 0
481-
while i < x:
482-
i += 1
483-
t = (i, i, i)
484-
a, b, c = t
485-
return a, b, c
486-
487-
res = testfunc(TIER2_THRESHOLD)
488-
self.assertEqual(res, (TIER2_THRESHOLD, TIER2_THRESHOLD, TIER2_THRESHOLD))
489-
490-
ex = get_first_executor(testfunc)
491-
self.assertIsNotNone(ex)
492-
uops = get_opnames(ex)
493-
self.assertIn("_UNPACK_SEQUENCE_TUPLE", uops)
494-
self.assertNotIn("_POP_TOP", uops)
495-
496-
def test_unpack_sequence_list(self):
497-
def testfunc(x):
498-
i = 0
499-
while i < x:
500-
i += 1
501-
a, b = [1, 2]
502-
return a, b
503-
504-
res = testfunc(TIER2_THRESHOLD)
505-
self.assertEqual(res, (1, 2))
506-
507-
ex = get_first_executor(testfunc)
508-
self.assertIsNotNone(ex)
509-
uops = get_opnames(ex)
510-
self.assertIn("_UNPACK_SEQUENCE_LIST", uops)
511-
512461

513462
@requires_specialization
514463
@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")

Python/bytecodes.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,18 +1588,14 @@ dummy_func(
15881588
(void)counter;
15891589
}
15901590

1591-
op(_UNPACK_SEQUENCE, (seq -- unused[oparg], top[0], s)) {
1592-
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
1591+
op(_UNPACK_SEQUENCE, (seq -- unused[oparg], top[0])) {
1592+
PyObject *seq_o = PyStackRef_AsPyObjectSteal(seq);
15931593
int res = _PyEval_UnpackIterableStackRef(tstate, seq_o, oparg, -1, top);
1594-
if (res == 0) {
1595-
PyStackRef_CLOSE(seq);
1596-
ERROR_IF(1);
1597-
}
1598-
s = seq;
1599-
INPUTS_DEAD();
1594+
Py_DECREF(seq_o);
1595+
ERROR_IF(res == 0);
16001596
}
16011597

1602-
macro(UNPACK_SEQUENCE) = _SPECIALIZE_UNPACK_SEQUENCE + _UNPACK_SEQUENCE + POP_TOP;
1598+
macro(UNPACK_SEQUENCE) = _SPECIALIZE_UNPACK_SEQUENCE + _UNPACK_SEQUENCE;
16031599

16041600
macro(UNPACK_SEQUENCE_TWO_TUPLE) =
16051601
_GUARD_TOS_TUPLE + unused/1 + _UNPACK_SEQUENCE_TWO_TUPLE + POP_TOP;
@@ -1616,10 +1612,10 @@ dummy_func(
16161612
INPUTS_DEAD();
16171613
}
16181614

1619-
macro(UNPACK_SEQUENCE_TUPLE) =
1620-
_GUARD_TOS_TUPLE + unused/1 + _UNPACK_SEQUENCE_TUPLE + POP_TOP;
1615+
macro(UNPACK_SEQUENCE_TUPLE) =
1616+
_GUARD_TOS_TUPLE + unused/1 + _UNPACK_SEQUENCE_TUPLE;
16211617

1622-
op(_UNPACK_SEQUENCE_TUPLE, (seq -- values[oparg], s)) {
1618+
op(_UNPACK_SEQUENCE_TUPLE, (seq -- values[oparg])) {
16231619
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
16241620
assert(PyTuple_CheckExact(seq_o));
16251621
DEOPT_IF(PyTuple_GET_SIZE(seq_o) != oparg);
@@ -1628,14 +1624,13 @@ dummy_func(
16281624
for (int i = oparg; --i >= 0; ) {
16291625
*values++ = PyStackRef_FromPyObjectNew(items[i]);
16301626
}
1631-
s = seq;
1632-
INPUTS_DEAD();
1627+
DECREF_INPUTS();
16331628
}
16341629

16351630
macro(UNPACK_SEQUENCE_LIST) =
1636-
_GUARD_TOS_LIST + unused/1 + _UNPACK_SEQUENCE_LIST + POP_TOP;
1631+
_GUARD_TOS_LIST + unused/1 + _UNPACK_SEQUENCE_LIST;
16371632

1638-
op(_UNPACK_SEQUENCE_LIST, (seq -- values[oparg], s)) {
1633+
op(_UNPACK_SEQUENCE_LIST, (seq -- values[oparg])) {
16391634
PyObject *seq_o = PyStackRef_AsPyObjectBorrow(seq);
16401635
assert(PyList_CheckExact(seq_o));
16411636
DEOPT_IF(!LOCK_OBJECT(seq_o));
@@ -1649,8 +1644,7 @@ dummy_func(
16491644
*values++ = PyStackRef_FromPyObjectNew(items[i]);
16501645
}
16511646
UNLOCK_OBJECT(seq_o);
1652-
s = seq;
1653-
INPUTS_DEAD();
1647+
DECREF_INPUTS();
16541648
}
16551649

16561650
inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8], top[0])) {

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)