File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3536,37 +3536,43 @@ def test_is_none(n):
35363536
35373537 def test_is_true_narrows_to_constant (self ):
35383538 def f (n ):
3539+ def return_true ():
3540+ return True
3541+
35393542 hits = 0
3543+ v = return_true ()
35403544 for i in range (n ):
3541- v = True if i != TIER2_THRESHOLD else - 1
35423545 if v is True :
3543- # Redundant after narrowing
3544- if v is True :
3545- hits += 1
3546+ hits += v + 1
35463547 return hits
35473548
35483549 res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
3549- self .assertEqual (res , TIER2_THRESHOLD )
3550+ self .assertEqual (res , TIER2_THRESHOLD * 2 )
35503551 self .assertIsNotNone (ex )
3552+ uops = get_opnames (ex )
35513553
3552- self .assertLessEqual (count_ops (ex , "_IS_OP" ), 1 )
3554+ # v + 1 should be constant folded
3555+ self .assertNotIn ("_BINARY_OP" , uops )
35533556
35543557 def test_is_false_narrows_to_constant (self ):
35553558 def f (n ):
3559+ def return_false ():
3560+ return False
3561+
35563562 hits = 0
3563+ v = return_false ()
35573564 for i in range (n ):
3558- v = False if i != TIER2_THRESHOLD else - 1
35593565 if v is False :
3560- # Redundant after narrowing
3561- if v is False :
3562- hits += 1
3566+ hits += v + 1
35633567 return hits
35643568
35653569 res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
35663570 self .assertEqual (res , TIER2_THRESHOLD )
35673571 self .assertIsNotNone (ex )
3572+ uops = get_opnames (ex )
35683573
3569- self .assertLessEqual (count_ops (ex , "_IS_OP" ), 1 )
3574+ # v + 1 should be constant folded
3575+ self .assertNotIn ("_BINARY_OP" , uops )
35703576
35713577 def test_for_iter_gen_frame (self ):
35723578 def f (n ):
You can’t perform that action at this time.
0 commit comments