Skip to content

Commit 181d096

Browse files
committed
Add failing regression tests
1 parent 2873c31 commit 181d096

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lib/test/test_capi/test_opt.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,40 @@ def test_is_none(n):
35343534
self.assertIn("_POP_TOP_NOP", uops)
35353535
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
35363536

3537+
def test_is_true_narrows_to_constant(self):
3538+
def f(n):
3539+
hits = 0
3540+
for i in range(n):
3541+
v = True if i != TIER2_THRESHOLD else -1
3542+
if v is True:
3543+
# Redundant after narrowing
3544+
if v is True:
3545+
hits += 1
3546+
return hits
3547+
3548+
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
3549+
self.assertEqual(res, TIER2_THRESHOLD)
3550+
self.assertIsNotNone(ex)
3551+
3552+
self.assertLessEqual(count_ops(ex, "_IS_OP"), 1)
3553+
3554+
def test_is_false_narrows_to_constant(self):
3555+
def f(n):
3556+
hits = 0
3557+
for i in range(n):
3558+
v = False if i != TIER2_THRESHOLD else -1
3559+
if v is False:
3560+
# Redundant after narrowing
3561+
if v is False:
3562+
hits += 1
3563+
return hits
3564+
3565+
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
3566+
self.assertEqual(res, TIER2_THRESHOLD)
3567+
self.assertIsNotNone(ex)
3568+
3569+
self.assertLessEqual(count_ops(ex, "_IS_OP"), 1)
3570+
35373571
def test_for_iter_gen_frame(self):
35383572
def f(n):
35393573
for i in range(n):

0 commit comments

Comments
 (0)