Skip to content

Commit 80c1c6c

Browse files
committed
Add failing regression test for _TO_BOOL_STR
1 parent 7afa476 commit 80c1c6c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,39 @@ def f(n):
14991499
# But all of the appends we care about are still there:
15001500
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
15011501

1502+
def test_narrow_type_to_constant_str_empty(self):
1503+
def f(n):
1504+
trace = []
1505+
for i in range(n):
1506+
empty = ""
1507+
# Hopefully the optimizer can't guess what the value is.
1508+
# f is always "", but we can only prove that it's a string:
1509+
f = empty + empty
1510+
trace.append("A")
1511+
if not f: # Kept.
1512+
trace.append("B")
1513+
if not f: # Removed!
1514+
trace.append("C")
1515+
trace.append("D")
1516+
if f: # Removed!
1517+
trace.append("X")
1518+
trace.append("E")
1519+
trace.append("F")
1520+
if f: # Removed!
1521+
trace.append("X")
1522+
trace.append("G")
1523+
return trace
1524+
1525+
trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
1526+
self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD)
1527+
self.assertIsNotNone(ex)
1528+
uops = get_opnames(ex)
1529+
# Only one guard remains:
1530+
self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 1)
1531+
self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 0)
1532+
# But all of the appends we care about are still there:
1533+
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
1534+
15021535

15031536
def global_identity(x):
15041537
return x

0 commit comments

Comments
 (0)