@@ -4819,6 +4819,46 @@ def f(n):
48194819 # Every element must be False: the set is empty after discard()
48204820 self .assertTrue (all (r is False for r in res ))
48214821
4822+ def _check_to_bool_recorded_type (self , inner , value , guard_op ):
4823+ """Recorded-type path: a value whose static type is unknown but whose
4824+ runtime type is recorded should emit `guard_op` + _TO_BOOL_SIZED."""
4825+ self .assertEqual (inner (value ), TIER2_THRESHOLD )
4826+ ex_inner = get_first_executor (inner )
4827+ self .assertIsNotNone (ex_inner )
4828+ uops = get_opnames (ex_inner )
4829+ self .assertIn (guard_op , uops )
4830+ self .assertIn ("_TO_BOOL_SIZED" , uops )
4831+ self .assertNotIn ("_TO_BOOL" , uops )
4832+
4833+ def test_to_bool_bytes (self ):
4834+ def inner (v ):
4835+ cnt = 0
4836+ for _ in range (TIER2_THRESHOLD ):
4837+ if v :
4838+ cnt += 1
4839+ return cnt
4840+ self ._check_to_bool_recorded_type (inner , b"hello" , "_GUARD_TOS_BYTES" )
4841+
4842+ def test_to_bool_bytearray (self ):
4843+ def inner (v ):
4844+ cnt = 0
4845+ for _ in range (TIER2_THRESHOLD ):
4846+ if v :
4847+ cnt += 1
4848+ return cnt
4849+ self ._check_to_bool_recorded_type (
4850+ inner , bytearray (b"hello" ), "_GUARD_TOS_BYTEARRAY" )
4851+
4852+ def test_to_bool_frozenset (self ):
4853+ def inner (v ):
4854+ cnt = 0
4855+ for _ in range (TIER2_THRESHOLD ):
4856+ if v :
4857+ cnt += 1
4858+ return cnt
4859+ self ._check_to_bool_recorded_type (
4860+ inner , frozenset ({1 , 2 , 3 }), "_GUARD_TOS_FROZENSET" )
4861+
48224862 def test_attr_promotion_failure (self ):
48234863 # We're not testing for any specific uops here, just
48244864 # testing it doesn't crash.
0 commit comments